
var totalLay = 6; //this value must be the count of array arrMenu
var menuid = 0;
var currSub = 0;
var timerId = 0;


var arrMenu = new Array();
arrMenu[0]='mnHome';
arrMenu[1]='mnAboutUs';
arrMenu[2]='mnLeisure';
arrMenu[3]='mnEvents';
arrMenu[4]='mnCruises';
arrMenu[5]='mnContactUs';

var defaultImg = 'menu_all.gif';
var arrBgImg = new Array();
arrBgImg[0]='menu_home_h.gif';
arrBgImg[1]='menu_aboutus_h.gif';
arrBgImg[2]='menu_leisure_h.gif';
arrBgImg[3]='menu_events_h.gif';
arrBgImg[4]='menu_cruises_h.gif';
arrBgImg[5]='menu_contactus_h.gif';

var arrMenuWidth = new Array();
for (i=0; i<(totalLay-1); i++) {
  j = i + 1;
  if (document.getElementById(arrMenu[j]) != undefined && document.getElementById(arrMenu[i]) != undefined)
    arrMenuWidth[arrMenu[i]] =  document.getElementById(arrMenu[j]).style.left - document.getElementById(arrMenu[i]).style.left;   
}

function menuHandler(menuid, showflag) {
	
  if (showflag != 0) { //show menu
    clearTimeout(timerId);
    showMenu(menuid, showflag)
  }
  else { //hide menu after a few sec
    timerId = setTimeout("showMenu('', 0)", 500);
  }
  
  
}

function showMenu(menuid, showflag) {
	
	if (!showflag) {
		if (menuid == '') { // hide all if menunum = 0
			for (i=0; i<totalLay; i++) {
		  	otherLay = document.getElementById(arrMenu[i]);
				if (otherLay){ otherLay.style.visibility = "hidden";}
	  	}
		
		}
		else { // hide just the specified menu
		 	otherLay = document.getElementById(menuid);
			if (otherLay) otherLay.style.visibility = "hidden";
			
		}
		document.getElementById("menu").src = "images/" + defaultImg; 
	}
	
	if (showflag != 0) { // show the appropriate menu
  	tempLay = document.getElementById(menuid);
  	tempLay.style.visibility = "visible";
  	tempLay.style.left = findPos(document.getElementById('m'+menuid)) + 'px';
  	tempLay.style.top = (findPosTop(document.getElementById('m'+menuid)) + (-2)) + 'px';
	
	//tempLay.style.left = 230 + 'px';
  	//tempLay.style.top = 150 + 20 + 'px';
		for(j=0;j<totalLay;j++){
			if(arrMenu[j] == menuid){
				document.getElementById("menu").src = "images/" + arrBgImg[j]; 
				break;
			}
		}
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	
	return curleft;
}

function findPosTop(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	
	return curtop;
}