// BrowserCheck Variables
var ie4 = (document.all && !document.getElementById) ? true : false;
var ns4 = (document.layers) ? true : false;
var ie5 = (document.all && document.getElementById) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;
var ismac = (navigator.appVersion.indexOf("Mac") != -1)? true:false;

var currentTimeout = 0;
var hasInit = 0;
var origWidth = 0;
var origHeight = 0;
var currentId = "";
var divX = new Object();
var divY = new Object();
var divW = new Object();
var divH = new Object();

var Popups= new Array();
Popups[0] = new Array('AboutDiv', 226, 0, 141, 140);
Popups[1]= new Array('ParticipantsDiv',226,0,141,120);
Popups[2]= new Array('CommunityDiv',226,0,141,100);
Popups[3]= new Array('ResourcesDiv',226,0,141,120);
Popups[4]= new Array('SoftwareDiv',226,0,141,80);

//Popups[1] = new Array('CommunityDiv', 600, 0, 141, 100);
//Popups[2] = new Array('SoftwareDiv', 405, 0, 141, 100);
var Menus=new Array();
Menus[0]='topabout';
//Menus[1]='topcommunity';
//Menus[2]='topsoftware';
Menus[1]='topparticipants';
Menus[2]='topcommunity';
Menus[3]='topresources';
Menus[4]='topsoftware';

function getElement(id) {
	if (ie4 || ie5) {
			return document.all[id];
	}
	if (ns4) {
		return document.layers[id];
	}
	if(ns6) {
		return document.getElementById(id); 
	}
}

function getWidth(id) {
	//alert("Call for get for "+id);
	elem=getElement(id);
	if(ie4||ie5) {
		//thestring=new String(elem.currentStyle["width"]);
		if(id=='beginmenu') {
			thestring=new String("228px");
		}
		if(id=='topabout') {
			thestring=new String("75px");
		}
		if(id=='topparticipants') {
			thestring=new String("68px");
		}
		if(id=='topcommunity') {
			thestring=new String("65px");
		}
		if(id=='topresources') {
			thestring=new String("61px");
		}
		if(id=='topsoftware') {
			thestring=new String("53px");
		}
		
	} else {
		thestring=new String(window.getComputedStyle(getElement(id),null).width);
	}
	//alert("The string is: "+thestring);
	theresult=thestring.substring(0,thestring.length-2);
	//alert(theresult);
	return parseInt(theresult);
}

function setLeft(id) {
	//alert("Before Left");
	elem=getElement(id);
	//alert("Got Element");
	if(ie4||ie5) {
		//alert("Into ie4 or ie5");
		elem.style.left=divX[id]+'px';
		//alert("After setting");
	} else {
		elem.style.setProperty('left',divX[id]+'px',null);
	}
	//alert("New left: "+window.getComputedStyle(document.getElementById(id),null).left+" where was "+divX[id]);
}

function init() {

var previous;

if ( hasInit == 0 ) {
   hasInit = 1;

previous=getWidth('beginmenu');
//alert("Length: "+Popups.length);
for (var i=0; i < Popups.length; i++)
		{
		var id = Popups[i][0];
		var headid= Menus[i];
		//alert("Currentid is "+id);
		if (ie4 || ie5) {
			document.all[id].onmouseout = doOut;
			document.all[id].onmouseover = doDisable;
		}
		if (ns4) {
			origWidth = innerWidth;
			origHeight = innerHeight;
			onresize = reDo;
			document.layers[id].onmouseout = doOut;
			document.layers[id].onmouseover = doDisable;
		}
		if (ns6) {
			document.getElementById(id).onmouseout = doOut;
			document.getElementById(id).onmouseover = doDisable;
		}
		var width;
		width=getWidth(headid);
		divX[id] = previous;
		previous=previous+width+20;
		//alert('Debug: '+divX[id]);
		divY[id] = Popups[i][2];
		divW[id] = Popups[i][3];
		divH[id] = Popups[i][4];
	}
}
}


function doOut(evt) {
	var x = 0;	var left = 0;	var right = 0;
	var y = 0;	var top = 0;	var bottom = 0;
	if (! evt) {evt = window.event};
	if (ns4 || ns6) {
		x = (evt.pageX + window.scrollX);
		y = (evt.pageY + window.scrollY);
	}
	if (ie4 || ie5) {
		x = evt.x+document.body.scrollLeft;
		y = evt.y+document.body.scrollTop; 
	}

	left = divX[currentId];
	right = left + divW[currentId];
	top = divY[currentId];
	bottom = top + divH[currentId];
	if (!((left < x)&&(x<right)&&(top < y)&&( y< bottom))) {
		hide(currentId);
	}
}

function dout(evt) {
	alert("call to doout");
	hide(currentId);
}

function doDisable(evt) {
	window.clearTimeout(currentTimeout);
	return false;
}

function hideAll(){
for (var i=0; i < Popups.length; i++)
		{
		hide(Popups[i][0]);
		}
}

function show(id){
init();
	hideAll();
	setLeft(id);
	if (ns4) document.layers[id].visibility ="show";
	else if (ie4 || ie5) document.all[id].style.visibility="visible";
	else document.getElementById(id).style.visibility="visible";
	currentId = id;
	currentTimeout = window.setTimeout("hide('" + id + "');", 1200);
}

function showDiv(id){
	if (ns4) document.layers[id].visibility ="show";
	else if (ie4 || ie5) document.all[id].style.visibility="visible";
	else document.getElementById(id).style.visibility="visible";
}

function hideDiv(id) {
		if (ns4) document.layers[id].visibility ="hide";
		else if (ie4 || ie5) document.all[id].style.visibility="hidden";
		else document.getElementById(id).style.visibility="hidden";
}

function hide(id){
	if (currentId != "") {
		if (ns4) document.layers[id].visibility ="hide";
		else if (ie4 || ie5) document.all[id].style.visibility="hidden";
		else document.getElementById(id).style.visibility="hidden";
	}
}

