//functions for the javascript pop up menus
var closeInterval;
var ie4=document.all;
var ns6=document.getElementById&&!document.all;

function openOrder(){
	window.open('order.php', 'order', 'toolbars=no, menubar=no, height=590, width=567');
}

function openPan(){
	window.open('webView.php', 'WebView', 'toolbars=no, menubar=no, height=300, width=400');
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function init(obj, e, id){
	dropmenuobj = document.getElementById(id);
	dropmenuobj.x=getposOffset(obj, "left");
	dropmenuobj.y=getposOffset(obj, "top");
	dropmenuobj.style.left=dropmenuobj.x-(clearbrowseredge(obj, "rightedge")+15)+"px";
	if(id == 'menusWrap'){
		dropmenuobj.style.top=(dropmenuobj.y - 238) +"px";
	}
	if(id == 'setMenuWrap'){
		dropmenuobj.style.top=(dropmenuobj.y - 142) +"px";
	}
	if(id == 'takeAwayMenuWrap'){
		dropmenuobj.style.top=(dropmenuobj.y - 595) +"px";
	}
	if(id == 'wineWrap'){
		dropmenuobj.style.top=(dropmenuobj.y - 118) +"px";
	}
	display(id);
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=0
	if (whichedge=="rightedge"){
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
		}else{
			var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
			var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
			dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
				if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
					edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
					if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
						edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
					}
				}
	return edgeoffset
}

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
return totaloffset;
}

function display(id){
	var menuOn = document.getElementById('menuOn').value
	
	if(closeInterval){
		if(menuOn == id){
			window.clearTimeout(closeInterval);
		}
	}
	if(document.getElementById(id)){
		document.getElementById(id).style.display = 'block';
		document.getElementById('menuOn').value = id;
	}
}

function noDisp(id){	
	if(document.getElementById(id)){
		closeInterval = window.setTimeout("document.getElementById('"+id+"').style.display = 'none'", 250)
	}
}
//end of pop up menu code

//functions for highlighting cells in the pop up menu
function onMouseOverHighlight(obj){
	if(obj){
		obj.style.backgroundColor = '#457b6b';
	}
}

function onMouseOutHighlight(obj){
	if(obj){
		obj.style.backgroundColor = '#004a45';
	}
}
// end of highlight functions

//function to move to the correct page
function gotoPage(page, id){
	window.location = page+'#'+id;
}
//end of function


//function to play sound on mouse over link
function EvalSound(){
	try{	
		var thissound = eval("document.sound1");
		thissound.Play();
	}catch(e){
		return true;
	}
}
//end of function

//function to init all of the on mouse over events called on window load
function initEvents(){
	/*if(document){
		document.getElementById('homeLink').onmouseover 		= EvalSound;
		document.getElementById('webViewLink').onmouseover 		= EvalSound;
		document.getElementById('menusLink').onmouseover 		= init(this, event, 'menusWrap');
		document.getElementById('menusLink').onmouseout 		= 'noDisp(\'menusWrap\')';
		document.getElementById('setMenuLink').onmouseover 		= 'init(this, event, \'setMenuWrap\')';
		document.getElementById('setMenuLink').onmouseout 		= 'noDisp(\'setMenuWrap\')'; 
		document.getElementById('takeAwayLink').onmouseover 	= 'init(this, event, \'takeAwayMenuWrap\')';
		document.getElementById('takeAwayLink').onmouseout 		= 'noDisp(\'takeAwayMenuWrap\')';
		document.getElementById('wineRoomsLink').onmouseover 	= 'init(this, event, \'wineWrap\')';
		document.getElementById('wineRoomsLink').onmouseout 	= 'noDisp(\'wineWrap\')';
		document.getElementById('contactLink').onmouseover 		= 'EvalSound(\'sound1\')';
		document.getElementById('orderLink').onmouseover 		= 'EvalSound(\'sound1\')';
	}*/
}
