function qf () {
	// PROMOTER HEIGHT FIX
	if($('body #page #body div.promoter').length>0) {
		$('body #page #body div.promoter').css('height', ( ($('body #page #body div.promoter div.text').height()>$('body #page #body div.promoter div.background').height() )? $('body #page #body div.promoter div.text').height() : $('body #page #body div.promoter div.background').height()));
	}
}

qf();

$(document).ready(function() {
	$('#menu-global label').hide();
	$('body #eventbubble').hide();
	$('#menu-main li.selected').className
	
	var bottomNavMax = 0;
	$('body #page #bottom-nav div').each(function() {
		if(bottomNavMax < $(this).height()) bottomNavMax = $(this).height();
	}); $('body #page #bottom-nav div').css('height', bottomNavMax);
	
	var bottomBoxMax = 0;
	$('body #page #bottom-box-container div .content').each(function() {
		if(bottomBoxMax < $(this).height()) bottomBoxMax = $(this).height();
	});
	$('body #page #bottom-box-container div .content').css('height', bottomBoxMax + ($('body #page #bottom-box-container div .content a.more').length>0? 20:0) );
	$('body #page #bottom-box-container').css('height', '100%');

	// FLOATERS SEPARATED BY VERTICAL GRADIENT
	if($('body #page #body div.separated-floaters div').length>0) {
		var floaterBoxMax = 0;
		$('body #page #body div.separated-floaters div').each(function() {
			if(floaterBoxMax < $(this).height()) floaterBoxMax = $(this).height();
		});
		if($('body #page #body div.separated-floaters div').parents().filter('div.customer-cases').length>0) floaterBoxMax = floaterBoxMax + 25;
		$('body #page #body div.separated-floaters div').css('height', floaterBoxMax);
	}
	
	// GRADIENT FLOATERS
	if($('body #page #body div.gradient-floaters div').length>0) {
		$('body #page #body div.gradient-floaters div div h2').each(function() {
			$(this).click(function () {
				window.location.href = $(this).find('a').attr('href');
			});
		});
	}

	// FRONTPAGE MENU EVENT HANDLER
	if($('body #page #body div.frontpage div.menu ul').length>0) {
		$('body #page #body div.frontpage div.menu ul li').mouseover(function () {
			$(this).addClass('hover');
		});
		$('body #page #body div.frontpage div.menu ul li').mouseout(function () {
			$(this).removeClass('hover');
		});
	}
	
	// XFORM
	if($('body #page #body div.xForm').length>0) {
		$('body #page #body div.xForm table tr').addClass('top');
		$('body #page #body div.xForm table tr td input[type="text"], body #page #body div.xForm table tr td textarea, body #page #body div.xForm table tr td select').each(function () {
			$(this).addClass('text');
			$($(this).parent().parent().children()[0]).addClass('label').html( '<label for="'+ this.id +'">' + $($(this).parent().parent().children()[0]).html() + '</label>' );
		});
		$('body #page #body div.xForm table tr td input[type="submit"], body #page #body div.xForm table tr td input[type="button"]').not('#campaign input[type="button"]').each(function () {
			$(this).parent().html( '<div class="action">' + $(this).parent().html() + '</div>' );
		});
		$('body #page #body div.xForm table tr td fieldset').each(function () {
			if($($(this).parent().parent().children()[0]).html()!='') $($(this).parent().parent().children()[0]).addClass('label').html( '<label for="">' + $($(this).parent().parent().children()[0]).html() + '</label>' );
		});
		$('body #page #body div.xForm table tr td input.required, body #page #body div.xForm table tr td textarea.required, body #page #body div.xForm table tr td select.required').each(function () {
			$(this).removeClass('required');
			$(this).parent().html( '<div class="form-required">' + $(this).parent().html() + '</div>' );
		});
		$('body #page #body #campaign div.xForm table tr td input[type="submit"], body #page #body #campaign div.xForm table tr td input[type="button"]').each(function () {
			$(this).parent().html( '<div class="button">' + $(this).parent().html() + '</div>' );
		});
		$('body #page #body #campaign div.xForm table tr td div.button, body #page #body #campaign div.xForm table tr td p').each(function() {
			$(this).parents('tr').addClass('noborder');
		});
	}
	
	


	// PROCESS FLOATERS
	if($('body #page #body div.process-large').length>0) {
		var floaterBoxMax = 0;
		var floaterBoxMin = 179;
		$('body #page #body div.process-large div div').each(function() {
			if(floaterBoxMax < $(this).height()) floaterBoxMax = $(this).height();
		});
		if(floaterBoxMax+80<floaterBoxMin) $('body #page #body div.process-large').css('height', floaterBoxMin);
	}




	// TAB HANDLERS
	if($('body #page #body div.tab-container').length>0) {
		var thisScroll = 0;
		if(window.location.hash!='#tab-none' && window.location.hash!='') {
			$('body #page #body div.tab-container div.tab-content div.tab').hide();
			$('body #page #body div.tab-container div.tab-content div'+ window.location.hash +'.tab').show();
			
			$('body #page #body div.tab-container table.tabs').addClass('active');
			$('body #page #body div.tab-container table.tabs td.tab').removeClass('selected');
			$('body #page #body div.tab-container table.tabs td.tab a[href='+ window.location.hash +']').parent().addClass('selected');
		} else {
			$('body #page #body div.tab-container table.tabs').removeClass('active');
			$('body #page #body div.tab-container table.tabs td.tab').removeClass('selected');
			$('body #page #body div.tab-container div.tab-content div.tab').hide();
		}
		$('body #page #body div.tab-container table.tabs tr').mouseover(function() {
			$(this).addClass('hover'); 
		});
		$('body #page #body div.tab-container table.tabs tr').mouseout(function() {
			$(this).removeClass('hover'); 
		});
		$('body #page #body div.tab-container table.tabs td.tab a').each(function() {
			$(this).parent().parent().children().filter('td').click(function() {
				thisScroll = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
				var thisHash = $(this).parent().children().filter('td.tab').children().filter('a').attr('hash');
				if(thisHash!=window.location.hash) {
					window.location.hash = thisHash;
				} else {
					window.location.hash = '#tab-none';
				}
				window.scrollTo(0,thisScroll);
				if(window.location.hash!='#tab-none' && window.location.hash!='') {
					$('body #page #body div.tab-container div.tab-content div.tab').hide();
					$('body #page #body div.tab-container div.tab-content div'+ window.location.hash +'.tab').show();
					
					$('body #page #body div.tab-container table.tabs').addClass('active');
					$('body #page #body div.tab-container table.tabs td.tab').removeClass('selected');
					$('body #page #body div.tab-container table.tabs td.tab a[href='+ window.location.hash +']').parent().addClass('selected');
				} else {
					$('body #page #body div.tab-container table.tabs').removeClass('active');
					$('body #page #body div.tab-container table.tabs td.tab').removeClass('selected');
					$('body #page #body div.tab-container div.tab-content div.tab').hide();
				}
				return false;
			});
		});
		$('body #page #body div.tab-container div.tab a.close-tab').click(function() {
			$('body #page #body div.tab-container table.tabs').removeClass('active');
			$('body #page #body div.tab-container table.tabs td.tab').removeClass('selected');
			$('body #page #body div.tab-container div.tab-content div.tab').hide();
			window.location.hash = '#tab-none';
			window.scrollTo(0,0);
			return false;
		});
		setTimeout("window.scrollTo(0,0);", 100);
	}
	
	// Country Selector
	$('body #page #header #country-selector').hide();
	$('body #page #header #menu-global li.country > a').click(function() {
		if($('body #eventbubble').length==0) $('body').append('<div id="eventbubble"></div>');
		$('body #eventbubble').show();
		var index = 0;
		var selectedIndex = 0;
		var thisName = $(this).html();
		$('body #page #header #country-selector li a span').each(function() {
			if($(this).html() == thisName) {
				$(this).parent().parent().addClass('selected');
				selectedIndex = index;
			}
			index++;
		});
		$('body #page #header #country-selector').css('left', '-32px');
		if(selectedIndex!=0) {
			$('body #page #header #country-selector').css('top', '-' + ((selectedIndex*34) - 1) + 'px');
			$('body #page #header #country-selector').fadeIn('fast', function() {
				$('body #page #header #country-selector').animate({top: '-12px'}, 500);
			});
		} else {
			$('body #page #header #country-selector').css('top', '-12px');
			$('body #page #header #country-selector').fadeIn('fast');
		}
	});
	$('body #page #header #menu-global li.country ul li a').click(function() {
		if($(this).parent().hasClass('selected')) {
			$('body #page #header #country-selector').animate({'top':'-'+($('body #page #header #country-selector').height()+12)+'px'}, 500, '', function() {
				$('body #page #header #country-selector').hide();
			});
			return false;
		} else {
			$(this).css('background-color','#2b85bf');
			$(this).css('color','#fff');
		}
	});
	$('body #eventbubble').add('body #logo').mouseover(function() {
		$('body #eventbubble').hide();
		$('body #page #header #country-selector').animate({'top':'-'+($('body #page #header #country-selector').height()+12)+'px'}, 500, '', function() {
			$('body #page #header #country-selector').hide();
		});
		return false;
	});
});