/* Copyright 2009 Jkwiz, LLC. All Rights Reserved.*/
var activeMenu = false;
var activeMotion = false;

$(document).ready(function(){
	$("#nav li").hoverIntent(function() {
		if ($("#" + $(this).attr("class")).length > 0)
		{
			processHover($(this).attr("class"));
		}
		else
		{
			checkStatus(activeMenu);
		}
	}, function() {} ).click(function() { if ($("#" + $(this).attr("class")).length > 0) { return false; } } );
	
	$("#header").hover(function() { }, function(){
		checkStatus(activeMenu);
	});
	
	$("#header-over").hover(function(){
		checkStatus(activeMenu);
	});
	
	$("#searchField").focus(function() { $(this).attr("value",""); });
	$("#searchField").blur(function() { if ($(this).attr("value") == "") { $(this).attr("value","search..."); } });
	
	$("#bookmark").jFav();
});

function processHover(pTarget)
{
	activeMenu = pTarget;
	
	if (activeMotion == false)
	{
		if ($(".drop-down").filter(':visible').length > 0)
		{
			activeMotion = true;
			$("." + $(".drop-down").filter(':visible').attr("id") + " .open-drop").removeClass("blue");
			$(".drop-down").filter(':visible').hide();
			
			$("." + pTarget + " .open-drop").addClass("blue");
			$("#" + pTarget).show();
			activeMotion = false;
		}
		else
		{
			activeMotion = true;
			$("." + pTarget + " .open-drop").addClass("blue");
			$("#" + pTarget).slideDown("normal", function() { activeMotion = false; });
		}
	}
	else
	{
		setTimeout(function() { processHover(pTarget) }, 200);
	}
}

function checkStatus(pTarget)
{
	if (activeMotion == false)
	{
		if (activeMenu != false)
		{
			activeMotion = true;
			$("#" + pTarget).slideUp("normal", function() { activeMotion = false; });
			$("." + pTarget + " .open-drop").removeClass("blue");
			activeMenu = false;
		}
	}
}