//dynamic navigation
var flag = 0;
var locatorVisible = false;
var hoverStatus = 0;
var blurEvent = 0;
var searchSText = "";
var setSText = 0;
var locLText = "";
var setLText = 0;
var objClicked = "";

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

initNav = function() {
	if (document.all && document.getElementById) 
	{
		var navRoot = document.getElementById("main-navigation");
		var lis = navRoot.getElementsByTagName("li");
		for (var i=0; i<lis.length; i++)
		{
			lis[i].onmouseover = function()
			{
				this.className += " hover";
			}
			lis[i].onmouseout = function()
			{
				this.className = this.className.replace(" hover", "");
			}
		}
	}
}
if (document.all && window.attachEvent)
	attachEvent("onload", initNav);

//Show Hide Division Sub Mneu - Main Navigation
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function hide(obj)
{	
	if(flag == 0)
	{alert("hello");
		document.getElementById(obj).style.visibility="hidden";
		hoverStatus = 0;
	}
}

function show(obj)
{	
	if(flag == 0 && locatorVisible==false)
	{
		document.getElementById(obj).style.visibility="visible";
		locatorVisible = true;
		hoverStatus = 1;
	}
}

function checkFlag()
{
	flag = 1;
}
function resetFlag()
{
	flag = 0;
}

function checkHover()
{
	hoverStatus = 1;
}

function resetHover()
{
	hoverStatus = 0;
}

$(function(){
	var hover="";
	var out="";
	var flag = 0;

	$(document).click(function(e){
	    //e.stopPropagation();
		var obj = $(e.target).attr("class");
		if(obj){

			if(obj.indexOf("tBox")>=0){
				$(e.target).val("");
				objClicked = $(e.target).parents("div").attr("id");
				flag = 1;
			}
			else {				
				$("#top-navigation div.newSubMenu:visible").slideUp("fast");
				flag = 0;
				hoverStatus = 0;
			}
		}else{
			$("#top-navigation div.newSubMenu:visible").slideUp("fast");
				flag = 0;
				hoverStatus = 0;
		}
	});

	//hover Left menu	
	leftConfig = {
	    sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
        interval: 30, // number = milliseconds for onMouseOver polling interval
        timeout: 200, // number = milliseconds delay before onMouseOut
        over: function() {
           hover= $("a:first",this).attr("rel");
		   $("#"+hover).slideDown("fast");
        }, // function = onMouseOver callback (REQUIRED)
        out: function() {
				out= $("a:first",this).attr("rel");
				$("#"+out).slideUp(50,function(){out="";});
		} // function = onMouseOut callback (REQUIRED)

   }
	
	$('#main-navigation li').hoverIntent(leftConfig);



	rightConfig = {
	    sensitivity: 3, 
        interval: 100,
        timeout: 100, 
        over: function() {
			
			hover= $("a:first",this).attr("rel");

			if(objClicked!="" && objClicked!=hover)
			{
				$("#"+objClicked).slideUp("fast");
				hoverStatus = 0;
				flag = 0;
			}

			if(hoverStatus==0)
			{
				$("#"+hover).slideDown(200);
				hoverStatus = 1;
				document.search_frm.searchx.value = searchSText;
				document.locator_frm.locate.value = locLText;
			}
        }, // function = onMouseOver callback (REQUIRED)
        out: function() { 

			out= $("a:first",this).attr("rel");

			if(objClicked!="" && objClicked!=out)
			{
				flag = 0;
			}
			if(flag == 0) {
				
				$("#"+out).slideUp(1,function(){out="";});
				hoverStatus = 0;
			}

		} // function = onMouseOut callback (REQUIRED)

   }
    

	$('#top-navigation li').hoverIntent(rightConfig);

	/*
	$("#top-navigation li a").each(function(){
		$(this).mouseover(function(){
			$("#top-navigation div.newSubMenu:visible").not($(this).find("~ div.newSubMenu:visible")).slideUp("fast");
			$(this).siblings(".newSubMenu").slideDown("fast");
			$(this).siblings(".newSubMenu .tBox").focus();
		});
		
	});*/

	$(".tBox").each(function(){
		$(this).blur(function(){
			if(hoverStatus==0){
			if($(this).attr("name")=="searchx")
			{
				$(this).val(searchSText);
			}
			else if($(this).attr("name")=="locate")
			{
				$(this).val(locLText);
			}
			}
		});
		/*$(this).focus(function(){
			$(this).attr("rel",$(this).val());
			$(this).val("");
		});*/
	});

});

 
