/***********************************/
/*                                 */
/*  AnyLink Dropdown Menu          */
/*  http://www.dynamicdrive.com/   */
/*                                 */
/*  Modifications by Ian McLean    */
/*  http://www.digitalink.com.au/  */
/*                                 */
/***********************************/

var ie4=document.all
var ns6=document.getElementById&&!document.all
var agent = navigator.userAgent.toLowerCase()

if (ie4||ns6)
/* document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')*/
document.write('<div id="dropmenudiv" style="visibility:hidden;background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onmouseout="checkhide(event);"></div>') 

if (ie4||ns6)
document.write('<div id="submenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="subclearhidemenu()" onMouseout="subdynamichide(event)"></div>') 
/*  document.write('<div id="submenudiv" style="visibility:hidden;background-color:'+menubgcolor+'" onMouseover="subclearhidemenu()" onMouseout="subdynamichide(event)"></div>')*/


function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style

// Commented out by IM to allow menu to determine its own width
// uncommented due to stupid effin IE not able to auto-size divs properly..useless I say!

dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function subshowhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
subdropmenuobj.style.left=subdropmenuobj.style.top=-500
if (menuwidth!=""){
subdropmenuobj.widthobj=subdropmenuobj.style
subdropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}


function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function subclearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
subdropmenuobj.contentmeasure=subdropmenuobj.offsetWidth
if (windowedge-subdropmenuobj.x < subdropmenuobj.contentmeasure)
edgeoffset=subdropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
subdropmenuobj.contentmeasure=subdropmenuobj.offsetHeight
if (windowedge-subdropmenuobj.y < subdropmenuobj.contentmeasure){ //move up?
edgeoffset=subdropmenuobj.contentmeasure+obj.offsetHeight
if ((subdropmenuobj.y-topedge)<subdropmenuobj.contentmeasure) //up no good either?
edgeoffset=subdropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}



function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}

function subpopulatemenu(what){
	subdropmenuobj=document.getElementById? document.getElementById("submenudiv") : submenudiv
if (ie4||ns6)
subdropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
//dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
//dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+(tablewidth-obj.offsetWidth)+"px"
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+1+"px"


// This works
//dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+tablewidth+5+"px"



//dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"


dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"

}

return clickreturnvalue()
}



function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function contains (container, containee) {
  while (containee) {
    if (container == containee) {
      return true;
    }
    containee = containee.parentNode;
  }
  return false;
}

function dynamichide(e){
	
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}


function checkhide(e){
	subdropmenuobj=document.getElementById? document.getElementById("submenudiv") : submenudiv
	if (subdropmenuobj.style.visibility=="hidden")
	dynamichide(e)
}


function dynamichidefromsub(e){		
if (ie4&&!dropmenuobj.contains(e.toElement))
//alert (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
//alert (ns6&&e.currentTarget)
delayhidemenu()

}


function checkhidefromsub(e){
	subdropmenuobj=document.getElementById? document.getElementById("submenudiv") : submenudiv
//	alert(subdropmenuobj.style.visibility)
	if (subdropmenuobj.style.visibility=="hidden")
	dynamichidefromsub(e)
}

function subdynamichide(e){
	mainmenuobj=document.getElementById? document.getElementById("menu") : menu
	subdropmenuobj=document.getElementById? document.getElementById("submenudiv") : submenudiv
//	alert("alert")
if (ie4&&!subdropmenuobj.contains(e.toElement)) {	
	subhidemenu()
	if (ie4&&!dropmenuobj.contains(e.toElement))
//	if ((ie4&&!dropmenuobj.contains(e.toElement)) && (ie4&&!mainmenuobj.contains(e.toElement)))
	// *** CHANGED
	delayhidemenu()
//		hidemenu()
}
		//subdelayhidemenu()
//else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))  
else if (ns6&&(!contains(subdropmenuobj, e.relatedTarget) ))  {
	subhidemenu()
	if (ns6&&(!contains(dropmenuobj, e.relatedTarget) )) 
//	if ((ns6&&(!contains(dropmenuobj, e.relatedTarget) )) && (ns6&&(!contains(mainmenuobj, e.relatedTarget) )) )
	// ** CHANGED
	//	hidemenu()
	delayhidemenu();
}
//hidemenu()
//else if (dropmenuobj.innerHTML.my_car.indexOf(e.relatedTarget.innerHTML) > -1)
//else //if ((dropmenuobj.innerHTML.indexOf(e.relatedTarget)> -1) | (dropmenuobj.innerHTML.indexOf(e.relatedTarget.src)> -1))
//alert(dropmenuobj.innerHTML.indexOf(e.relatedTarget) + " " + dropmenuobj.innerHTML + " " + e.relatedTarget)
//subdelayhidemenu()
}

function subhidemenus(e){	
	subdynamichide(e)
//	subdropmenuobj=document.getElementById? document.getElementById("submenudiv") : submenudiv
//	alert(subdropmenuobj.style.visibility)
//	if (subdropmenuobj.style.visibility=="hidden")
//	alert("->" + e.relatedTarget + "<-")
	checkhidefromsub(e)	
//		alert(subdropmenuobj.style.visibility)
//	dynamichide(e)
}


function hidemenu(e){
	
//alert(dropmenuobj.style.visibility)
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
	dropmenuobj.style.visibility="hidden"
}
//subhidemenu(e)
}

function subhidemenu(e){
if (typeof subdropmenuobj!="undefined"){
if (ie4||ns6)
subdropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function subdelayhidemenu(){
if (ie4||ns6)
subdelayhide=setTimeout("subhidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

function subclearhidemenu(){
if (typeof subdelayhide!="undefined")
clearTimeout(subdelayhide)
}
if (hidemenu_onclick=="yes")
document.onclick=hidemenu


function submenu(obj, e, menucontents, menuwidth){	
	dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
	
	dropmenuobj.widthobj=dropmenuobj.style
	mw = dropmenuobj.widthobj.width
	mw = parseInt(mw.replace(/px/,''))
//	alert(mw)
	if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
subclearhidemenu() 
subdropmenuobj=document.getElementById? document.getElementById("submenudiv") : submenudiv

subpopulatemenu(menucontents)
if (ie4||ns6){	
subshowhide(subdropmenuobj.style, e, "visible", "hidden", menuwidth)
subdropmenuobj.x=getposOffset(obj, "left")
subdropmenuobj.y=getposOffset(obj, "top") 
//subdropmenuobj.style.left=subdropmenuobj.x-subclearbrowseredge(obj, "rightedge")+tablewidth+"px"
//subdropmenuobj.style.left=subdropmenuobj.x+tablewidth+10+"px"

subdropmenuobj.style.left=subdropmenuobj.x+mw+"px"
subdropmenuobj.style.top=subdropmenuobj.y+"px"	
}
return clickreturnvalue()

}