//** Chrome Drop Down Menu- Author: Dynamic Drive (http://www.dynamicdrive.com)
//** Altered by Adam McNeeney, August 2008

//** Updated: July 14th 06' to v2.0
        //1) Ability to "left", "center", or "right" align the menu items easily, just by modifying the CSS property "text-align".
        //2) Added an optional "swipe down" transitional effect for revealing the drop down menus.
        //3) Support for multiple Chrome menus on the same page.

//** Updated: Nov 14th 06' to v2.01- added iframe shim technique

//** Updated: July 23rd, 08 to v2.4
        //1) Main menu items now remain "selected" (CSS class "selected" applied) when user moves mouse into corresponding drop down menu. 
        //2) Adds ability to specify arbitrary HTML that gets added to the end of each menu item that carries a drop down menu (ie: a down arrow image).
        //3) All event handlers added to the menu are now unobstrusive, allowing you to define your own "onmouseover" or "onclick" events on the menu items.
        //4) Fixed elusive JS error in FF that sometimes occurs when mouse quickly moves between main menu items and drop down menus


var cssdropdown={
disappeardelay: 250, //set delay in miliseconds before menu disappears onmouseout

//No need to edit beyond here////////////////////////

dropmenuobj: null, asscmenuitem: null, domsupport: document.all || document.getElementById, standardbody: null, swipetimer: undefined, bottomclip:0,

getposOffset:function(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;
},

swipeeffect:function(){
  if (this.bottomclip<parseInt(this.dropmenuobj.offsetHeight)){
    this.bottomclip+=10+(this.bottomclip/10) //unclip drop down menu visibility gradually
    this.dropmenuobj.style.clip="rect(0 auto "+this.bottomclip+"px 0)"
  }
  else
    return
  this.swipetimer=setTimeout("cssdropdown.swipeeffect()", 10)
},

css:function(el, targetclass, action){
  var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig")
  if (action=="check")
    return needle.test(el.className)
  else if (action=="remove")
    el.className=el.className.replace(needle, "")
  else if (action=="add" && !needle.test(el.className))
    el.className+=" "+targetclass
},

showhide:function(obj, e){
  this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
  obj.visibility="visible"
  this.css(this.asscmenuitem, "selected", "add")
},

dropit:function(obj, e, dropmenuID){
  if (this.dropmenuobj!=null) //hide previous menu
    this.hidemenu() //hide menu
  this.clearhidemenu()
  this.dropmenuobj=document.getElementById(dropmenuID) //reference drop down menu
  this.asscmenuitem=obj //reference associated menu item
  this.showhide(this.dropmenuobj.style, e)
  this.dropmenuobj.x=this.getposOffset(obj, "left") - 1;
  this.dropmenuobj.y=84; //this.getposOffset(obj, "top") + 80
  this.dropmenuobj.style.left=this.dropmenuobj.x+"px"
  this.dropmenuobj.style.top=this.dropmenuobj.y+obj.offsetHeight+1+"px"
},

isContained:function(m, e){
  var e=window.event || e
  var c=e.relatedTarget || ((e.type=="mouseover")? e.fromElement : e.toElement)
  while (c && c!=m)try {c=c.parentNode} catch(e){c=m}
  if (c==m)
    return true
  else
    return false
},

dynamichide:function(m, e){
  if (!this.isContained(m, e)){
    this.delayhidemenu()
  }
},

delayhidemenu:function(){
  this.delayhide=setTimeout("cssdropdown.hidemenu()", this.disappeardelay) //hide menu
},

hidemenu:function(){
  this.css(this.asscmenuitem, "selected", "remove")
  this.dropmenuobj.style.visibility='hidden'
  this.dropmenuobj.style.left=this.dropmenuobj.style.top=0
},

clearhidemenu:function(){
  if (this.delayhide)
  {
    clearTimeout(this.delayhide);
    this.delayhide = undefined;
  }
},

addEvent:function(target, functionref, tasktype){
  if (target.addEventListener)
    target.addEventListener(tasktype, functionref, false);
  else if (target.attachEvent)
    target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)});
},

startchrome:function(){
  if (!this.domsupport)
    return
  this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
  for (var ids=0; ids<arguments.length; ids++){
    var menuitems=document.getElementById(arguments[ids]).getElementsByTagName("span")
    for (var i=0; i<menuitems.length; i++){
      if (menuitems[i].getAttribute("rel")){
        var relvalue=menuitems[i].getAttribute("rel")
        var asscdropdownmenu=document.getElementById(relvalue)
        this.addEvent(asscdropdownmenu, function(){cssdropdown.clearhidemenu()}, "mouseover")
        this.addEvent(asscdropdownmenu, function(e){cssdropdown.dynamichide(this, e)}, "mouseout")
        this.addEvent(asscdropdownmenu, function(){cssdropdown.delayhidemenu()}, "click")
        this.addEvent(menuitems[i], function(e){ //show drop down menu when main menu items are mouse over-ed
          if (!cssdropdown.isContained(this, e)){
            var evtobj=window.event || e
            cssdropdown.dropit(this, evtobj, this.getAttribute("rel"))
          }
        }, "mouseover")
        this.addEvent(menuitems[i], function(e){cssdropdown.dynamichide(this, e)}, "mouseout") //hide drop down menu when main menu items are mouse out
        this.addEvent(menuitems[i], function(){cssdropdown.delayhidemenu(); return false;}, "click") //hide drop down menu when main menu items are clicked on
      }
    } //end inner for
  } //end outer for
} //end startchrome

}

