/* -------------------------------------------------------------------

	Boondoggle - <css creator>
	<client>
	
	This JavaScript file collects all general functions used
	throughout the site, as well as some smaller specific
	functions.

------------------------------------------------------------------- */



// when the document is ready to be traversed and manipulated...
$(document).ready(function(){
	
	// LINK HANDLER
	// when you click on a link with class externalLink
	$("a.externalLink").click(function(){
		// open a new window with the link's location
		window.open($(this).attr("href"));
		// and do nothing after (to prevent the link from actually firing)
		return false;
	});
	
	navbar();

});




function showSubNav(hoveredItem){
	$(".navigationLeftActiveItem").removeClass("navigationLeftActiveItem").addClass("navigationLeftActiveItemOff");
	hoveredItem.children("ul:hidden").css({"z-index": 2}).show();
}

function hideSubNav(hoveredItemSubNav){
	$(".navigationLeftActiveItemOff").removeClass("navigationLeftActiveItemOff").addClass("navigationLeftActiveItem");
	$(".hover").removeClass("hover");
	hoveredItemSubNav.hide();
}

function navbar() {
	// create variables
	var subNavTimer;
	var open;
	var hoverableItems = $("#navigation > ul > li").not(".navigationLeftActiveItem, li:first-child");
	// make sure that when user mouses over sub menu ul it stays open
	hoverableItems.children("ul").mouseover(function(){
		$(this).show();
		// lets remember what's open
		open = $(this).parent();
	});
	// when user mouses over main item in navbar
	hoverableItems.mouseover(function(){
		$(".hover").removeClass("hover");
		$(this).addClass("hover");
		// close other nav item submenus
		if (open != null) open.children("ul").hide();
		// stop the timer
		clearTimeout(subNavTimer);
		// show this nav item's sub menu
		if ($(this) != open) showSubNav($(this));
	});
	// when user's mouse leaves the navbar item
	hoverableItems.mouseout(function(){
		$(".hover").not($(this)).removeClass("hover");
		// lets keep tabs of what is open
		open = $(this);
		// start the timer for 2 seconds until it closes.
		subNavTimer = setTimeout(function(){hideSubNav(open.children('ul:visible'))}, 500);
	});
}
