var contain = new Array();
var contain2 = new Array();
var mstrCurrMenu = "";
var checkIt;
var mstrType = "vert" //"vert" = vertical menu; "horz" = horizontal

var DHTML = (document.getElementById || document.all || document.layers);

function show(name,lvl,obj, left, parent_element_name) {
	//alert("in show");
	if (!DHTML) return;
	
	var pobjMenu;

    checkUserInput();
	/*if (window.innerWidth) {
 	   ScreenW = window.innerWidth
	} else if (document.body) {
	  	if (document.body.clientWidth) {
	    	ScreenW = document.body.clientWidth
	    }
	}*/
	//alert((mstrCurrMenu == name));
    if (mstrCurrMenu == name) return;
	//alert((mstrCurrMenu == name));
	//close any visible menus
	closeAll();
		//alert("After Close All");
	
	/*} else if (mstrCurrMenu != "") {
		pobjMenu = getObj(mstrCurrMenu);
		pobjMenu.visibility='hidden';
	}*/
	//if (contain[lvl] && contain[lvl] == name) return;
    
	/*if (contain[lvl]) {
		closeAll(lvl);
    }*/
    if (name) {
		mstrCurrMenu = name;
//		pobjMenu = getObj(name);
		
		aobjParent = document.getElementById(parent_element_name);
        //pobjMenu.visibility = 'visible';
		var parentX = findPosX(aobjParent);
		var parentY = findPosY(aobjParent);
		var x;
		var y;
		if (mstrType == "vert") {
			x = parentX + aobjParent.offsetWidth + 2;//parentX;
			y = parentY; // + parent_element.offsetHeight;
		} else if (mstrType == "horz") {
			x = parentX;
			y = parentY + aobjParent.offsetHeight;				
		}	
		showLayer(name, x, y);

	} else {
		alert("no name");
	}
    //contain[lvl] = name;
	
}

function findPosX(obj)
{

	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
		//if (what == 'ie') curleft = curleft/2;
		
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function setPosX(obj, x) {

	if (obj.offsetLeft)	{
		obj.offsetLeft = x;
	}
	else if (obj.left) {
		obj.left = x;
	}
}
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
		if (what == 'ie') {
			//curtop = curtop/2;

		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function setPosY(obj, y){
	if (obj.offsetTop) {
		obj.offsetTop = y;
	} else if (obj.top) {
		obj.top = y;
	}
}
function closeAll()
{
        /*for (i=contain.length - 1;i>=lvl;i--)
        {
                if (contain[i]) //IE4 Mac
                {
                        var x = getObj(contain[i]);
                        x.visibility = 'hidden';
                }
                contain[i] = null;
                if (contain2[i])
                {
                        contain2[i].className = '';
                        contain2[i] = null;
                }
        }*/

	if (mstrCurrMenu != "") {
		try {
			hideLayer(mstrCurrMenu);
			//var pobjMenu = findObj(mstrCurrMenu);
	
			//if (pobjMenu) pobjMenu.visibility='hidden';
		} catch(ex) {}

	}
	mstrCurrMenu = "";
}

function checkUserInput()
{
        if (checkIt) clearTimeout(checkIt);
        checkIt = setTimeout('closeAll()',5000);
}

function getObj(name)
{
  if (document.getElementById)
  {
    return document.getElementById(name).style;
  }
  else if (document.all)
  {
    return document.all[name].style;
  }
  else if (document.layers)
  {
    return document.layers[name];
  }
  else return false;
}

//*
function reDo(){ window.location.reload() }
//*
//Define global variables
var timerID = null;
var timerOn = false;
var timecount = 800;
var what = null;
var newbrowser = true;
var check = false;
//*
function init(){
	if(document.all){
		//  IE
		layerRef="document.all";
		styleSwitch=".style";
		visibleVar="visible";
		screenSize = document.body.clientWidth + 18;
		what ="ie";
	}
	else if (document.layers) {
		//  Netscape 4
		layerRef="document.layers";
		styleSwitch="";
		visibleVar="show";
		screenSize = window.innerWidth;
		what ="ns4";
	}
	else if(document.getElementById){
		//  Netscape 6
		layerRef="document.getElementByID";
		styleSwitch=".style";
		visibleVar="visible";
		what="moz";
	}
	else{
		// Older than 4.0 browser
		what="none";
		newbrowser = false;
	}
	check = true;
} // init
//*
function showLayer(layerName,left ,top ){
	top+=5;
	if(check){

		if (what =="none"){
			return;
		}
		else if ((what == "moz") || (what == "ie")) {
			var pobj = getObj(layerName);
			pobj.visibility="visible";
			if (what == "moz") {
				pobj.top = top+'px';
				pobj.left = left+'px';
			} else {
				pobj.top=top;
				pobj.left=left;
			}
		}
		else{
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.left=left');
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.top=top');
		}
	}
	else {
		return;
	}
} // showLayer
//*
function hideLayer(layerName){
	if(check){
		if (what =="none"){
			return;
		}
		else if (what == "moz"){
			document.getElementById(layerName).style.visibility="hidden";
		}
		else{
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
		}
	}
	else {// alert ("Please wait for the page to finish loading.");
		return;
	}
} // hideLayer
