var ns = (navigator.appName == 'Netscape');
var ie = (navigator.appName == 'Microsoft Internet Explorer');
var ns4 = (ns && parseInt(navigator.appVersion) >= 4 && parseInt(navigator.appVersion)<5);
var ie4 = (ie && parseInt(navigator.appVersion) >= 4);
var ns5 = (ns && parseInt(navigator.appVersion) >= 5);
var oper = (window.opera != null);

var DOCloaded = false;
var prev;

var divPOS = new Array();
var divPOSed = new Array();

cRight = 1;
cDownRight = 2;
var LAYOUT = cDownRight;

cOBJ = "object";
cUNDEF = "undefined";
var fuLYOFF = 28;

function ViewProp(obj) {
  var str;
  for (var propName in obj) {
   if (obj[propName])
   str +=propName+"="+obj[propName]+"<br>";
  }
  var win = window.open();
  win.document.writeln(str);
}

function AreaWidth(){
	return getCurrentWinWidth();
}

function AreaHeight(){
	return getCurrentWinHeight();
}

function LMoveTo(ly,X,Y){
	if (typeof(ly) == cOBJ) el = ly; else el = getElt(ly);
	if (el && typeof(el) != cUNDEF) moveEltTo(el, X, Y);
}

function LMoveBy(ly,X,Y){
	if (typeof(ly) == cOBJ) el = ly; else el = getElt(ly);
	if (el && typeof(el) != cUNDEF) moveEltBy(el, X, Y);
}

function LGetX(ly){
	if (typeof(ly) == cOBJ) el = ly; else el = getElt(ly);
	if (el && typeof(el) != cUNDEF) return getEltPageLeft(el);
}

function LGetY(ly){
	if (typeof(ly) == cOBJ) el = ly; else el = getElt(ly);
	if (el && typeof(el) != cUNDEF) return getEltPageTop(el);
}

function LShow(ly){
	if (typeof(ly) == cOBJ) el = ly; else el = getElt(ly);
	if (el && typeof(el) != cUNDEF) showElt(el);
}

function LGetVis(ly){
	if (typeof(ly) == cOBJ) el = ly; else el = getElt(ly);
	if (el && typeof(el) != cUNDEF) return getEltVisibility(el);
}

function LHide(ly){
	if (typeof(ly) == cOBJ) el = ly; else el = getElt(ly);
	if (el && typeof(el) != cUNDEF) hideElt(el);
}

function LSetClip(ly,l,t,r,b){
	if (typeof(ly) == cOBJ) el = ly; else el = getElt(ly);
	if (el && typeof(el) != cUNDEF) setEltClip (el, t, r, b, l);
}

var layertimer = 0;
var lastmenues;
var active = 0;

function killMenus(strWen){
	lastmenues=null;
	if (arguments.length == 2 && arguments[1] == "now") showMenus(strWen, 'off');
	else layertimer = setTimeout("showMenus('"+strWen+"', 'off')", 2000);
	return false;
}

function showMenus(strWen, strStatus, strCoord) {
	if(strStatus == "on"){
		if(layertimer){ clearTimeout(layertimer);}
		layertimer = 0;
	}
//	alert("showMenues " + strStatus + " " + strWen + " " + isMouseIn(strWen));
	var tempWen = strWen.split(",");
	var strOut="";

	if(DOCloaded){
		clearTimeout(active);
		if(lastmenues && lastmenues!=strWen){
			tempLastmenues = lastmenues.split(",");
			for (i=0;i<tempLastmenues.length;i++) { LHide(tempLastmenues[i]); }
			lastmenues = null;
		}
		if(strStatus=="on"){
		    if(strCoord!=null && strCoord!="") tempCoord = strCoord.split("|");
			tempActualLayers=strWen.split(",");
			for (i=0;i<tempWen.length;i++){
				if(strCoord!=null && strCoord!="" && typeof(divPOSed[tempActualLayers[i]]) == cUNDEF){
				    T = tempCoord[i].split(",");
				    if (T[0]!="" && T[1]!="") LMoveTo(tempActualLayers[i], T[0], T[1]);
				    divPOSed[tempActualLayers[i]] = T;
				}
				LShow(tempActualLayers[i]);
          }
			lastmenues = strWen;
		}
		if(strStatus=="off"){
			tempActualLayers=strWen.split(",");
			for (i=0;i<tempWen.length;i++) LHide(tempActualLayers[i]);
		}
	} else {
		active = setTimeout("showMenus('" + strWen + "','" + strStatus + "','"+strCoord+")",2000);
	}
	return false;
}

function show(a,id,layer,idt) {
	clearTimeout(layertimer);
	if (!idt) {idt = id};
	var tempWen = a.split(",");
	var lx = 0, ly = 0, mx = '';
	if (typeof(divPOS[a]) == cUNDEF) {
		for (i = 0; i < tempWen.length; i++) {
			aw = true;
			if (!i && tempWen[i].substr(1) == id.substr(1)) {
				el = getElt(id);
			} else if (!i && tempWen[i] == layer) {
				el = getElt(layer);
				aw = false;
			} else {
				el = getElt(tempWen[i]);
			}
			if (typeof(el) != cUNDEF) {
				if (!i) {
					lx = getEltPageLeft(el);
					ly = getEltPageTop(el);
				}
				ew = getEltWidth(el);
				if (aw) {
					if (LAYOUT == cRight) {
						lx += ((ns4 && !i) ? 190 : getEltWidth(el));
					} else if (LAYOUT == cDownRight && i) {
						lx += getEltWidth(el);
					}
					if (ns4) ly -= ((!i) ? 1 : 0);
					if (i) lx += (ns4)? 3:5;
				}
				if (tempWen[i].substr(1) == id.substr(1)) {
					el = getElt(id);
					if (typeof(el) != cUNDEF && el != null) {
					    ly = getEltPageTop(el) - ((!i)?3:0);
					}
					el = getElt(layer);
					if (typeof(el) != cUNDEF && el != null) {
					    lx += getEltWidth(el) - ew;
					}
				}
				aly = ly;
				if (arguments.length > 4 && i && arguments[4] && typeof(arguments[4].y) != cUNDEF) fuLYOFF = arguments[4].y;
				if (LAYOUT == cDownRight) {
					if (!i) aly += fuLYOFF;
					if (ns4 && !i) aly = 45;
				} else if (LAYOUT == cRight) {
					if (i) aly += fuLYOFF;
				}

				
				sx = AreaWidth();
//				alert(sx);
				if(lx + 170 > sx) lx = sx - 170;
				mx += lx + "," + aly;
				if (i + 1 < tempWen.length) mx += "|";
			}
		}

		divPOS[a] = mx;
	}
//	alert(a + ";" + id + ";" + layer + ";" + idt + "; = " + mx);
	HideAll(a);
	showMenus(a,'on',divPOS[a]);
}

function mousecoord(ev){
    if(ie4){ ev = event;
    	_mouseX = ev.clientX; _mouseY = ev.clientY;
    }else{
    	_mouseX = ev.pageX; _mouseY = ev.pageY;
    }
}


if(ns4){ document.captureEvents(Event.MOUSEMOVE); }
document.onmousemove = mousecoord;

function isMouseIn(a) {
	if (a && a != "" && a!= null) {
	var t = a.split(",");
	for (i = 0; i < t.length; i++) {
		el = getElt(t[i]);
		if (typeof(el) != cUNDEF) {
			l = getEltPageLeft(el); t = getEltPageTop(el);
			if ((_mouseX >= l && _mouseX <= l + getEltWidth(el)) && (_mouseY >= t && _mouseY <= t + getEltHeight(el)))
				return true;
		}
	}}
	return false;
}

function bgcol(e,c) {
	var el = getElt(e);
	if (el && typeof(el) != cUNDEF) setEltBackgroundColor(el,c);
}