// CBE Cascading Drop-down Menu Copyright(c)2002 Mike Foster (cross-browser.com) (Licensed under the LGPL)

var
	cbeMenu,
	mnuMarker,
	downgrade = true,
	ua = navigator.userAgent.toLowerCase();

if (
	ua.indexOf('msie') != -1 && parseInt(navigator.appVersion) >= 4  // IE4 up
	|| ua.indexOf('gecko') != -1                                     // Gecko
	|| ua.indexOf('konqueror') != -1                                 // Konquerer
	|| window.opera                                                  // Opera
	)
	{
	document.write("<script type='text/javascript' src='js/cbe_core.js'></script>");
	document.write("<script type='text/javascript' src='js/cbe_event.js'></script>");
	downgrade = false;
	}

function windowOnload() {
	mnuMarker = cbeGetElementById('mnuMarker').cbe;
	cbeMenu = new cbeDropdownMenu(mnuMarker.pageX(), mnuMarker.pageY(),110,20,180,18,2,'#294D73','#FFFFFF','#FFFFFF','#294D73');
        winResizeListener(); //Fix's opera not displaying menu
	window.cbe.addEventListener('resize', winResizeListener, false);
	;
}

function winResizeListener() {
  cbeMenu.paint(mnuMarker.pageX(), mnuMarker.pageY());
}

// begin class cbeDropdownMenu
function cbeDropdownMenu(mnuX, mnuY, lblW, lblH, boxW, itmH, itmPad, bgColor, txtColor, hvrBColor, hvrTColor) {
  // Properties
  this.mnuX = mnuX;
  this.mnuY = mnuY;
  this.lblW = lblW;
  this.lblH = lblH;
  this.boxW = boxW;
  this.itmH = itmH;
  this.itmPad = itmPad;
  this.bgColor = bgColor;  
  this.txtColor = txtColor; 
  this.hvrBColor = hvrBColor;
  this.hvrTColor = hvrTColor;
  this.lblCount = 0;
  this.lblActive = null;
  
  // Methods
  this.paint = function(mnuX, mnuY) { // this is the only public method
    if (arguments.length > 0) this.mnuX = mnuX;
    if (arguments.length > 1) this.mnuY = mnuY;
    var lbl = null; // of type Element
    var box = null; // of type CBE
    var mX = this.mnuX;
    this.lblCount = 0;
    do {
      ++this.lblCount;
      lbl = cbeGetElementById('label' + this.lblCount)
      if (lbl) {
        with (lbl.cbe) {
          color(this.txtColor);    
          background(this.bgColor);
          zIndex(2002);
          resizeTo(this.lblW, this.lblH);
          moveTo(mX, this.mnuY);
          show();
        }
        if (lbl.cbe.nextSibling && lbl.cbe.nextSibling.id.indexOf('label')==-1) box = lbl.cbe.nextSibling;
        else box = null;
        lbl.cbe.childBox = box;
        lbl.cbe.parentLabel = null;
        if (box) this.paintBox(box, lbl.cbe, mX, this.mnuY + lbl.cbe.height());
        mX += lbl.cbe.width();
      }
    } while(lbl);
    --this.lblCount;
  }

  this.paintBox = function(box, parent, x, y) {
    var mx=0, my=4, itmCount=0;
    box.background(this.bgColor);
    box.width(this.boxW);
    box.moveTo(x, y);
    box.zIndex(2002);
    var itm = box.firstChild;
    while (itm) {
      if (itm.id.indexOf('i') != -1) {
        itm.color(this.txtColor);
        itm.background(this.bgColor);
        itm.resizeTo(this.boxW - 6, this.itmH);
        itm.moveTo(mx + this.itmPad, my);
        itm.show();
        my += itm.height();
        ++itmCount;
      }
      else {
        itm.previousSibling.childBox = itm;
        itm.previousSibling.parentLabel = parent;
        this.paintBox(itm, itm.previousSibling, mx + itm.parentNode.width() - 4, my - itm.previousSibling.height());
      }
      itm = itm.nextSibling;
    }
    box.height(itmCount * this.itmH + 8);
  }

  this.mousemoveListener = function(e) {
    if (
      this.lblActive &&
      (e.cbeTarget != this.lblActive.childBox &&
      e.cbeTarget != this.lblActive &&
      e.cbeTarget.parentNode != this.lblActive.childBox)
    ) {
      if (this.lblActive.childBox) this.lblActive.childBox.hide();
      this.lblActive.color(this.txtColor);
      this.lblActive.background(this.bgColor);
      this.lblActive = this.lblActive.parentLabel;
    }
    else if (e.cbeTarget.childBox || e.cbeTarget.id.indexOf('label')!=-1) {
      e.cbeTarget.color(this.hvrTColor);
      e.cbeTarget.background(this.hvrBColor);
      this.lblActive = e.cbeTarget;
      if (this.lblActive.childBox) this.lblActive.childBox.show();
    }
  }
  
  // Constructor Code
  this.paint();
  document.cbe.addEventListener('mousemove', this.mousemoveListener, false, this);

}


// Image fading script of unknow origin (Please contact webmaster at evirtus.net if you know where it originally is from)
imgFadeObjects = new Object();
imgFadeTimers = new Object();

function imgFade(object, destOp, rate, delta){
if (!document.all)
return
    if (object != "[object]"){ 
        setTimeout("imgFade("+object+","+destOp+","+rate+","+delta+")",0);
        return;
    }
    clearTimeout(imgFadeTimers[object.sourceIndex]);
    diff = destOp-object.filters.alpha.opacity;
    direction = 1;
    if (object.filters.alpha.opacity > destOp){ direction = -1;
    }
    delta=Math.min(direction*diff,delta);
    object.filters.alpha.opacity+=direction*delta;
    if (object.filters.alpha.opacity != destOp){ imgFadeObjects[object.sourceIndex]=object; imgFadeTimers[object.sourceIndex]=setTimeout("imgFade(imgFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
    }
}

// Set form focus
function SetLoginFocus(FieldName) {
  var elem = document.forms ? document.forms[0] : false;
  elem = elem && elem.elements ? elem.elements[FieldName] : false;
  if (elem) {
    elem.focus();
    elem.select();
  }
}

