$(document).ready(function()
{
	// remove dotted white line on top menu when next selected
	$('.menu ul li.selected').prev().css('border', 'none');
	
	
	// make all boxes the same height
	//$('.box').equalHeights();
	$('.col').equalHeights();
	$('.equal_h').equalHeights();
	
	
	// make 'col_2' the same height as two boxes (with margin)
	set_col_height = 0;
	count = 0;
	
	// sets height to remove if there are no buttons on boxes
	$('.no_bt').each(function(){
		if(count < 2) {
			set_col_height -= 42;
			count++;
		}
	});
	
	// reset count
	count = 0;
	// adds up height of first two boxes
	$('.box').each(function(){
		if(count < 2) {
			set_col_height += $(this).height() + 42;
			if(count != 0) {
				set_col_height += 10;
			}
			count++;
		}
	});
	$('.double_box_height').css({'min-height':set_col_height});
	
	if(!$.browser.msie) {
		// animate image in
		$('.leader').hide();
		$('.leader .sub_menu').hide();
		$('.leader .main_image').hide();
		$('.main .leader .main_image').css({"right":"50px", "bottom":"-12px"});
		$('.home .leader .main_image').css({"right":"20px", "bottom":"-12px"});
	
		$('.leader').fadeIn('slow', function(){
		
			$('.leader .overflow .sub_menu').animate({
					"opacity" :"show"
				}, 500, "easeOutQuad");
			$('.main .leader .main_image').animate({
					"opacity": "show"
				}, 800, "easeOutQuad");
				
			$('.home .leader .main_image').animate({
				"opacity": "show"
			}, 800, "easeOutQuad");
		});
	}
	else
	{
		$('.home .leader .main_image').css({"right":"20px", "bottom":"-12px"});
	}
	
	// set margin left for ie 7 (work around because of float left)
	if(jQuery.browser.msie && jQuery.browser.version.substr(0,1) == "7") {
		var setMarginLeft = (screen.width - 990 - 16) / 2; // (screen - container - scrool bar) / 2
		$('.footer .container').css({'margin-left': setMarginLeft});
	}
	
	$('body').click(function() {
 		//Hide the menus if visible
 		if(drop_down == 1)
 		{
 			$('.box .drop_down ul').slideUp();
			drop_down = 0;
		}
 	});
 	
	// drop down
	$('.box .drop_down ul').hide();
	drop_down = 0;
	$('.box .drop_down').click(function(e){
		if(drop_down == 0)
		{
			$('.box .drop_down ul').slideDown();
			drop_down = 1;
		}
		else
		{
			$('.box .drop_down ul').slideUp();
			drop_down = 0;
		}
		e.stopPropagation();
	});
	
	// hide the text in the search bar
	$('.box form.email .textBox').each(function()
	{
		document['def_'+$(this).attr('name')] = $(this).attr('value');
		$(this).focus(function()
		{
			if($(this).attr('value') == document['def_'+$(this).attr('name')]) $(this).attr('value','');
		});
		$(this).blur(function()
		{
			if($(this).attr('value') == '') $(this).attr('value',document['def_'+$(this).attr('name')]);
		});
	});
	
	// hide all menu items
	$('.sub_menu ul li ul').hide();
	
	// on hover show menu items and change color 
	$('.sub_menu ul li').hover(function()
		{
			$(this).find('ul').show();
			$(this).find('li').each(function(){
				$(this).hover(function()
				{
					$(this).css({'background-color':'#dce54f'});
					$(this).find('a').css({'color':'#333'});
				},function()
				{
					$(this).css({'background-color':'#333'});
					$(this).find('a').css({'color':'#fff'});
				});
			});
		},function()
		{
			$(this).find('ul').hide();
		}
	);
	
	$('.sub_menu li.first.last').each(function(){
		$(this).append('<span class="single_li"></span>');
	});
	
	$('a[href=#download]').click(function(ev){
		ev.preventDefault();
		if(drop_down == 0)
		{
			$('.box .drop_down ul').slideDown();
			drop_down = 1;
		}
		else
		{
			$('.box .drop_down ul').slideUp();
			drop_down = 0;
		}
		ev.stopPropagation();
	});
	
});
