var showhide = 0; // the switch view variable for the drop down menu

// MENU: when the drop down div is clicked this shows or hides the state or city menu based on the seting of the "showhide" variable
function SelectSim(obj) {

	var obj = document.getElementById(obj);
	
	if(showhide == 0) {
		popUp(obj);
		showhide = 1;
		HideSelect(obj);
	}
	else {
		popDown(obj);
	}
}

// MENU: auto hides the drop down menu after 15 seconds
function HideSelect(obj) {

this.obj = obj;

	this.hideobj = function(){
	popDown(this.obj);
	}

	setTimeout("this.hideobj();", 15000);
}

// ALL: get an elements width
Object.prototype.getElementWidth = function() {
	if (typeof this.clip !== "undefined") {
		return this.clip.width;
	} else {
		if (this.style.pixelWidth) {
			return this.style.pixelWidth;
		} else {
			return this.offsetWidth;
		}
	}
}

// MENU: shows drop down menu and finds its correct position
function popUp(obj) {

	var menu = obj.previousSibling;

	while (menu.nodeType == '3') {
		menu = menu.previousSibling;
	}

	var objtop = menutop(menu);
	var objleft = menuleft(menu);

	var parentdiv = document.getElementById('main');

	var parentstop = menutop(parentdiv);
	var parentsleft = menuleft(parentdiv);

	var settop = (objtop - parentstop + 99);
	var setleft = (objleft - parentsleft);

	obj.style.top = settop +'px';
	obj.style.left = setleft + 'px';
	obj.style.display = 'block';
}

// MENU: hides drop down menu
function popDown(obj) { 

	obj.style.top = '-500px';
	obj.style.left = '-500px';
	obj.style.display = 'none';
	
	showhide = 0;
	clearTimeout;
}

// ALL: get an elemants top pixel position
function menutop(menu) {

var posy = 0;

	while (menu != null) {

		posy += menu.offsetTop;
		menu = menu.offsetParent;
	}

	return posy;
}

// ALL: get an elemants left pixel position
function menuleft(menu) {

var posx = 0;

	while (menu != null) {

		posx += menu.offsetLeft;
		menu = menu.offsetParent;
	}

	return posx;
}