/***********************************************
* AnyLink Drop Down Menu- ?Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

/////No further editting needed

// preload menu item images.
if (document.images) {
  var mitembk  = new Image(26,1); mitembk.src  = CurrentUrl + '/public/assets/img/mitembk.gif';
  var mitembko = new Image(1,18); mitembko.src = CurrentUrl + '/public/assets/img/mitembk-o.gif';
} 

var offset = 1;

// adjust offset for older versions of IE
if (navigator.userAgent.indexOf("MSIE") != -1) {
    var temp = navigator.appVersion.split("MSIE") ;
    var ver = parseFloat(temp[1]) ;
    if (ver < 7.0) { offset = -2; }
}

var ie4=document.all
var ns6=document.getElementById&&!document.all

// codejock
var objBtn = 0 ;

if (ie4||ns6)
document.write('<div id="DropDownMenu" style="visibility:hidden;width:' + menuwidth + ';background:url(' + mitembk.src + ') ' + menubgcolor + ' repeat-y;" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
    var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop + offset;
    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, menuwidth){
    if (ie4||ns6)
    objDropDownMenu.style.left=objDropDownMenu.style.top="-500px"
    if (menuwidth!=""){
    objDropDownMenu.widthobj=objDropDownMenu.style
    objDropDownMenu.widthobj.width=menuwidth
    }
    if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
    //obj.visibility="visible"
    fader.fadeIn();
    else if (e.type=="click")
    //obj.visibility="hidden"
    fader.fadeOut();
}

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
    objDropDownMenu.contentmeasure=objDropDownMenu.offsetWidth
    if (windowedge-objDropDownMenu.x < objDropDownMenu.contentmeasure)
    edgeoffset=objDropDownMenu.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
    objDropDownMenu.contentmeasure=objDropDownMenu.offsetHeight
    if (windowedge-objDropDownMenu.y < objDropDownMenu.contentmeasure){ //move up?
    edgeoffset=objDropDownMenu.contentmeasure+obj.offsetHeight
    if ((objDropDownMenu.y-topedge)<objDropDownMenu.contentmeasure) //up no good either?
    edgeoffset=objDropDownMenu.y+obj.offsetHeight-topedge
    }
    }
    return edgeoffset
}

function populatemenu(what){
    if (ie4||ns6)
    objDropDownMenu.innerHTML=what.join("")
}

function backgroundPosition(obj) {
    if (objBtn) { objBtn.style.backgroundPosition = '0px -50px' ; objBtn.style.color = ''; }
    objBtn = obj ;
    if (objBtn) { objBtn.style.backgroundPosition = '0px 0px' ; objBtn.style.color = '#000000'; }
}

function dropdownmenu(obj, e, menucontents, menuwidth){
    if (window.event) event.cancelBubble=true
    else if (e.stopPropagation) e.stopPropagation()
    clearhidemenu()
    objDropDownMenu=document.getElementById? document.getElementById("DropDownMenu") : DropDownMenu
    fader = new DropDownMenuFader(objDropDownMenu, 14, 0, 0, 99)
    populatemenu(menucontents)
    
    if (ie4||ns6){
    backgroundPosition(obj)
    showhide(objDropDownMenu.style, e, menuwidth)
    objDropDownMenu.x=getposOffset(obj, "left")
    objDropDownMenu.y=getposOffset(obj, "top")
    objDropDownMenu.style.left=objDropDownMenu.x-clearbrowseredge(obj, "rightedge")+"px"
    objDropDownMenu.style.top=objDropDownMenu.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"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 dynamichide(e){
    if (ie4&&!objDropDownMenu.contains(e.toElement))
    delayhidemenu()
    else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
    delayhidemenu()
}

function hidemenu(e){
    if (typeof objDropDownMenu!="undefined"){
    if (ie4||ns6)
    //objDropDownMenu.style.visibility="hidden"
    fader.fadeOut();
    backgroundPosition(0)
    }
}

function delayhidemenu(){
    if (ie4||ns6)
    delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
    if (typeof delayhide!="undefined")
    clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
    document.onclick=hidemenu

// Fade interval in milliseconds
// Make this larger if you experience performance issues
DropDownMenuFader.INTERVAL_MILLIS = 25;

// Creates a fader
// element - The element to fade
// speed - The speed to fade at, from 0.0 to 100.0
// initialOpacity (optional, default 100) - element's starting opacity, 0 to 100
// minOpacity (optional, default 0) - element's minimum opacity, 0 to 100
// maxOpacity (optional, default 0) - element's minimum opacity, 0 to 100
function DropDownMenuFader (element, rate, initialOpacity, minOpacity, maxOpacity) {
  this._element = element;
  this._intervalId = null;
  this._rate = rate;
  this._isFadeOut = true;

  // Set initial opacity and bounds
  // NB use 99 instead of 100 to avoid flicker at start of fade
  this._minOpacity = 0;
  this._maxOpacity = 99;
  this._opacity = 99;

  if (typeof minOpacity != 'undefined') {
    if (minOpacity < 0) {
      this._minOpacity = 0;
    } else if (minOpacity > 99) {
      this._minOpacity = 99;
    } else {
      this._minOpacity = minOpacity;
    }
  }

  if (typeof maxOpacity != 'undefined') {
    if (maxOpacity < 0) {
      this._maxOpacity = 0;
    } else if (maxOpacity > 99) {
      this._maxOpacity = 99;
    } else {
      this._maxOpacity = maxOpacity;
    }

    if (this._maxOpacity < this._minOpacity) {
      this._maxOpacity = this._minOpacity;
    }
  }
  
  if (typeof initialOpacity != 'undefined') {
    if (initialOpacity > this._maxOpacity) {
      this._opacity = this._maxOpacity;
    } else if (initialOpacity < this._minOpacity) {
      this._opacity = this._minOpacity;
    } else {
      this._opacity = initialOpacity;
    }
  }

  // See if we're using W3C opacity, MSIE filter, or just
  // toggling visiblity
  if(typeof element.style.opacity != 'undefined') {

    this._updateOpacity = this._updateOpacityW3c;

  } else if(typeof element.style.filter != 'undefined') {

    // If there's not an alpha filter on the element already,
    // add one
    if (element.style.filter.indexOf("alpha") == -1) {

      // Attempt to preserve existing filters
      var existingFilters="";
      if (element.style.filter) {
        existingFilters = element.style.filter+" ";
      }
      element.style.filter = existingFilters+"alpha(opacity="+this._opacity+")";
    }

    this._updateOpacity = this._updateOpacityMSIE;
    
  } else {

    this._updateOpacity = this._updateVisibility;
  }

  this._updateOpacity();
}

// Initiates a fade out
DropDownMenuFader.prototype.fadeOut = function () {
  this._isFadeOut = true;
  this._beginFade();
}

// Initiates a fade in
DropDownMenuFader.prototype.fadeIn = function () {
  this._isFadeOut = false;
  this._beginFade();
}

// Makes the element completely opaque, stops any fade in progress
DropDownMenuFader.prototype.show = function () {
  this.haltFade();
  this._opacity = this._maxOpacity;
  this._updateOpacity();
}

// Makes the element completely transparent, stops any fade in progress
DropDownMenuFader.prototype.hide = function () {
  this.haltFade();
  this._opacity = 0;
  this._updateOpacity();
}

// Halts any fade in progress
DropDownMenuFader.prototype.haltFade = function () {

  clearInterval(this._intervalId);
}

// Resumes a fade where it was halted
DropDownMenuFader.prototype.resumeFade = function () {

  this._beginFade();
}

// Pseudo-private members

DropDownMenuFader.prototype._beginFade = function () {

  this.haltFade();
  var objref = this;
  this._intervalId = setInterval(function() { objref._tickFade(); },DropDownMenuFader.INTERVAL_MILLIS);
}

DropDownMenuFader.prototype._tickFade = function () {

  if (this._isFadeOut) {
    this._opacity -= this._rate;
    if (this._opacity < this._minOpacity) {
      this._opacity = this._minOpacity;
      this.haltFade();
    }
  } else {
    this._opacity += this._rate;
    if (this._opacity > this._maxOpacity ) {
      this._opacity = this._maxOpacity;
      this.haltFade();
    }
  }

  this._updateOpacity();
}

DropDownMenuFader.prototype._updateVisibility = function () {
  
  if (this._opacity > 0) {
    this._element.style.visibility = 'visible';
  } else {
    this._element.style.visibility = 'hidden';
  }
}

DropDownMenuFader.prototype._updateOpacityW3c = function () {
  
  this._element.style.opacity = this._opacity/100;
  this._updateVisibility();
}

DropDownMenuFader.prototype._updateOpacityMSIE = function () {
  
  this._element.filters.alpha.opacity = this._opacity;
  this._updateVisibility();
}

DropDownMenuFader.prototype._updateOpacity = null;

