$(window).load( function(){

	// Related Code is in: /views/elements/header.ctp

	$("#topnav-links li a").hoverIntent( function(){

		$(this).parent().siblings().each( function(){
			$(this).find('a img').fadeTo('fast',0.5);
		});

	}, function(){

		$("#topnav-links").find("li a img").fadeTo('fast',1.0);

	});


	// events menu
	$('#event-info-links').hoverIntent( function(){
			//		$('#event-info-links').show();
			//		eventMenuOn = true;
	}, function(){
		$('#event-info-links').slideUp('fast');
		$("#topnav-links").find("li a").fadeTo('fast',1.0);
	});

	// sponsors menu
	$('#sponsors-links').hoverIntent( function(){
			//		$('#sponsors-links').show();
			//		sponsorMenuOn = true;
	}, function(){
		$('#sponsors-links').slideUp('fast');
		$("#topnav-links").find("li a").fadeTo('fast',1.0);
	});


	// big-nav menu
	$('ul.sf-menu').superfish({
		speed:'fast',
		autoArrows:false,
		dropShadows:false
	});

	$("#search-submit").click( function(){
		$(this).parents("form").submit();
		return false;
	});

	// search form
	$("#PageSearchForm").bind('submit', function(){
		keyword = $("#PageKeyword").val();
		if( keyword.length > 2 ){
			window.location = '/pages/search/keyword:'+encodeURI(keyword);
		}else{
			$.jGrowl('Searches must contain at least 3 characters');
		}
		return false;
	});

	fixHeights();

	$("#content").resize( function(){
			fixHeights();
	});

});

function damnIE6(){
	$("#footer").css({"top":"-10px"});
	// fix css style issues in footer
   	$("#content-bg-mid").css({'height': ($("#content").height()-40)+"px", 'overflow' : 'visible'});
}

function fixHeights(){
	if( $("#sidebar-left").length > 0 && $("#copy").length > 0 ){
		lheight = $("#sidebar-left").height() - 10;
		rheight = $("#copy").height();
		if( lheight > rheight ){
			diff = lheight - rheight;
			if( $.browser.msie ) diff += 5;
			$("#copy .box-med-mid").height(
									 $("#copy .box-med-mid").height() + diff );
		}
	}


	// fix css style issues in footer
	//	$("#content-bg-mid").height( $("#content").height()-40 );

	if( $.browser.msie && $.browser.version == 7 ){
		$("#footer").css({"top":"0px"});
	}

	// if ie6/7, fix footer
	if( $.browser.msie && $.browser.version < 7 ){
		setTimeout('damnIE6();', 200);		
	}
}

