var imgobjpd = new Array();
var imgmopd = new Array();
var pdstatusimages = new Array();
var pdimgopen = new Array();
var pdimgclose = new Array();
var MenuValues = new Array();
var PdLayAmnt = 2;
var firstrun=0;
visproperty = 0;
LayStartPosTop = 1;

function setmenuvalues(PdLayAmnt, menustatus) { 
	for (var i=0; i < PdLayAmnt; i++) {
		MenuValues[i] = new Array();
		MenuValues[i][visproperty] = menustatus;
		MenuValues[i][LayStartPosTop] = 0;
	}
	if(document.all) {
		document.all["addlay"].style.top = 0;
	}
	if(is.ns7) {
		document.getElementById("addlay").style.top = 0;
		document.getElementById("addlay").style.visibility = "visible"; // set the visibility to visible (NS7 needs explicid definition)
	}
}

function openclose() { //ghost function, is called instead of a real url in href's of <a>tags that are only title of Pull-Down-Menu's
window.status="";
}

function markpd(no) {
	imgobjpd[no].src = imgmopd.src;
}

function normpd(no) {
	imgobjpd[no].src = "/icons/ecblank.gif";
}

function SwitchVisibility(no) {
	if(MenuValues[no][visproperty] == "hidden") {
		MenuValues[no][visproperty] = "visible";
		pdstatusimages[no].src = pdimgclose[no].src;
	}
	else {
		MenuValues[no][visproperty] = "hidden";
		pdstatusimages[no].src = pdimgopen[no].src;
	}
	RefreshPdPosition(no);
}

function InitImages() {
	MoImgSrc = "/"+dbpath+"/Files/Sitelocator/$file/pdarrow_white.gif";
	if(document.layers) {	
		for(var i = 0; i < PdLayAmnt; i++) {
			imgobjpd[i] = document.layers["LeftNavigation"].document.layers["sl"].document.layers[LayerTitleName[i]].document.layers[LayerMoName[i]].document.images["imgpd"+i];
			pdstatusimages[i] = document.layers["LeftNavigation"].document.layers["sl"].document.layers[LayerTitleName[i]].document.layers[LayerMoName[i]].document.images["pdstatusimg"+i];
			imgmopd[i] = new Image;
			imgmopd[i].src = MoImgSrc;
		}
	}
	if(document.all){
		for(var i = 0; i < PdLayAmnt; i++) {
			imgobjpd[i] = document.images["imgpd"+i];
			pdstatusimages[i] = document.images["pdstatusimg"+i];
			imgmopd[i] = new Image;
			imgmopd[i].src = MoImgSrc;
		}
	}
	if(is.ns7){
		for(var i = 0; i < PdLayAmnt; i++) {
			imgobjpd[i] = document.images["imgpd"+i];
			pdstatusimages[i] = document.images["pdstatusimg"+i];
			imgmopd[i] = new Image;
			imgmopd[i].src = MoImgSrc;
		}
	}
	for(var i = 0; i < PdLayAmnt; i++) {
		pdimgclose[i] = new Image;
		pdimgclose[i].src = "/"+dbpath+"/Files/Sitelocator/$file/pdclose.gif";
		pdimgopen[i] = new Image;
		pdimgopen[i].src = "/"+dbpath+"/Files/Sitelocator/$file/pdopen.gif";
	}
}

function markpd(no) {
	imgobjpd[no].src = imgmopd[no].src;
}

function normpd(no) {
	imgobjpd[no].src = "/icons/ecblank.gif";
}

function InitPdNames() {
	LayerTitleName = new Array();
	LayerTitleName = InitPdNames.arguments;
	PdLayAmnt = LayerTitleName.length;
	LayerContentName = new Array();
	LayerMoName = new Array();
	LayerControlName = new Array();
	for(var j=0; j<PdLayAmnt; j++) {
		LayerContentName[j] = LayerTitleName[j]+"CONTENT";
		LayerMoName[j] = LayerTitleName[j]+"MO";
		LayerControlName[j] = LayerTitleName[j]+"Control";
	}
}

function convToNum(value) {
	var output, temp;
	for(var i=0; i<value.length; i++) {
		temp = value.charAt(i);
		if(isNaN(temp) == false) {
			output = Number(value.substring(0,i+1));
		}
	}
	return output;
}

function RefreshPdPosition(no) {
	posY=MenuValues[no][LayStartPosTop];
	if(document.layers) {
		parentPath = document.layers["LeftNavigation"].document.layers["sl"];
		for(var i = no; i < PdLayAmnt; i++) {
			parentPath.document.layers[LayerContentName[i]].visibility = "hide";
			parentPath.document.layers[LayerTitleName[i]].visibility = "hide";
		}
		for(var i = no; i < PdLayAmnt; i++) {
			parentPath.document.layers[LayerTitleName[i]].top = posY;
			MenuValues[i][LayStartPosTop] = posY;
			posY += parentPath.document.layers[LayerTitleName[i]].document.layers[LayerControlName[i]].clip.height;
			if(MenuValues[i][visproperty] == "visible") {
				parentPath.document.layers[LayerContentName[i]].top = posY;
				posY += parentPath.document.layers[LayerContentName[i]].clip.height;
			}
		}
		if(firstrun == 0) {
			firstrun=1;
			posAlt=posY;
			parentPath.document.layers["addlay"].top += posY;
		}
		diff = posY-posAlt;
		posAlt = posY;
		parentPath.document.layers["addlay"].top += diff;
		parentPath.clip.height = posY+parentPath.document.layers["addlay"].clip.height;
		for(var i = no; i < PdLayAmnt; i++) {
			parentPath.document.layers[LayerContentName[i]].visibility = MenuValues[i][visproperty];
			parentPath.document.layers[LayerTitleName[i]].visibility = "show";
		}
	}
	if(document.all) {
		for(var i = no; i < PdLayAmnt; i++) {
			document.all[LayerContentName[i]].style.visibility = "hidden";
			document.all[LayerTitleName[i]].style.visibility = "hidden";
		}
		for(var i = no; i < PdLayAmnt; i++) {
			document.all[LayerTitleName[i]].style.top = posY;
			MenuValues[i][LayStartPosTop] = posY;
			posY += document.all[LayerControlName[i]].offsetHeight;
			if(MenuValues[i][visproperty] == "visible") {
				document.all[LayerContentName[i]].style.top = posY;
				posY += document.all[LayerContentName[i]].offsetHeight;
			}
		}
		if(firstrun == 0) {
			firstrun=1;
			posAlt=posY;
			temptop = parseInt(document.all["addlay"].style.top);
			document.all["addlay"].style.top = temptop+posY;
		}
		diff = posY-posAlt;
		posAlt = posY;
		temptop = parseInt(document.all["addlay"].style.top); //iexplorer returns result with unit of measurement(e.g. px), the function extract the number
		document.all["addlay"].style.top = temptop + diff;
		for(var i = no; i < PdLayAmnt; i++) {
			document.all[LayerContentName[i]].style.visibility = MenuValues[i][visproperty];
			document.all[LayerTitleName[i]].style.visibility = "visible";
		}
	}
	if(is.ns7) {
		for(var i = no; i < PdLayAmnt; i++) {
			document.getElementById(LayerContentName[i]).style.visibility = "hidden";
			document.getElementById(LayerTitleName[i]).style.visibility = "hidden";
//		alert(LayerContentName[i]+";"+i+";"+document.getElementById(LayerContentName[i]).style.visibility);
		}
		for(var i = no; i < PdLayAmnt; i++) {
//			alert(LayerContentName[i]+";"+i);
			document.getElementById(LayerTitleName[i]).style.top = posY;
			MenuValues[i][LayStartPosTop] = posY;
			posY += 2 + parseInt(getProperty(LayerControlName[i],'height'));
//			alert(LayerControlName[i]+"="+parseInt(getProperty(LayerControlName[i],'height')));
			if(MenuValues[i][visproperty] == "visible") {
				var LayerTableName = 'htmlcontent'+i;
//				alert(LayerTableName);
				document.getElementById(LayerContentName[i]).style.top = posY;
				posY += 2 + parseInt(getProperty(LayerTableName,'height'));
//				alert(parseInt(getProperty(LayerTableName,'height')));
//				alert(LayerContentName[i]+"="+parseInt(getProperty(LayerContentName[i],'height')));
			}
//		alert(posY);
//		alert(LayerContentName[i]+";"+i+";"+document.getElementById(LayerContentName[i]).style.visibility);
		}
		if(firstrun == 0) {
			firstrun=1;
			posAlt=posY;
			temptop = parseInt(document.getElementById("addlay").style.top);
//			document.getElementById("addlay").style.visibility = "visible";
//			alert(document.getElementById("addlay").style.visibility);
			document.getElementById("addlay").style.top = temptop+posY;
		}
		diff = posY-posAlt;
		posAlt = posY;
//		alert(parseInt(document.getElementById("addlay").style.top))
//		else alert("no:"+parseInt(document.getElementById("addlay").style.top));
		temptop = parseInt(document.getElementById("addlay").style.top); //iexplorer returns result with unit of measurement(e.g. px), the function extract the number
//		alert(temptop+"+"+diff);
		document.getElementById("addlay").style.top = temptop + diff;
//		alert(document.getElementById("addlay").style.top);
		for(var i = no; i < PdLayAmnt; i++) {
			document.getElementById(LayerContentName[i]).style.visibility = MenuValues[i][visproperty];
			document.getElementById(LayerTitleName[i]).style.visibility = "visible";
		}
	}
}

function getProperty(objId,objProperty) {
	var objLayer = getLayerRef(objId);
	var o = document.defaultView.getComputedStyle(objLayer, '');
	var p = o.getPropertyValue(objProperty);
	return p;
}

function getLayerRef (id, document) {
  if (!document)
    document = window.document;
  if (document.layers) {
    for (var l = 0; l < document.layers.length; l++)
      if (document.layers[l].id == id)
        return document.layers[l];
    for (var l = 0; l < document.layers.length; l++) {
      var result = getLayerRef(id, document.layers[l].document);
      if (result)
        return result;
    }
    return null;
  }
  else if (document.all) {
    return document.all[id];
  }
  else if (document.getElementById) {
    return document.getElementById(id);
  } else {
    return null;
  }
}