//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-left");
		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 MM_findObj(n, d) 
{ //v4.01
	var p,i,x;  
	if(!d) d=document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) 
	{
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n]; 
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); 

	return x;

}

function MM_showHideLayers() { //v6.0

	var mytext = document.search_frm.searchx; 
	
	var i,p,v,obj,args=MM_showHideLayers.arguments;

	for (i=0; i<(args.length-2); i+=3) 
	{
		if ((obj=MM_findObj(args[i]))!=null) 
		{
			v=args[i+2];
			
    		if (obj.style) 
			{ 
				v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
			}
			
			if(v=='visible')
			{
				obj.style.visibility=v;
				hoverStatus = 1;
			}
			else if(v=='hidden')
			{
				hoverStatus = 0;
				if(obj.id=='Search') {
					if(blurEvent == 0)
						setTimeout("if(hoverStatus==0) hide('Search');",1000);
					else
					{
						hide('Search');
						blurEvent = 0;
					}
				}
				else
					hide('Restaurant');
			}
			else
			{
				obj.style.visibility=v;
			} 
		}   
  	}  
	
	var mytext1 = document.locator_frm.locate;
	mytext.value = searchSText;
	mytext1.value = locLText;
}

function MM_showHideLayers2() { //v6.0
	
	var mytext = document.search_frm.searchx; 
	//alert(mytext.value);
	
	var i,p,v,obj,args=MM_showHideLayers2.arguments;
	for (i=0; i<(args.length-2); i+=3)
	{
		
		if ((obj=MM_findObj(args[i]))!=null) 
		{
			v=args[i+2];
			
			if (obj.style) 
			{
				v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
			}

			if(v=='visible')
			{
				obj.style.visibility=v; 
				hoverStatus = 1;
			}
			else if(v=='hidden')
			{
				hoverStatus = 0;
				if(obj.id=='Restaurant') {
					if(blurEvent == 0)
						setTimeout("if(hoverStatus==0) hide('Restaurant');",1000);
					else
					{
						hide('Restaurant');
						blurEvent = 0;
					}
				}
				else
					hide('Search');
			}
			else
			{
				obj.style.visibility=v;
			}
		}
	}
	
	var mytext1 = document.locator_frm.locate;
	mytext.value = searchSText;
	mytext1.value = locLText;
}

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 submitSearch(path,target,collectionName,sText)
{
	var searchVal = document.search_frm.searchx.value.trim();
	if(searchVal=="" || searchVal==searchSText)
	{
		alert(sText);
	}
	else
	{
		var formActionn = path+"?queryText=" + escape(searchVal) + "&collection=" + collectionName;
		window.open(formActionn,target);	
	}
}

function submitPageSearch(searchPath,target,collectionName,searchReqMsg)
{
	var searchVal = document.specialPage_frm.query.value.trim();
	if(searchVal=="")
	{
		alert(searchReqMsg);
	}
	else
	{
		var formActionn = searchPath+"?queryText=" + searchVal + "&collection=" + collectionName;
		window.open(formActionn,target);	
	}
}


function submitLocator(locPath,target,lText,country)
{
	var primaryCity = document.locator_frm.locate.value;
	
	primaryCity = primaryCity.replace(/#/g," ").trim();
	
	primaryCity = primaryCity.replace(/'/g,"\\'");
	
	if(primaryCity=="" || primaryCity==locLText)
	{
		alert(lText);
	}
	else
	{
	
		var postalCode="";
	
		if(!isNaN(primaryCity))
			postalCode = primaryCity;
	
		var queryString = "?country="+country+"&method=search&primaryCity=" + escape(primaryCity) + "&postalCode=" + escape(postalCode);
		var formActionn = locPath+queryString;
		window.open(formActionn,target);		
	}
}

function NewWindow(mypage, myname, w, h, scroll) 
		{
		//alert("My Page : " + mypage);
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
		win = window.open(mypage, myname, winprops);
		if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	}

	/* function used to print a page */
	function printWindow()
		{
	
	   bV = parseInt(navigator.appVersion);
	   if (bV >= 4) window.print();
	}


$(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("slow");
        }, // function = onMouseOver callback (REQUIRED)
        out: function() {
				out= $("a:first",this).attr("rel");
				$("#"+out).slideUp(50,function(){out="";});
		} // function = onMouseOut callback (REQUIRED)

   }
	
	$('#main-navigation-left 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("");
		});*/
	});

});

 
