  var timers=new Array();
  var IsMSIE=(document.all) ? true : false;
  var IsMac =(navigator.appVersion.toLowerCase().indexOf("mac")>-1) ? true : false;
  var currentMNU=null; //current selected root menu

  //parent window containing this script (e.g. for IFRAME mode)
  var pw=self;
  
  function doFalse(){
  	return false;
  }
  
  function doLink(el,sLink){
  	if((!sLink)||(sLink=="")){return}
  	pw.location.href=sLink;
  }

  function doMouseOverItem(el,sOverClass,subid){
  	doSelect(el,sOverClass,subid);
    el.onselectstart=doFalse;
  }

  function doSelect(el,sOverClass,subid){
	if(!el){return}
	var mid=el.getAttribute("mid");
	var mnu=document.getElementById(mid);
	if(!mnu) return;
  	var rid=mnu.getAttribute("rid");
  	
  	//if moved to another menu, then hide last menu
    if(currentMNU) if(currentMNU!=rid) unSelect(document.getElementById(currentMNU));  	
  	currentMNU=rid;

	if(el!=mnu.current){
  		unSelect(mnu);
  		el.classNameOrg =el.className;
		el.className=sOverClass;
  		mnu.current=el;
  	}else{
  		doClearHideTimer(mid);
  		return;
  	}
  	
  	if(typeof(subid)!="undefined"){
	  	//show sub menu if there is one
  		doShowSubMenu(el,subid);
  	}
  }

  function unSelect(mnu){
	doHideSubMenuChildren(mnu);
	resetClass(mnu);
  }

  function resetClass(mnu){
  	if(mnu.current){
  		mnu.current.className=mnu.current.classNameOrg;
  		mnu.current=null
  	}
  }

  function doShowSubMenu(el,id){
	if(!id){return}
	var mnu=document.getElementById(id);  //div that contains table with items - the (sub) menu
	if(!mnu){return}
	
	var mid=el.getAttribute("mid");
	
	var parentMenu=document.getElementById(mid); 		// parent menu

	var rid = mnu.getAttribute("rid");
	//var rootMenu=document.getElementById(rid); 		// root menu

	var mhv=mnu.getAttribute("hv");						// direction of menu (horizontal or vertical)
	var phv=parentMenu.getAttribute("hv");				// direction of parent menu (horizontal or vertical)

	var w=mnu.offsetWidth;
	var h=mnu.offsetHeight;

	 //take care of possible expander arrow;
	//if(IsMSIE)if(!mnu.initialized)if(mhv=="|"){w+=18;mnu.style.width=w}

	//determine positioning parent
	if(mhv=="|"){
		var pel=el;
		//make it look better if parent item width > submenu width
		if((phv=="-")&&(pel.offsetWidth>(w))){mnu.style.width=pel.offsetWidth;w=pel.offsetWidth;}
	}else{
		var pel=parentMenu;
		//horizontal, so same width as parentMenu
		mnu.style.width=parentMenu.offsetWidth;
	}

	//determine new position based on parent
	if(phv=="|"){
			var x=mnugetPageLeft(pel)+pel.offsetWidth;
			var y=mnugetPageTop(pel);
	}else{
			var x=mnugetPageLeft(pel);
			var y=mnugetPageTop(pel)+ pel.offsetHeight;
	}
			
	//IE4+ and ActiveX, Frames, Flash put everything in IFRAME now, so zIndex is correct
	//tricky: move existing mnu (outer TABLE) into a new created IFRAME
	if(IsMSIE && useIframeContainer){
	 if(mnu.tagName!="IFRAME"){ 
		//remember properties of mnu
		mnu.style.margin="0";
		var sMenu=mnu.outerHTML;
		var w=mnu.offsetWidth;
		var h=mnu.offsetHeight;
		
		//destroy mnu, because IFRAME will become new mnu
		mnu.outerHTML="";

		//create new iframe with same id as mnu
		var sHTML='<iframe src="blank.html" id="'+id+'" hv="'+mhv+'" class='+mnu.className+' style="position:absolute;border:0px;padding:0px;top:0px;left:0px;width:'+w+'px;height:'+h+'px;visibility:hidden" frameborder=0 scrolling=no></iframe>';
		//BeforeEnd would cause document to extend scroll height, therefore scroll bar would change
		document.body.insertAdjacentHTML("AfterBegin",sHTML);
		var ifr=document.getElementById(id);
		ifr.rid = rid;

		var t=eval(id+".document");
		var sty='<link REL="stylesheet" TYPE="text/css" HREF="menu.css">'+
				'<script language="JavaScript">var pw=parent;onload=doShow;function doShow(){'+id+'.style.visibility="visible";'+id+'.onmousemove=null;'+id+'.onmouseout=null;}</script>';
	 	t.open();
	 	t.writeln(sty+'\n<body STYLE="background-color:transparent" TOPMARGIN=0 LEFTMARGIN=0 RIGHTMARGIN=0 MARGINHEIGHT=0 MARGINWIDTH=0 onmouseover="pw.doClearHideTimer(\''+id+'\')" onmousemove="pw.doClearHideTimer(\''+id+'\')" onmouseout="pw.doSetHideTimer(\''+id+'\')">'+sMenu+'</body>');
		t.close();
		mnu=ifr;
		//window.status+="+["+id+"]+";
	 }

     //1st level sub menu is an IFRAME so apply correct position to 2nd level one
     //since el in sub menu 1 is now positioned relative to it's IFRAME document, 
     //must add parentMenu offset, if vertical
	 if(mhv=="|"){
	 	if((typeof(parentMenu.parentMenu)!="undefined")||(parentMenu.style.position=="absolute")){
	 		x+=parentMenu.offsetLeft;
	 		y+=parentMenu.offsetTop;
	 	}
	 }
	}

	if((typeof(parentMenu)!="undefined")||(parentMenu.style.position=="absolute")){
	  if(typeof(parentMenu.w)!="undefined"){
		var parw=parentMenu.w;
		var parh=parentMenu.h;
	  }else{
		var parw=parentMenu.offsetWidth;
		var parh=parentMenu.offsetHeight;
	  }
	}else{
		var parw=0;
		var parh=0;
	}	

	var w=mnu.offsetWidth;
	var h=mnu.offsetHeight;

	//for vertical menus, adjust scrolling and body width, so it fits always in visible window
	if(mhv=="|"){
		if((x+w)>=(document.body.clientWidth+document.body.scrollLeft)){
			if(phv!="-"){
				x-=w+parw-2;
			}else{
				x=document.body.clientWidth+document.body.scrollLeft-w;
			}
			//window.status=phv+":"+w+":"+parw+":"+x+":"+document.body.clientWidth+":"+document.body.scrollLeft;
		}
    	
		if((y+h)>=(document.body.clientHeight+document.body.scrollTop)){
			if(phv!="-"){
				y=document.body.clientHeight+document.body.scrollTop-h;
			}else{
				y-=(h+parh);
			}
			//window.status=phv+":"+h+":"+parh+":"+document.body.clientHeight+":"+document.body.scrollTop;
		}
	}
	
	//last menu item should open right aligned
	//if(phv=="-") x-=(w-pel.offsetWidth);

	mnu.w	=w;
	mnu.h	=h;
	mnu.style.left=x;
	mnu.style.top=y;
	//mnu.style.filter="BlendTrans(duration=0.3)";
	doShowMenu(mnu);
	parentMenu.childMenu=mnu;  //link with parent
  	mnu.parentMenu=parentMenu; 
	mnu.initialized=true;
  }
  
  function doShowMenu(mnu){
	//if(mnu.filters) mnu.filters.BlendTrans.Apply();
	//if (window.focus) window.focus();
	mnu.style.visibility="visible";
	mnu.style.display="";
	//if(mnu.filters) mnu.filters.BlendTrans.Play();
  }
   
  function doClearHideTimer(id){
  	var mnu=document.getElementById(id);
  	var rid=mnu.getAttribute("rid");
	//window.status=mnu.id+":"+rid+" hide timer cleared";
  	if(timers[rid]){clearTimeout(timers[rid]);timers[rid]=null}
  }

  function doSetHideTimer(id){
  	var mnu=document.getElementById(id);
	if(!mnu) return;
  	var rid=mnu.getAttribute("rid");
    doClearHideTimer(id);
	timers[rid]=setTimeout("doHideSubMenuRecurse('"+id+"')",450);
  }
    
  function doHideSubMenuChildren(mnu){
	//close all children
	while(mnu.childMenu){
		resetClass(mnu.childMenu);
		pot=document.getElementById(mnu.childMenu.id);
		if(pot){pot.style.visibility="hidden"};
		closedMenu=mnu;
		mnu=mnu.childMenu;
		closedMenu.childMenu=null;
  	}
  }
   
  function doHideSubMenuRecurse(id){
	var mnu=document.getElementById(id);
	doHideSubMenuChildren(mnu);
	if(mnu.childMenu){return}
	//close menus all the way up to root-parent
	while(mnu){
		resetClass(mnu);
		pot=document.getElementById(mnu.id);
		if(pot&&pot.style.position=="absolute"){pot.style.visibility="hidden"}
		var hiddenMenu=mnu;
		mnu=mnu.parentMenu;
		if(!mnu||!mnu.parentMenu){if(mnu){resetClass(mnu)};return} //reached root
	   	hiddenMenu.parentMenu.childMenu=null; //unlink
	}
  }
   
/* ------------- get Element Absolute Left ------------------------------------------------------ */
function mnugetPageLeft(el) {
  var x=0;
  while (el!= null) {
       x += el.offsetLeft;
       el = el.offsetParent;
  }
  return x;
}

/* ------------- get Element Absolute Top  ------------------------------------------------------ */
function mnugetPageTop(el) {
  var y=0;
    while (el!= null) {
	 if(el.tagName!="TR") y += el.offsetTop; 
     el = el.offsetParent;
    }
    return y;
}

/* ------------- get a Style Property    ------------------------------------------------------ */
function getStyle(el,styleProp){
	if (document.defaultView)
		var retValue = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
	else if (el.currentStyle)
		var retValue = eval("el.currentStyle." + styleProp);
	return retValue;
}

var useIframeContainer=false;

function checkForControls(){
	if(document.body){
		if(document.body.readyState=="complete"){
			useIframeContainer=(document.body.getElementsByTagName("IFRAME").length+
							   document.body.getElementsByTagName("SELECT").length+
							   document.body.getElementsByTagName("OBJECT").length)>0;
		}
	}
//	if(useIframeContainer)window.status="using iframes";
}
 
if(IsMSIE){
 document.onreadystatechange=checkForControls;
}  

//---------------------------------------------------------------------------------------------------------
//Menu Class Object
//---------------------------------------------------------------------------------------------------------

var zIndex=0;

function clsMenu(){
	this.Name="";
	this.RootName="";
	this.hv="|";
	this.ItemCount=0;
	this.MenuClass="";
	this.sHTML="";
	this.bIsFirst=true;
	
	this.CreateMenu=CreateMenu;
	this.CreateSubMenu=CreateSubMenu;
	this.OpenSubMenu=OpenSubMenu;
	this.AddItem=AddItem;
	this.AddSubMenuLink=AddSubMenuLink;
	this.MakeDefaultSeparator=MakeDefaultSeparator;
	this.WrapMenu=WrapMenu;
	this.CloseMenu=CloseMenu;
	this.CloseSubMenu=CloseSubMenu;
	this.ExpanderArrow="V";
}
 
function CreateMenu(sName,sDirection,sClass,sExpanderArrow){
	this.Name=sName;
	this.RootName=sName;
	this.hv=sDirection;
	this.MenuClass=sClass;
	this.ExpanderArrow=sExpanderArrow;
		
	if(this.hv=="|"){
		var sWidth=" width=\"100%\" ";
	}else{
		var sWidth="";
	}	
	
	this.sHTML+="<table "+sWidth+" onselectstart=\"return false\" class=\""+ this.MenuClass +"\" style=\"border-collapse:separate;\" hv=\""+ 
				sDirection +"\" id="+ sName +" rid="+ this.RootName +" onmousemove=\"doClearHideTimer('"+ sName +"')\" onmouseout=\"doSetHideTimer('"+ sName +"')\" border=0 cellPadding=0 cellSpacing=0>\n";
	if(this.hv=="-"){
		this.sHTML+="<tr><td><table onselectstart=\"return false\" class=\""+ this.MenuClass +"\" style=\"border-collapse:separate;margin:0px;padding:0px;border:0px;background:none;\" border=0 cellPadding=0 cellSpacing=0><tr>\n";
	}
}

function CreateSubMenu(sDirection,sLink,sTitle,sClass,sItemClass,sItemClassOver){
	var sName="";
	var sText="";

	sText=sTitle;

	zIndex+=1;
	sName=this.Name + "_" + zIndex;

	if (this.hv=="|"){
		//--- expander arrow vertical
		if (this.ExpanderArrow.indexOf("V")>-1) sText="<img width=10 height=10 border=0 style=\"margin-left:0px;margin-top:2px;padding:0px;\" align=right src=\"ico_arrow_right_small.gif\">"+ sText;
	}else {
		//--- expander arrow horizontal
		if (this.ExpanderArrow.indexOf("H")>-1) sText=sText +"&nbsp;<img width=10 height=10 border=0  align=absmiddle src=\"../_icons/ico_arrow_down_small.gif\">";
	}
    	
	this.AddSubMenuLink(sName,sLink,sText,sItemClass,sItemClassOver);

	var rCreateSubMenu=new clsMenu();
	rCreateSubMenu.ExpanderArrow=this.ExpanderArrow;
	rCreateSubMenu.OpenSubMenu(sName,this.RootName,sDirection,sClass);
	return rCreateSubMenu;
}
  
function OpenSubMenu(sName,sRootName,sDirection,sClass){
	this.hv=sDirection;
	this.Name=sName;
	this.RootName=sRootName;

	this.sHTML+="<table width=150 id="+ this.Name +" hv=\""+ this.hv +"\" rid="+ this.RootName +" class=\""+ sClass +"\" border=0 cellPadding=0 cellSpacing=0 style=\"z-index:"+ 
				zIndex +";position:absolute;top:0px;left:0px;visibility:hidden;border-collapse:separate;\" "+
				" onmousemove=\"doClearHideTimer('"+ this.Name +"')\" onmouseout=\"doSetHideTimer('"+ this.Name +"')\" >\n";

	if(this.hv=="-") {this.sHTML+="<tr>\n"}
}

function AddItem(sLink,sTitle,sClass,sClassOver){
 	var re = new RegExp("'","ig");
	var sLink=sLink.replace(re,"\\'");
	var sText=sTitle;

	this.ItemCount+=1;
	this.MakeDefaultSeparator(sClass);
    
	if(this.hv=="|") {this.sHTML+="<tr>\n"}
	 
	this.sHTML+="<td mid="+ this.Name +" style=\"cursor:default;cursor:hand;\" onclick=\"pw.doLink(this,'"+ sLink +"')\" " +
	 		      " onmouseover=\"pw.doMouseOverItem(this,'"+ sClassOver +"')\" class=\""+ sClass +"\" >"+ sText +"</td>\n";
	
 	if(this.hv=="|") {this.sHTML+="</tr>\n"}
}

function AddSubMenuLink(sSubName,sLink,sTitle,sClass,sClassOver){
 	var re = new RegExp("'","ig");
	var sLink=sLink.replace(re,"\\'");
	var sText=sTitle;
	
	this.ItemCount+=1;

	this.MakeDefaultSeparator(sClass);

	if(this.hv=="|") {this.sHTML+="<tr>\n"}
	
	this.sHTML+="<td mid="+ this.Name +" style=\"cursor:default;cursor:hand;\" onclick=\"pw.doMouseOverItem(this,'"+ sClassOver +"','"+ sSubName +"');pw.doLink(this,'"+ sLink +"');\" " +
				  " onmouseover=\"pw.doMouseOverItem(this,'"+ sClassOver +"','"+ sSubName +"')\" class=\""+ sClass +"\" >"+ sText +"</td>\n";

 	if(this.hv=="|") {this.sHTML+="</tr>\n"}

}
 
//default separator
function MakeDefaultSeparator(sClass){
 	//make default item separator
	if(!this.bIsFirst) {
	  if(this.hv=="-") {
	 	this.sHTML+="<td height=100% valign=middle class=\""+ sClass +"\" style=\"margin:0px;border:0px;padding:0px;width:0px;background:none;\"><img class=\"mnuItemSeparatorH\" width=1 height=100% alt=\"\" src=\"../_icons/pt.gif\"></td>";
	  }else{
	 	this.sHTML+="<tr class=\""+ sClass +"\" style=\"margin:0px;padding:0px;border:0px;background:none;\"><td align=center><img class=\"mnuItemSeparatorV\" width=100% height=1 alt=\"\" src=\"../_icons/pt.gif\"></td></tr>";
	  }
	}else{
	  this.bIsFirst=false;
	}
}

function WrapMenu(){
 	if(this.hv=="-") {
 			this.sHTML+="</tr></table><table onselectstart=\"return false\" class=\""+ this.MenuClass +"\" style=\"border-collapse:separate;margin:0px;padding:0px;border:0px;background:none;\" border=0 cellPadding=0 cellSpacing=0><tr>\n";
			this.bIsFirst=true;
	}
}
 
function CloseMenu(){
	if(this.hv=="-") {this.sHTML+="</tr></table></td></tr>\n"}
	
	this.sHTML +="</table>\n";
	return this.sHTML;
}

function CloseSubMenu(){
	if(this.hv=="-") {this.sHTML+="</tr>\n"}

	this.sHTML+="</table>\n";
	return this.sHTML;
}
