var timer = "";
var openMenu = null;
var canMenuBeClosed = true;

function hideObjects() 
{ 
	var selCount = document.all.tags("select"); 
	for (i=0; i<selCount.length; i++) 
	{
		selCount[i].style.visibility = "hidden";
	}
}  

function showObjects() 
{ 
	selCount=document.all.tags("select");
	for (i=0;i<selCount.length;i++) 
	{
		selCount[i].style.visibility="visible"; 
	}
}

function clearTimer(){
	window.clearTimeout(timer);
}

function tryToClose(){
	var funcToCall = "canMenuBeClosed = true"
	timer = window.setTimeout(funcToCall, 400);
}

function showMenu(id, objPos){

	if(document.getElementById){
		clearTimer();
		setElementProperty('home', 'display', 'none');
		setElementProperty('commissions', 'display', 'none');
		setElementProperty('reservations', 'display', 'none');
		setElementProperty('onlinehelp', 'display', 'none');
		setElementProperty('promotions', 'display', 'none');
		setElementProperty('aboututell', 'display', 'none');
		openMenu = id;
		canMenuBeClosed = false

		var x = 0;
		var y = 0;
		
		x = getElementLeft(objPos);
		y = getElementBottom(objPos);

		setElementProperty(id, 'display', 'block');
		setElementProperty(id, 'left', x + "px");
		setElementProperty(id, 'top', y + "px");
	}
}

function hideMenu(id){
	setElementProperty(id, 'display', 'none');
	openMenu = null;
}

function getMousePos(event){
	var x, y;
	
	if(window.event){
		x = window.event.clientX;
		y = window.event.clientY;
		if (document.documentElement && document.documentElement.scrollTop){
			y+=document.documentElement.scrollTop;
			
		} else {
			y+=document.body.scrollTop;
			
		}
	} else {
		x = event.pageX;
		y = event.pageY;
	}

	if(openMenu != null){
		var testInside = isInside(x, y, openMenu);
		if(!testInside && canMenuBeClosed == true){
			hideMenu(openMenu);
		}
		if(testInside){
			canMenuBeClosed = true;
			clearTimer();
		}
	}
}

function isInside(xMouse, yMouse, id){
	if( (id != null) && (xMouse >= getElementLeft(id)) && (xMouse <=getElementRight(id)) && (yMouse >= (getElementTop(id))-25) && (yMouse <= getElementBottom(id)) ){
		hideObjects();
		return true;
	} else {
		showObjects();
		return false;
	}
}

window.onload = function() {
	document.onmousemove = getMousePos;
}

function switchDisplay(elm){
	var elm = elm.parentNode.nextSibling;
	while(elm.nodeType == 3){
		elm = elm.nextSibling;
	}
	
	var elmStyle = getElementProperty(elm, "display")

	if((elmStyle == "none") || (elmStyle == "") || (elmStyle == null)){
		setElementProperty(elm, "display", "block");
		return;
	}
	if(elmStyle == "block"){
		setElementProperty(elm, "display", "none");
		return;
	}
}


function getElementLeft(p_elm) {

	var x = 0;

	var elm;

	if(typeof(p_elm) == "object"){

		elm = p_elm;

	} else {

		elm = document.getElementById(p_elm);

	}

	while (elm != null) {

		x+= elm.offsetLeft;

		elm = elm.offsetParent;

	}

	return parseInt(x);

}


function getElementWidth(p_elm){

	var elm;

	if(typeof(p_elm) == "object"){

		elm = p_elm;

	} else {

		elm = document.getElementById(p_elm);

	}

	return parseInt(elm.offsetWidth);

}


function getElementRight(p_elm){

	return getElementLeft(p_elm) + getElementWidth(p_elm);

}

function getElementTop(p_elm) {

	var y = 0;

	var elm;

	if(typeof(p_elm) == "object"){

		elm = p_elm;

	} else {

		elm = document.getElementById(p_elm);

	}

	while (elm != null) {

		y+= elm.offsetTop;

		elm = elm.offsetParent;

	}

	return parseInt(y);

}


function getElementHeight(p_elm){

	var elm;

	if(typeof(p_elm) == "object"){

		elm = p_elm;

	} else {

		elm = document.getElementById(p_elm);

	}

	return parseInt(elm.offsetHeight);

}


function getElementBottom(p_elm){

	return getElementTop(p_elm) + getElementHeight(p_elm);

}



function getElementProperty(p_elm, p_property){

	var elm = null;

	if(typeof(p_elm) == "object"){

		elm = p_elm;

	} else {

		elm = document.getElementById(p_elm);

	}

	if (elm != null){

		if(elm.style){

			elm = elm.style;

			if(elm[p_property]){

				return elm[p_property];

			} else {

				return null;

			}

		} else {

			return null;

		}

	}

}


function setElementProperty(p_elm, p_property, p_value){

	var elm = null;

	if(typeof(p_elm) == "object"){

		elm = p_elm;

	} else {

		elm = document.getElementById(p_elm);

	}

	if((elm != null) && (elm.style != null)){

		elm = elm.style;

		elm[ p_property ] = p_value;

	}

}
