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


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

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

function showMenu(id, objPos){
        showHideSelects('none')
	if(document.getElementById){
		clearTimer();
                                       		setElementProperty('1', 'display', 'none');
                                                          		setElementProperty('2', 'display', 'none');
                                                          		setElementProperty('3', 'display', 'none');
                                                                setElementProperty('media_news', 'display', 'none');
                                                          		setElementProperty('client_resources', 'display', 'none');
                                                                openMenu = id;
		canMenuBeClosed = false

		var x = 0;
		var y = 0;
		
		x = getElementLeft(objPos);
		y = getElementBottom(objPos);
		
		/*if(!window.event){
			y-=1;
		}*/
		
		setElementProperty(id, 'display', 'block');
		setElementProperty(id, 'left', x + "px");
		setElementProperty(id, 'top', y + "px");
	}
}

function hideMenu(id){
	setElementProperty(id, 'display', 'none');
        showHideSelects('block')
	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)) ){
		return true;
	} else {
		return false;
	}
}


window.onload = function() {
mMove = document.onmousemove;
document.onmousemove = function(e) {
  getMousePos(e);
  if(mMove)mMove(e);
  return true;
  }
}

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;
	}
}

function showHideSelects(action) {
  if(action == "none") {
        setElementProperty(document.getElementById('dropdown'), 'display', 'none');
        setElementProperty(document.getElementById('noDropdown'), 'display', 'block');
        }
  if(action == "block") {
        setElementProperty(document.getElementById('dropdown'), 'display', 'block');
        setElementProperty(document.getElementById('noDropdown'), 'display', 'none');
        }
}

var y1 = 50;   // change the # on the left to adjuct the Y co-ordinate

(document.getElementById && !document.all) ? dom = true : dom = false;

function typeStart() {
  if (dom) {
    document.write('<div id="logoBox" style="position:absolute; left:' + (window.innerWidth/'2') + '; visibility:visible">') }
  if (document.all) {
    document.write('<div id="logoBox" style="position:absolute; left:' + (document.body.clientWidth/'2') + '; visibility:visible">') }
 }

function typeEnd() {
  if (document.all || dom) { document.write('</div>') }
 }

function placeIt() {
  if (dom) {document.getElementById("logoBox").style.top = window.pageYOffset + (window.innerHeight - 33) ;}
  if (document.layers) {
        document.layers["logoBox1"].left = window.innerWidth/'2';
        document.layers["logoBox1"].top = window.pageYOffset + (window.innerHeight - 33)}
  if (document.all) {document.all["logoBox"].style.top = document.body.scrollTop + (document.body.clientHeight - 33);}
  window.setTimeout("placeIt()", 10);  
 }