




/*	****************************************************
					Document Ready / General Functions
	**************************************************** */

$(document).ready(function() {
	
	$("#secondaryNav li").hover(
		function() {
			navOver($(this).attr("id"));
		},
		function() {
			navOut();
		}
	);

	$("#secondarySubNav li").hover(
		function() {
			$(this).addClass("hover");
		},
		function() {
			$(this).removeClass("hover");
		}
	);


	// setup tooltips
	$("#secondarySubNav li[@title='tooltip']").Tooltip({
		track: true,
		delay: 0,
		fixPNG: true,
		bodyHandler: getBlipBody,
		top: -30,
		left: 99
	});
	
});


var subsHeight = 0;
$(window).load(function() {
	$("#secondarySubNav div.sub").each(function() {
		var thisBottom = parseInt($(this).css("top")) + $(this).height();
		subsHeight = Math.max(subsHeight, thisBottom);
	});
	
	var nh = subsHeight + 150;
	$("#copyArea").css({minHeight: nh+"px"});

});


function updateLogos() {
	var worlds = $('#worldsTop');
	var wt = worlds.position().top;
	var sub = $('#' + stuckSub);
	var sb = sub.position().top + sub.height();
	if(wt < sb) {
		worlds.css('paddingTop', (sb-wt+20));
	}
}





/*	****************************************************
					Sub Nav Biz
	**************************************************** */

var activeSub = null;
var activeNav = null;
var stuckNav = null;
var stuckSub = null;
var offTimer = null;

function navOver(nav) {
	// hide the currently active nav if there's one showing
	hideActive();

	// make sure the stuck nav is off
	hideStuck();
	
	// make the current nav the active one
	makeActive(nav);
}


function navOut() {
	offTimer = setTimeout("hideActive()", 400);
}



function subOver() {
	clearTimeout(offTimer);
}


function subOut() {
	offTimer = setTimeout("hideActive()", 400);
}



function makeActive(nav) {
	// stick the current nav to on
	$("#"+nav).addClass("hover");
	$("#"+nav).children("a").addClass("hover");
	activeNav = nav;
	
	// show the current nav's sub
	$("#"+nav+"_sub").css("display", "block");
	activeSub = nav+"_sub";
}




function hideActive() {
	// turn off the active nav
	if(activeNav != null) {
		$("#"+activeNav).removeClass("hover");
		$("#"+activeNav).children("a").removeClass("hover");
		activeNav = null;
	}

	// turn off the active sub
	if(activeSub != null) {
		$("#"+activeSub).css("display", "none");
		activeSub = null;
	}
	
	// make sure we clear the timer for this function
	clearTimeout(offTimer);
	
	// show the stuck navs
	showStuck();
}


function stick(nav) {
	if(nav != null) {
		stuckNav = nav;
		stuckSub = nav+'_sub';
		showStuck();
		updateLogos();
	}
}


function showStuck() {
	if(stuckNav != null) {
		$("#"+stuckNav).addClass("stick");
		$("#"+stuckNav).children("a").addClass("hover");
	}
	
	if(stuckSub != null) {
		$("#"+stuckSub).css("display", "block");
	}
}


function hideStuck() {
	if(stuckNav != null) {
		$("#"+stuckNav).removeClass("stick");
	}
	
	if(stuckSub != null) {
		$("#"+stuckSub).css("display", "none");
	}
}





