function pd_menu() {
  this.prefix_ul = 'sub';
	this.prefix_li = 'item';
	this.prefix_a = 'itemLink';
	this.prefix_img = 'linkImg';
	this.menuTimeOut = 600;
	this.lvl0style = 'img';
	this.lvl1style = 'css';
	this.lvl2style = 'css';
	this.select0 = -1;
	this.select1 = -1;
	this.select2 = -1;
	this.menuRootId = '';
	this.menuRootNode = '';
	this.myInstanceName = '';
	this.mouseOverActive = false;
	this.showSelectedSubs = true; // if true then submenu's reappear after mouseout
	this.aRolloverGroups = new Array(); //groups of id's, a-tags -> css classname switching
	this.aRolloverImages = new Array(); // groups of images -> rollovers
	this.aRolloverObjects = new Array(); // instances of rollOver objects
	
	
	pd_menu.prototype.init = function(menuRootId,instanceName) {
	  this.menuRootId = menuRootId;
		this.myInstanceName = instanceName;
		this.menuRootNode = document.getElementById(menuRootId);
		this.setIds_ul(this.menuRootNode);
    myObj = document.getElementById(this.aRolloverGroups['root'][0]);
		this.setRollovers();
	}
  // *****
	pd_menu.prototype.setSelected = function(lvl0,lvl1,lvl2) {
		if (lvl0 || lvl0=='0') {
			if (this.select0) this.select0=lvl0;
			if (this.aRolloverObjects) this.aRolloverObjects['root'].setIndex(lvl0);
		}
		if (lvl1 || lvl1=='0') {
			if (this.select1) this.select1=lvl1;
			if (this.aRolloverObjects) this.aRolloverObjects['sub_'+lvl0].setIndex(lvl1);
		}
 		if (lvl2 || lvl2=='0') {
 			if (this.select2) this.select2=lvl2;
 			if (this.aRolloverObjects) this.aRolloverObjects['sub_'+lvl0+'_'+lvl1].setIndex(lvl2);
 		}
		this.showSelected();
	}
  // *****
	pd_menu.prototype.showSelected = function() {
	  if (this.showSelectedSubs==false) return;
		var mySub;
		if (this.select1>=0) {
		  this.hideAll('root',-1,-1,-1);
		  mySub = document.getElementById('sub_'+this.select0);
		  if (mySub){
			mySub.style.display = 'block';
		  }
		}
	}
  // *****
	pd_menu.prototype.setRollovers = function() {
    var indexName, currentStyle;
		for (indexName in this.aRolloverGroups) {		
			// determine the level
			var menuLevel;
			if (indexName=='root') {
			  menuLevel=0;
			} else if (indexName.length>=5) {
			  menuLevel=1;
			} else if (indexName.length>=7) {
			  menuLevel=2;
			}
			//determine the menu type
			if (menuLevel==0) {
			  // level 0 type menu
			  if (this.lvl0style=='img') currentStyle = 'img';
			  if (this.lvl0style=='css') currentStyle = 'css';
			}
			if (menuLevel==1) {
			  // level 1 type menu
			  if (this.lvl1style=='img') currentStyle = 'img';
			  if (this.lvl1style=='css') currentStyle = 'css';
			}
			if (menuLevel==2) {
			  // level 2 type menu
			  if (this.lvl2style=='img') currentStyle = 'img';
			  if (this.lvl2style=='css') currentStyle = 'css';
			}
			// build stuff
			if (currentStyle=='img') {
			  // build image rollover object
  			this.aRolloverImages[indexName] = new Array();
    		var i=0;
    		var myImg, imgName, dotIndex, imgBaseName, imgExt;
        var imgN_n, imgN_r, imgN_s;
    		var dotIndex = 0;
    		var zutt='';
    		for (i=0;i<this.aRolloverGroups[indexName].length;i++) {
    		  myImg = document.getElementById(this.aRolloverGroups[indexName][i]);
    			imgName = myImg.src;
    			dotIndex = imgName.lastIndexOf('.');
    			imgBaseName = imgName.substring(0,dotIndex);
    			imgExt = imgName.substr(dotIndex,imgName.length);
          imgN_n = imgBaseName+imgExt;
          imgN_r = imgBaseName+'_r'+imgExt;
          imgN_s = imgBaseName+'_s'+imgExt;
    			this.aRolloverImages[indexName][i] = new Array();
          this.aRolloverImages[indexName][i][0] = imgN_n;
          this.aRolloverImages[indexName][i][1] = imgN_r;
          this.aRolloverImages[indexName][i][2] = imgN_s;
          this.aRolloverImages[indexName][i][3] = this.aRolloverGroups[indexName][i];
    		}
        this.aRolloverObjects[indexName] = new rollOvers_img();
    		this.aRolloverObjects[indexName].init(this.aRolloverImages[indexName]);
			}
			if (currentStyle=='css') {
			  // build css rollover object
        this.aRolloverObjects[indexName] = new rollOvers_css();
    		this.aRolloverObjects[indexName].init(this.aRolloverGroups[indexName]);
			}
		}
	}
  // *****
  pd_menu.prototype.setIds_a = function(rootNode,lvl0,lvl1,lvl2) {
		var hasImg = false;
    var idEndPart = "";
 		var i=0;
		if (lvl0 || lvl0=='0') idEndPart+="_"+lvl0;
    if (lvl1 || lvl1=='0') idEndPart+="_"+lvl1;
    if (lvl2 || lvl2=='0') idEndPart+="_"+lvl2;
		for (i=0;i<rootNode.childNodes.length;i++) {
 		  myNode = rootNode.childNodes[i];
			if (myNode.nodeName=="IMG") {
        var idPrefix = this.prefix_img;
        var myId = idPrefix+idEndPart;
			  myNode.id=myId;
				hasImg = true;
      }
    }	
		// building img-rollover arrays
		if (!(lvl1 || lvl1=='0')) {
      // level 0, menu-root
      if (!this.aRolloverGroups['root']) this.aRolloverGroups['root'] = new Array(); 
      var myIndex = this.aRolloverGroups['root'].length;
			if (hasImg==true) {
   		  this.aRolloverGroups['root'][myIndex] = myId;
			} else {
			  // no image, put the id of the a tag in array
				myId = this.prefix_a+idEndPart;
   		  this.aRolloverGroups['root'][myIndex] = myId;
			}
    } else if (!(lvl2 || lvl2=='0')) {
      // level1 sub_x
			var indexName = 'sub_'+lvl0;
			if (!this.aRolloverGroups[indexName]) this.aRolloverGroups[indexName] = new Array(); 
      var myIndex = this.aRolloverGroups[indexName].length;
      if (hasImg==true) {
   		  this.aRolloverGroups[indexName][myIndex] = myId;
			} else {
			  // no image, put the id of the a tag in array
				myId = this.prefix_a+idEndPart;
   		  this.aRolloverGroups[indexName][myIndex] = myId;
			}
		}
  }
  // *****
  pd_menu.prototype.setIds_li = function(rootNode,lvl0,lvl1,lvl2) {
    var idEndPart = "";
 		var i=0;
		if (lvl0 || lvl0=='0') idEndPart+="_"+lvl0;
    if (lvl1 || lvl1=='0') idEndPart+="_"+lvl1;
    if (lvl2 || lvl2=='0') idEndPart+="_"+lvl2;
		for (i=0;i<rootNode.childNodes.length;i++) {
		  myNode = rootNode.childNodes[i];
			if (myNode.nodeName=="A") {
		    var idPrefix = this.prefix_a;
        var myId = idPrefix+idEndPart;
			  myNode.id=myId;
    	  this.setIds_a(myNode,lvl0,lvl1,lvl2);
      } else if (myNode.nodeName=="UL") {
				var idPrefix = this.prefix_ul;
        var myId = idPrefix+idEndPart;
			  myNode.id=myId;
    	  this.setIds_ul(myNode,lvl0,lvl1,lvl2);
      }			
		}
	}
  // *****
  pd_menu.prototype.setIds_ul = function(rootNode,lvl0,lvl1,lvl2) {
    var idPrefix = this.prefix_li;
		if (lvl0 || lvl0=='0') idPrefix+="_"+lvl0;
    if (lvl1 || lvl1=='0') idPrefix+="_"+lvl1;
    if (lvl2 || lvl2=='0') idPrefix+="_"+lvl2;
		var index_li = 0;
		var i=0;
		for (i=0;i<rootNode.childNodes.length;i++) {
		  myNode = rootNode.childNodes[i];
			myId = idPrefix + "_" + index_li;
			if (myNode.nodeName=="LI") {
			  myNode.id=myId;
				// building passed lvl variables
				if (!(lvl0 || lvl0=='0')) {
				  lvl0p = index_li;
					lvl1p = lvl1;
					lvl2p = lvl2;
          // alert('lvl0: '+lvl0p+','+lvl1+','+lvl2);
				} else if (!lvl1 && lvl1!='0') {
          lvl0p = lvl0;
				  lvl1p = index_li;
					lvl2p = lvl2;
          // alert('lvl1: '+lvl0+','+lvl1p+','+lvl2);
				} else if (!lvl2 && lvl2!='0') {
          lvl0p = lvl0;
					lvl1p = lvl1;
				  lvl2p = index_li;
          // alert('lvl2: '+lvl0+','+lvl1+','+lvl2p);
				}
				myNode.lvl0 = lvl0p;
				myNode.lvl1 = lvl1p;
				myNode.lvl2 = lvl2p;
				myNode.menuPointer = this;
//				myNode.onmouseover = function() { this.menuPointer.mouseOver(this.id,this.lvl0,this.lvl1,this.lvl2);top.status='over '+this.id; }
				myNode.onmouseover = function() { this.menuPointer.mouseOver(this.id,this.lvl0,this.lvl1,this.lvl2)}
//				myNode.onmouseout = function() { this.menuPointer.mouseOut(this.id,this.lvl0,this.lvl1,this.lvl2);top.status='out '+this.id }
				myNode.onmouseout = function() { this.menuPointer.mouseOut(this.id,this.lvl0,this.lvl1,this.lvl2)}

        this.setIds_li(myNode,lvl0p,lvl1p,lvl2p);
				index_li++;
			}
		}
	}
  // *****
	pd_menu.prototype.mouseOver = function(myId,lvl0,lvl1,lvl2) {
    if (window.pd_menu_timer) window.clearTimeout(window.pd_menu_timer);
    this.hideAll('root',lvl0,lvl1,lvl2);
	}
  // *****
	pd_menu.prototype.mouseOut = function(myId,lvl0,lvl1,lvl2) {
		if (window.pd_menu_timer) window.clearTimeout(window.pd_menu_timer);
		window.pd_menu_timer = window.setTimeout(this.myInstanceName+'.hideTimed()',this.menuTimeOut);
	}
  // *****
	pd_menu.prototype.hideTimed = function() {
	  this.hideAll('root',-1,-1,-1);
    this.showSelected();
	}
  // *****
	pd_menu.prototype.hideAll = function(rootNode,lvl0,lvl1,lvl2) {
      // hides all menu's. except the one given by lvl0,lvl1,lvl2 (if any)
		var i=0;
		var j=0;
    if (rootNode=='root') rootNode = this.menuRootNode;
		  // set the id's that shouldn't be hidden
		var matchIds = new Array();
		if (lvl0 || lvl0=='0') matchIds[i++] = this.prefix_ul+'_'+lvl0;
		if (lvl1 || lvl1=='0') matchIds[i++] = this.prefix_ul+'_'+lvl0+'_'+lvl1;
 		if (lvl2 || lvl2=='0') matchIds[i++] = this.prefix_ul+'_'+lvl0+'_'+lvl1+'_'+lvl2;
    // set the display mode
		var displayStyle = 'none';
		for (i=0;i<matchIds.length;i++) {
		  if ( (rootNode.id == matchIds[i]) || (rootNode == this.menuRootNode) ) displayStyle = 'block';
		}
		rootNode.style.display = displayStyle;
	    // scan for submenu's and execute hideAll on those
		for (i=0;i<rootNode.childNodes.length;i++) {
		  if (rootNode.childNodes[i].nodeName=="LI") {
			    // check if submenu's in the LI-item...
			  var myNode = rootNode.childNodes[i];
				for (j=0;j<myNode.childNodes.length;j++) {
			    if (myNode.childNodes[j].nodeName=="UL") {
					  newRootNode = myNode.childNodes[j];
				    this.hideAll(newRootNode,lvl0,lvl1,lvl2);
				  }
				}
			}
		}
	}
}

//=======================================================================



function rollOvers_img() {
  this.selectedIndex = -1;
	this.rollOverSelectedItems = false;
	this.ldImg = new Array();

  rollOvers_img.prototype.init = function(passedArray) {
	  // ** user called ***
	  // passedArray =  array(btnNorm, btnRollOver, btnSelected, btnId)
	  this.btnArray = passedArray;
		this.preload();
		this.setHovers();
	}
  rollOvers_img.prototype.setIndex = function(myIndex) {
	  // ** user called ***
    this.selectedIndex = myIndex;
		this.setHovers();
	}
	rollOvers_img.prototype.preload = function() {
    var i=0,j=0;
  	if (document.images) {
   	  for(i=0;i<this.btnArray.length;i++) {
        this.ldImg[i] = new Array();
  	    for (j=0;j<3;j++) {
      		this.ldImg[i][j] = new Image;
      		this.ldImg[i][j].src = this.btnArray[i][j]; //ldImg[index][state]
	    	}
  	  }
    }
  }
  rollOvers_img.prototype.setHovers = function() {
	  var i=0,j=0;
		for (i=0;i<this.btnArray.length;i++) {
		  myImg = document.images[this.btnArray[i][3]];
      myImg.img_n = this.btnArray[i][0];
      myImg.img_r = this.btnArray[i][1];
      myImg.img_s = this.btnArray[i][2];
		  
			if (this.selectedIndex!=i) {
  			myImg.onmouseover = function() { this.src = this.img_r;	}
  			myImg.onmouseout = function() { this.src = this.img_n; }
				myImg.src = myImg.img_n // set to normal image
  	  } else {
  			if (this.rollOverSelectedItems==true) {
    			myImg.onmouseover = function() { this.src = this.img_r;	}
    			myImg.onmouseout = function() { this.src = this.img_s; }
				} else {
    			myImg.onmouseover = function() { 	}
    			myImg.onmouseout = function() {  }
				}
				myImg.src = myImg.img_s // set to selected image
			}
		}
	}
}

//=======================================================================

function rollOvers_css() {
  this.selectedIndex = -1;
	this.rollOverSelectedItems = false;

  rollOvers_css.prototype.init = function(passedArray) {
	  // ** user called ***
	  // passedArray =  array(btnId)
	  this.btnArray = passedArray;
		this.setHovers();
	}
  rollOvers_css.prototype.setIndex = function(myIndex) {
	  // ** user called ***
    this.selectedIndex = myIndex;
		this.setHovers();
	}
  rollOvers_css.prototype.setHovers = function() {
	  var i=0
		for (i=0;i<this.btnArray.length;i++) {
  		myBtn = document.getElementById(this.btnArray[i]);
			if (this.selectedIndex!=i && this.btnArray[i]!=undefined) {
  			myBtn.onmouseover = function() { this.className = 'r';}
  			myBtn.onmouseout = function() { this.className = 'n';}
				myBtn.className = 'n' // set to normal button
  	  } else if (this.btnArray[i]!=undefined) {
  			if (this.rollOverSelectedItems==true) {
  			  myBtn.onmouseover = function() { this.className = 'r'; }
  		  	myBtn.onmouseout = function() { this.className = 's'; }
				} else {
    			myBtn.onmouseover = function() { 	}
    			myBtn.onmouseout = function() {  }
				}
				myBtn.className = 's' // set to selected btn
			}
		}
	}

}

//
