
//====================================
// DDL Menu
// From Dawson's DHTML Library
//
// Version: 3.25
//
// Author:   Dawson Cowals
// Created:  06-07-2002
// Modified: 06-07-2003
//
//====================================

// GLOBALS
mainMenuImagePrefix = "menu";
mainMenuImageExt    = ".gif";
subMenuImagePrefix  = "menu";
subMenuImageExt     = ".gif";
menuImagePath       = menuImagePrefix + "images/";
imageIDPrefix       = "img_";
imageOffSuffix      = "_off";
imageOnSuffix       = "_on";
numberOfMenus       = 8;
subMenuLayerPrefix  = "divMenu";
mainMenuLayer       = "divMainMenu";
nameDelimiter       = "_";

//Initialize our Menu Object
var ddlMenuObj = new DDLMenuObj();

//init main menu with number of items, image name prefix, and image extension
//based on image name "main": main0_off.gif, main0_on.gif
//submenus with name "menu":  menu0_0_off.gif, menu0_0_on.gif
ddlMenuObj.initMenu(numberOfMenus,
					menuImagePath,
					imageIDPrefix,
					imageOffSuffix,
					imageOnSuffix,
					mainMenuLayer,
					mainMenuImagePrefix,
					mainMenuImageExt,
					subMenuLayerPrefix,
					subMenuImagePrefix,
					subMenuImageExt);

//init each sub menu: subMenuIndex, numberOfItems
//for successive levels of menus just keep appending:
//so a submenu under menu 1's 3rd item would be '1_2'
ddlMenuObj.initSubMenu('0', 0);
ddlMenuObj.initSubMenu('1', 0);
ddlMenuObj.initSubMenu('2', 2);
ddlMenuObj.initSubMenu('3', 2);
ddlMenuObj.initSubMenu('4', 6);
ddlMenuObj.initSubMenu('5', 0);
ddlMenuObj.initSubMenu('6', 4);
ddlMenuObj.initSubMenu('7', 4);

//============================================================================
// DO NOT CHANGE ANYTHING BELOW THIS LINE OR THE MENUS WILL BREAK
//============================================================================

//DDLMenuObj type constructor
function DDLMenuObj() {

  //number of main menu entries
  this.numberOfMenus          = 0;
  this.imagePath              = "";
  this.imageIDPrefix          = "img_";
  this.imageOffSuffix         = "_off";
  this.imageOnSuffix          = "_on";

  //main menu properties
  this.mainMenuLayer          = "divMainMenu";
  this.mainImgPrefix          = "main";
  this.mainImgExt             = ".gif";
  this.mainImgOffSrc          = new Array();
  this.mainImgOnSrc           = new Array();

  //sub menu properties
  this.subMenuActive          = new Array();
  this.subMenuLayerPrefix     = "divMenu";
  this.subMenuItems           = new Array();
  this.menuImgPrefix          = "menu";
  this.menuImgExt             = ".gif";
  this.menuImgOffSrc          = new Array();
  this.menuImgOnSrc           = new Array();

  //member functions
  this.initMenu               = initMenu;
  this.initSubMenu            = initSubMenu;
  this.showMenu               = showMenu;
  this.closeMenu              = closeMenu;
  this.hideAllMenusExcept     = hideAllMenusExcept;
  this.positionSubMenu        = positionSubMenu;
  this.getSubMenuLayerName    = getSubMenuLayerName;
  this.mainImageSwap          = mainImageSwap;
  this.menuImageSwap          = menuImageSwap;

}

function initMenu(numberOfMenus, imagePath, imageIDPrefix, imageOffSuffix, imageOnSuffix, mainMenuLayer, mainImgPrefix, mainImgExt, subMenuLayerPrefix, menuImgPrefix, menuImgExt) {
  var i = 0;

  this.numberOfMenus      = numberOfMenus;
  this.imagePath          = imagePath;
  this.mainMenuLayer      = mainMenuLayer;
  this.mainImgPrefix      = mainImgPrefix;
  this.mainImgExt         = mainImgExt;
  this.subMenuLayerPrefix = subMenuLayerPrefix;
  this.menuImgPrefix      = menuImgPrefix;
  this.menuImgExt         = menuImgExt;
  this.imageIDPrefix      = imageIDPrefix;
  this.imageOffSuffix     = imageOffSuffix;
  this.imageOnSuffix      = imageOnSuffix;

  //inner loop through each main menu item
  for (i=0; i < numberOfMenus; i++) {
    this.mainImgOffSrc[i]     = new Image();
    this.mainImgOffSrc[i].src = imagePath + mainImgPrefix + i + imageOffSuffix + mainImgExt;
    this.mainImgOnSrc[i]      = new Image();
    this.mainImgOnSrc[i].src  = imagePath + mainImgPrefix + i + imageOnSuffix  + mainImgExt;
  }
}

function initSubMenu(subMenuIndex, numberOfItems) {
  var i        = 0;
  var tmpIndex = "";

  this.subMenuItems[subMenuIndex]  = numberOfItems;

  //loop through each sub menu item
  for (i=0; i < numberOfItems; i++) {
	tmpIndex = "" + subMenuIndex + nameDelimiter + i + "";
    this.menuImgOffSrc[tmpIndex]     = new Image();
    this.menuImgOffSrc[tmpIndex].src = this.imagePath + this.menuImgPrefix + tmpIndex + this.imageOffSuffix + this.menuImgExt;
    this.menuImgOnSrc[tmpIndex]      = new Image();
    this.menuImgOnSrc[tmpIndex].src  = this.imagePath + this.menuImgPrefix + tmpIndex + this.imageOnSuffix  + this.menuImgExt;
  }
}

function mainImageSwap(imgIndex,imgState) {
  if (document.images) {
	var imgName  = this.imageIDPrefix + imgIndex + "";
	var imgLayer = this.mainMenuLayer;

	switch (imgState) {
		case 'off':
			//if we are using a newer browser
			if (is_nav6up || is_ie6up || is_gecko || is_opera || is_konqueror) {
			   changeSrc = eval('document.getElementById("'+imgName+'").setAttribute("src","'+this.imagePath + this.mainImgPrefix + imgIndex + this.imageOffSuffix + this.mainImgExt + '")');
			//if we are dealing with NS4 and we are inside a layer
			//we have to call the div name first
			} else if (is_nav4up && imgLayer!=null) {
			   changeSrc = eval('document.layers["'+imgLayer+'"].document.images["'+imgName+'"].src=this.mainImgOffSrc['+imgIndex+'].src');
			//otherwise if we are using IE5 or not accessing an image inside a layer
			} else {
			   document.images[imgName].src = this.mainImgOffSrc[imgIndex].src;
			}
			break;
		case 'on':
			//if we are using a newer browser
			if (is_nav6up || is_ie6up || is_gecko || is_opera || is_konqueror) {
			   changeSrc = eval('document.getElementById("'+imgName+'").setAttribute("src","'+this.imagePath + this.mainImgPrefix + imgIndex + this.imageOnSuffix + this.mainImgExt+'")');
			//if we are dealing with NS4 and we are inside a layer
			//we have to call the div name first
			} else if (is_nav4up && imgLayer!=null) {
			   changeSrc = eval('document.layers["'+imgLayer+'"].document.images["'+imgName+'"].src=this.mainImgOnSrc['+imgIndex+'].src');
			//otherwise if we are using IE5 or not accessing an image inside a layer
			} else {
			   document.images[imgName].src = this.mainImgOnSrc[imgIndex].src;
			}
			break;
	}
  }
}

function menuImageSwap(menuIndex, imgIndex, imgState) {
  if (document.images) {

	//create string like "0_0", "0_1", etc
	var tmpIndex = "" + menuIndex + nameDelimiter + imgIndex + "";
	//piece together image name / ID: "img_0_0"
	var imgName  = "" + this.imageIDPrefix + tmpIndex;
	//grab menu layer name
	var imgLayer = this.getSubMenuLayerName(menuIndex);

	switch (imgState) {
		case 'off':
			//if we are using a newer browser
			if (is_nav6up || is_ie6up || is_gecko || is_opera || is_konqueror) {
			   changeSrc = eval('document.getElementById(imgName).setAttribute("src",this.imagePath + this.menuImgPrefix + tmpIndex + this.imageOffSuffix + this.menuImgExt)');
			//if we are dealing with NS4 and we are inside a layer
			//we have to call the div name first
			} else if (is_nav4up && imgLayer!=null) {
			   changeSrc = eval('document.layers["'+imgLayer+'"].document.images["'+imgName+'"].src=this.menuImgOffSrc["'+tmpIndex+'"].src');
			//otherwise if we are using IE5 or not accessing an image inside a layer
			} else {
			   document.images[imgName].src = this.menuImgOffSrc[tmpIndex].src;
			}
			break;
		case 'on':
			//if we are using a newer browser
			if (is_nav6up || is_ie6up || is_gecko || is_opera || is_konqueror) {
			   changeSrc = eval('document.getElementById(imgName).setAttribute("src",this.imagePath + this.menuImgPrefix + tmpIndex + this.imageOnSuffix + this.menuImgExt)');
			//if we are dealing with NS4 and we are inside a layer
			//we have to call the div name first
			} else if (is_nav4up && imgLayer!=null) {
			   changeSrc = eval('document.layers["'+imgLayer+'"].document.images["'+imgName+'"].src=this.menuImgOnSrc["'+tmpIndex+'"].src');
			//otherwise if we are using IE5 or not accessing an image inside a layer
			} else {
			   document.images[imgName].src = this.menuImgOnSrc[tmpIndex].src;
			}
			break;
	}
  }
}

//given menu index returns layer name
function getSubMenuLayerName(menuIndex) {
	return ("" + this.subMenuLayerPrefix + menuIndex + "");
}

//returns count of number of delimiters in menu index string
//which correlates to the submenu level
function getSubMenuLevel(menuIndex) {
	var i = 0;
	var subMenuLevel = 0;

	for (i=0; i < menuIndex.length; i++) {
		if (menuIndex.substr(i,1) == nameDelimiter) {
			subMenuLevel++;
		}
	}
	return subMenuLevel;
}

//pass 'none' to turn off all menus, pass a menu index to turn on that menu
function showMenu(menuIndex) {
	if (menuIndex == 'none') {
		var i = 0;
		for (i=0; i < numberOfMenus; i++) {
			toggleLayer(this.getSubMenuLayerName(i), 'hide');
			eval('this.mainImageSwap('+i+',"off")');
		}
	} else {
		//show layer
		toggleLayer(getSubMenuLayerName(menuIndex),'show');
		//hide other layers
		this.hideAllMenusExcept(menuIndex);
	}
}

//pass the subMenu index to close
function closeMenu(menuIndex) {
	toggleLayer(this.getSubMenuLayerName(menuIndex),'hide');
	eval('this.mainImageSwap('+menuIndex+',"off")');
}

//hides all menus except the one represented by the index passed
function hideAllMenusExcept(menuIndex) {
	var i = 0;
	for (i=0; i < numberOfMenus; i++) {
		if (this.getSubMenuLayerName(i) != this.getSubMenuLayerName(menuIndex)) {
			toggleLayer(this.getSubMenuLayerName(i), 'hide');
			eval('this.mainImageSwap('+i+',"off")');
		}
	}
}

//send xOffset and yOffset for submenu to be positioned relative to
//main menu item with same number, for pages where menu position can shift on resize
//call this function prior to using "showMenu(##)"
//NOTE: this currently only works for menus with no further submenu levels
function positionSubMenu(menuIndex,xOffset,yOffset){
	var item;
	var imgName    = this.imageIDPrefix + menuIndex + "";
	var imgLayer   = this.mainMenuLayer;
	var menuImageX = 0;
	var menuImageY = 0;
	var menuLayer  = "";
	var newX       = 0;
	var newY       = 0;

	//create string like "0_0", "0_1", etc
	//var tmpIndex = "" + menuIndex + nameDelimiter + imgIndex + "";
	//piece together image name / ID: "img_0_0"
	//var imgName  = "" + this.imageIDPrefix + tmpIndex;

	if (is_nav6up || is_ie6up || is_gecko || is_opera || is_konqueror) {
	   item = eval('document.getElementById(imgName)');
        }

	//determine location of main menu item
	menuImageX = getPageOffsetLeft(item);
	menuImageY = getPageOffsetTop(item);

	//set new positions
	newX = menuImageX + xOffset;
	newY = menuImageY + yOffset;

	if (is_nav6up || is_ie6up || is_gecko || is_opera || is_konqueror) {
		//position submenu to appear correctly related to main menu item
		menuLayer = this.getSubMenuLayerName(menuIndex)
		document.getElementById(menuLayer).style.left = newX  + "px";
		document.getElementById(menuLayer).style.top  = newY + "px";
	}
}

//function takes a layer name and a toggle value
//works in both NS and IE to hide layer or make it visible
function toggleLayer(layerID,tog) {
   //if we want to hide the layer
   if (tog == 'hide') {
        //if this is new 6.0 Browser
        if (is_nav6up || is_ie6up || is_gecko || is_opera || is_konqueror) {
           document.getElementById(layerID).style.visibility = "hidden";
        //if this is an old Netscape 4.x browser
        }  else if (is_nav4up) {
           document.layers[layerID].visibility='hide';
	    //if this is an old IE 5.x browser
        } else if (is_ie5up) {
           document.all[layerID].style.visibility='hidden';
        }
   //otherwise we want to show it
   } else {
        //if this is new 6.0 Browser
        if (is_nav6up || is_ie6up || is_gecko || is_opera || is_konqueror) {
           document.getElementById(layerID).style.visibility = "visible";
        //if this is an old Netscape 4.x browser
        }  else if (is_nav4up) {
           document.layers[layerID].visibility='show';
	    //if this is an old IE 5.x browser
        } else if (is_ie5up) {
           document.all[layerID].style.visibility='visible';
        }
   }
}

function getPageOffsetLeft(el) {
  var x;

  // Return the x coordinate of an element relative to the page.
  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {
  var y;

  // Return the y coordinate of an element relative to the page.
  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}