var timeout1=0, lid=null ,bw
var menuOffsetTop =-52 , menuOffsetLeft=110  //edit these values to shift offset of menu to header link, use either positive or negative values as required.
menuOffsetTop =0 ; menuOffsetLeft=-3
function getBrowser(){
this.dom = document.getElementById?true:false
this.ie4 = (document.all && !this.dom)?true:false
this.ns4 = (document.layers && !this.dom)?true:false
this.mac = navigator.userAgent.indexOf("Mac")>-1
this.gecko =navigator.userAgent.indexOf("Gecko")>-1
this.opera = navigator.userAgent.indexOf('Opera')>-1
this.ie = (document.all && !this.opera)?true:false
//this.w3cDTD=false;if(this.dom && !this.opera){var layer=document.createElement('DIV');layer.style.width='1px';layer.style.border='1px solid Black';document.body.appendChild(layer);if(layer.offsetWidth==3)this.w3cDTD=true;document.body.removeChild(layer);} //opera does not support appendChild because it is shit
this.obj=function (id,nest){var object= this.dom?document.getElementById(id):this.ie4?document.all[id]:this.ns4?(nest)? eval("document."+ nest +".document['"+ id +"']"):document[id]:0;object.css=this.dom||this.ie4?object.style:object; return object;}
}

function getOffsetLeft (el) {
  var ol = el.offsetLeft;
  while ((el = el.offsetParent) != null)ol += el.offsetLeft;
  if(bw.mac){ 
	  var mleft=parseInt(document.body.currentStyle.marginLeft)
	  if(!isNaN(mleft))ol+=mleft
	  }
  return ol;
}
function getOffsetTop (el) {
  var ot = el.offsetTop;
  while((el = el.offsetParent) != null) ot += el.offsetTop;
  if(bw.mac){ 
	  var mtop=parseInt(document.body.currentStyle.marginTop)
	  if(!isNaN(mtop))ot+=mtop
	  }
  return ot;
}

function showmenu(menu,callobj,vis){
if(!bw){
	bw= new getBrowser()
/*	if(bw.w3cDTD){ //if DTD strict browser complient then update class to reduce drop menu width by border widths
		var menustyle=getStyleClass(bw.obj(menu).className)
		if(menustyle) menustyle.style.width = parseInt(menustyle.style.width) - parseInt(menustyle.style.borderLeftWidth) - parseInt(menustyle.style.borderRightWidth)
	}*/
}
var dmenu= bw.obj(menu)
var title= bw.obj(callobj)
if(!dmenu.onmouseout){dmenu.onmouseover = mlayers;dmenu.onmouseout = mlayers;} //set function for layers
if(timeout1!=0){clearTimeout(timeout1);	timeout1=0;} //clear any timer functions
if(lid!=null && lid!=menu)menuvis(lid,false)//hide any open layers
if (vis){//set position of menu
//	dmenu.css.top = menuOffsetTop + ((bw.dom || bw.ie4)?(getOffsetTop(title) + title.offsetHeight):(title.pageY + title.clip.height+1))
//	dmenu.css.left = menuOffsetLeft + ((bw.dom || bw.ie4)?getOffsetLeft(title):title.pageX)
//	dmenu.css.top = menuOffsetTop + ((bw.dom || bw.ie4)?(getOffsetTop(title)):(title.pageY ))
	menuvis(menu,true)
//	window.status =dmenu.css.top +":"+ dmenu.css.left +":"+ dmenu.css.visibility	
}else{
	timeout1=setTimeout("menuvis('"+ menu + "',false)",300)
}
}

function menuvis(id,show){
bw.obj(id).css.visibility=(show?bw.ns4?"show":"visible":bw.ns4?"hide":"hidden")
lid=(show)?id:null
}

function mlayers(evt){
var action = (bw.ns4)? evt.type :(bw.ie)?event.type:evt.type; 
var menu = this.id
if(timeout1!=0){clearTimeout(timeout1);timeout1=0;}
if(action=="mouseout"){
	timeout1=setTimeout("menuvis('"+ menu + "',false)",300)
	}
}

function getStyleClass (className) {
if (bw.ie) {
    for (var s = 0; s < document.styleSheets.length; s++)
      for (var r = 0; r < document.styleSheets[s].rules.length; r++)
        if (document.styleSheets[s].rules[r].selectorText == '.' + className){
			return document.styleSheets[s].rules[r];
			}
  }
  else if (bw.dom) {
    for (var s = 0; s < document.styleSheets.length; s++)
      for (var r = 0; r < document.styleSheets[s].cssRules.length; r++)
        if (document.styleSheets[s].cssRules[r].selectorText == '.' + className)
          return document.styleSheets[s].cssRules[r]
  }
  return null;
}
