<!-- 
/*
------------------------------------------------------------------------------
File Name: pH2.menu.js
Company: ph2enterprises
Author: Phil Henslee <ph2@ph2.us> ©2003
Purpose: Creates simple drop down menu object
Functions: 6
Date Created: April 26, 2003
Last Modified: April 26, 2003
Required Files: pH2.config.js, pH2.detection.js, ph2.utility.js
------------------------------------------------------------------------
*/

/*----------------------------------------------------------------------
  ** Create pH2 SimpleMenu Class
  ----------------------------------------------------------------------
*/

	pH2.SimpleMenu = function(name,trigger,posLeft,posTop,width,color,activeColor,fontColor,fontColorActive,borderColor,lineColor,style,useDivisions,useCaps,capHeight,capColor,isPreview){
	
		this.name = name;
		this.trigger = trigger;
		this.posLeft = posLeft;
		this.posTop = posTop;
		this.width = width;
		this.color = color;
		this.activeColor = activeColor;
		this.fontColor = fontColor;
		this.fontColorActive = fontColorActive;
		this.borderColor = borderColor;
		this.lineColor = lineColor;
		this.style = style;
		this.useDivisions = useDivisions;
		this.useCaps = useCaps;
		this.capHeight = capHeight;
		this.capColor = capColor;
		this.isPreview = isPreview;

		// Create an Array to store menu items
		
		this.items = new Array();

	}

/*----------------------------------------------------------------------
  Method addItem
  Add a menu item to the menu's items array
  ----------------------------------------------------------------------
*/

pH2.SimpleMenu.prototype.addItem = function(item,url){
	
	this.items[this.items.length] = new Array(2);
	this.items[this.items.length - 1][0] = item;
	this.items[this.items.length - 1][1] = url;
	//alert(this.items.length);

}



/*----------------------------------------------------------------------
  Method render
  Render div or layer of menu
  ----------------------------------------------------------------------
*/

pH2.SimpleMenu.prototype.render = function(){

	
	if(document.getElementById)
	{
		this.createDiv();
	}
	else if(document.all)
	{ 
		this.createDiv();
	}
	else if(document.layers)
	{
		this.createLayer();
	}
	
}


/* 
------------------------------------------------------------------------
Method getPosition()
Purpose: return the real position of the menu
Arguments: 1
Arg 0: i
Arg 1: which
------------------------------------------------------------------------
*/ 
pH2.SimpleMenu.prototype.getPosition = function(i,which) {
  iPos = 0
  while (i!=null) {
    iPos += i["offset" + which]
    i = i.offsetParent
  }
  return iPos
}

/* 
------------------------------------------------------------------------
Method show()
Purpose: makes the current menu visiable.
------------------------------------------------------------------------
*/ 
pH2.SimpleMenu.prototype.show = function(){
var theMenuObj;
	
	if(document.getElementById){ 
		if (this.trigger != null){
			theMenuObj = document.getElementById(this.name);
			theRegObj = document.getElementById(this.trigger);
			var leftPos = this.getPosition(theRegObj,"Left");
			var topPos =  this.getPosition(theRegObj,"Top");
			theMenuObj.style.left = (  leftPos - this.posLeft );
			theMenuObj.style.top  = (  topPos + theRegObj.height + this.posTop);	
			theMenuObj.style.visibility = 'visible';	
		}else{
			theMenuObj = document.getElementById(this.name);
			theMenuObj.style.visibility = 'visible';
		}
	}else if(document.all){ 
		if (this.trigger != null){
			theMenuObj = document.all[this.name];
			theRegObj = document.all[this.trigger];
			var leftPos = this.getPosition(theRegObj,"Left");
			var topPos =  this.getPosition(theRegObj,"Top");
			theMenuObj.style.left = (  leftPos - this.posLeft );
			theMenuObj.style.top  = (  topPos + theRegObj.height + this.posTop);
			theMenuObj.style.visibility = 'visible';	
		}else{
			theMenuObj = document.all[this.name];
			theMenuObj.style.visibility = 'visible';
		}
	}else if(document.layers){ 
		if (this.trigger != null){
			theMenuObj = document.layers[this.name + "Lyr" ];
			theRegObj = document[this.trigger];
			var leftPos = theRegObj.x;
			var topPos =  theRegObj.y;
			theMenuObj.left = (  leftPos - this.posLeft );
			theMenuObj.top  = (  topPos + theRegObj.height + this.posTop);
			theMenuObj.visibility = 'show';
		}else{
			theMenuObj = document.layers[this.name + "Lyr" ];
			theMenuObj.visibility = 'show';
		}
	}
}
/* 
------------------------------------------------------------------------
Method hideMenu()
Purpose: makes the current menu hidden.
------------------------------------------------------------------------
*/ 

pH2.SimpleMenu.prototype.hide = function(){
var theMenuObj;
	
if(document.getElementById)
	{
	theMenuObj = document.getElementById(this.name);
	theMenuObj.style.visibility = 'hidden';
	}
else if(document.all)
	{ 
	theMenuObj = document.all[this.name];
	theMenuObj.style.visibility = 'hidden';
	}
else if(document.layers)
	{
	theMenuObj = document.layers[this.name + "Lyr" ];
	theMenuObj.visibility = 'hide';
	}
}

/* 
------------------------------------------------------------------------
Function menuOver()
Purpose: menu rollover event
------------------------------------------------------------------------
*/ 
pH2.SimpleMenu.prototype.menuOver = function(sMenu){

	var theMenuObj;

	if(document.getElementById)
		{
		theMenuObj = document.getElementById(sMenu);
		theMenuObj.style.backgroundColor= this.activeColor;
		theMenuObj.style.color= this.fontColorActive;
		}
		
	else if(document.all)
		{ 
		theMenuObj = document.all[sMenu];
		theMenuObj.style.backgroundColor= this.activeColor;
		theMenuObj.style.color= this.fontColorActive;
		}
	else if(document.layers)
		{
		theMenuObj = document.layers[this.name + "Lyr"].document.layers[sMenu];
		theMenuObj.bgColor= this.activeColor; 
		theMenuObj.color = this.fontColorActive;
		}	
}

/* 
------------------------------------------------------------------------
Method menuOut()
Purpose: menu rollout event
------------------------------------------------------------------------
*/

pH2.SimpleMenu.prototype.menuOut = function menuOut(sMenu){

	var theMenuObj;

	if(document.getElementById)
		{
		theMenuObj = document.getElementById(sMenu);
		theMenuObj.style.backgroundColor= this.color;
		theMenuObj.style.color= this.fontColor;
		}
	else if(document.all)
		{	
		theMenuObj = document.all[sMenu];
		theMenuObj.style.backgroundColor= this.color;
		theMenuObj.style.color= this.fontColor;
		}
	else if(document.layers)
		{
		theMenuObj = document.layers[this.name + "Lyr"].document.layers[sMenu];
		theMenuObj.bgColor= this.color; 
		}
}
/* 
------------------------------------------------------------------------
Method createDiv()
Purpose: creates a div for each menu
Arguments: 4
Arg 0: sMenu - name of the menu to show
------------------------------------------------------------------------
*/ 

pH2.SimpleMenu.prototype.createDiv = function(){

	var tdID = 0;
	var separator="<img src=images/spacer.gif height=1 width=1>";
	var alreadyRendered = false;
	var iTweakAmount = 2;
	
	if ( pH2.Browser.isNavigator && pH2.Browser.version == 1.5 ){
	   iTweakAmount = -3;
	}
	//alert(iTweakAmount);
	
	var isFirstItem = true;
	
	if (pH2.Browser.isNavigator  && pH2.Browser.majorVersion >=6) {
	
		strMenuDiv = "<div id=\"" + this.name + "\" style=\"position:absolute; width:" + ((this.width - iTweakAmount))  + "; z-index:100; top:"+ this.posTop +"px; left: " + this.posLeft + "px; background-color:" + this.color +"; border:1px  solid " + this.borderColor +"; visibility: hidden;\" onMouseover=\"" + this.name + ".show();\"  onMouseout=\"" + this.name + ".hide();\">";     
	    
	    if(this.useCaps){
		  	strMenuDiv += "<div id=\"topcap\" style=\"position:relative; height:" + this.capHeight +"px; width:" + (this.Width)  + "; z-index:101; left: 0; background-color:" + this.capColor + ";\">" + separator + "</div>";
	    }
	    
	    for (x = 0; x < this.items.length ; x++){
	    
          if(this.items[x][0]!=null){
	        if (!isFirstItem & this.useDivisions == true){
	      		strMenuDiv += "<div id=\"division\" style=\"position:relative; height:1; width:" + (this.width - iTweakAmount)  + "; z-index:102; left: 0; background-color:" + this.lineColor + ";\">" + separator + "</div>";
	        }
	      	strMenuDiv += "<div id=\"" + this.name + "Item" + tdID + "\" style=\"position:relative; background-color:"+ this.color +"; padding:1px; padding-left:3px; z-index:103; \" onMouseover=\"" + this.name +".menuOver(\'" + this.name + "Item" + tdID + "\');\" onMouseout=\"" + this.name + ".menuOut(\'" + this.name + "Item" + tdID + "\',\'" + this.color + "\',\'" + this.fontColor +"\' );\" class=\" " + this.style + "\" onClick=\"pH2.Utility.loadURL('"+ this.items[x][1] + "')\">" + this.items[x][0] + "</div>";
	    	tdID++;
	    	isFirstItem = false;
	    	}
	     }
		
		if(this.useCaps){
			  	strMenuDiv += "<div id=\"topcap\" style=\"position:relative; height:" + this.capHeight +"px; width:" + (this.width - iTweakAmount)  + "; z-index:104; left: 0; background-color:" + this.capColor + ";\">" + separator + "</div>";
	   	 }
		
		strMenuDiv += "</div>";
		document.write(strMenuDiv);
		

		if(pH2.debugState){  
			//alert(strMenuDiv);
		}

    }else{
        
		strMenuDiv = "<div id=\"" + this.name + "\" style=\"position:absolute; width:" + ((this.width - iTweakAmount))  + "; z-index:100; top:"+ this.posTop +"px; left: " + this.posLeft + "px; background-color:" + this.color +"; border:1px  solid " + this.borderColor +"; visibility: hidden;\" onMouseover=\"" + this.name +".show();\""
		
		if (! this.isPreview){
		strMenuDiv += " onMouseout=\"" + this.name +".hide();\">" 
		}else{
		strMenuDiv += ">"
		}      
	    
	      if(this.useCaps){
			  	strMenuDiv += "<div id=\"topcap\" style=\";position:relative; height:" + this.capHeight +"px; width:" + (this.width - iTweakAmount)  + "; z-index:101; left: 0; background-color:" + this.capColor + ";\">" + separator + "</div>"
	    	}
	    
	    for (x = 0; x < this.items.length; x++){
	    
          if(this.items[x][0]!=null){
	        if (!isFirstItem & this.useDivisions == true){
	      		strMenuDiv += "<div id=\"division\" style=\"position:relative; height:1; width:" + (this.width - iTweakAmount)  + "; z-index:103; left: 0; background-color:" + this.lineColor + ";\">" + separator + "</div>"
	        }
	      	strMenuDiv += "<div id=\"" + this.name + "Item" + tdID + "\" style=\"position:relative; background-color:"+ this.color +"; padding:2px; padding-left:3px; width:" + (this.width - iTweakAmount)  + "; z-index:104; left:0px;\" onMouseover=\"" + this.name + ".menuOver(\'" + this.name + "Item" + tdID + "\');\" onMouseout=\"" + this.name +".menuOut(\'" + this.name + "Item" + tdID + "\');\" class=\"" + this.style + "\" onClick=\"pH2.Utility.loadURL('"+ this.items[x][1] + "')\">" + this.items[x][0] + "</div>";
	    	tdID = tdID +1
	    	isFirstItem = false;
	    	}
	      	}
		
		 if(this.useCaps){
			  	strMenuDiv += "<div id=\"bottomcap\" style=\"position:relative; height:" + this.capHeight +"px; width:" + (this.width -2)  + "; z-index:104; left: 0; background-color:" + this.capColor + ";\">" + separator + "</div>";
	     }
		
		strMenuDiv += "</div>";
		
		if (this.isPreview){
						
			if(document.getElementById('preview')){
				lastMenu = document.getElementById('preview')
				document.body.removeChild(lastMenu);
			}
			
			var preview = document.createElement("DIV");
			preview.id = 'preview';
			preview.innerHTML = strMenuDiv
			document.body.appendChild(preview);
			
			if(pH2.Browser.isExplorer && pH2.Browser.majorVersion >=5){
			//this.renderDropShadow('silver',2);
			}
			preview.style.visibility = 'visible'; 
			this.show();
			
		}else{
			document.write(strMenuDiv);
			if(pH2.Browser.isExplorer && pH2.Browser.majorVersion >=5){
			//this.renderDropShadow('silver',2);
			}

		}
		
		
		if(pH2.debugState){  
			//alert(strMenuDiv);
        	}
        
    }
	
}

/* 
------------------------------------------------------------------------
Function buildMenuLayer()
Purpose: creates a layer for the menu 
------------------------------------------------------------------------
*/ 

pH2.SimpleMenu.prototype.createLayer = function(){
	
	var nestLayerID = 0;
	var isFirstItem = true;
	var separator="<img src=images/spacer.gif height=1 width=1>";
			
	strMenuLayer = "<layer id=\""+ this.name +"Lyr\" Z-INDEX=1 bgColor=\""+ this.borderColor + "\" width=" + this.width +" left="+ this.posLeft +" top="+ this.posTop +" VISIBILITY=HIDE onMouseOver=\"" + this.name + ".show();\" onMouseOut=\"" + this.name + ".hide();\">";
	var nestTop=1;
	if(this.useCaps){
		strMenuLayer += "<layer id=\"division\" bgColor=\""+ this.lineColor +"\" WIDTH=" + this.width + " HEIGHT=" + this.capHeight + "Z-INDEX=4 LEFT=1 TOP="+ nestTop +">"+ separator +"</layer>";
		nestTop = nestTop + this.capHeight
	}

	for (x = 0; x < this.items.length; x++){
	
	   if(this.items[x][0]!=null){
			if (!isFirstItem & this.useDivisions == true){
				strMenuLayer += "<layer id=\"division\" bgColor=\""+ this.lineColor +"\" WIDTH=" + this.width + " HEIGHT=1 Z-INDEX=4 LEFT=1 TOP="+ nestTop +">"+ separator +"</layer>";
				nestTop++
			}
			strMenuLayer += "<layer id=\"" + this.name + "Item" + nestLayerID+"\" Z-INDEX=3 bgColor=\""+ this.color +"\" HEIGHT=14 WIDTH=" + (this.width -1) +" LEFT=1 TOP="+ nestTop +" onMouseover=\"" + this.name + ".menuOver(\'" + this.name + "Item" + nestLayerID +"\');\" onMouseOut=\"" + this.name + ".menuOut(\'" + this.name + "Item" + nestLayerID + "\');\" onClick=\"pH2.Utility.loadURL('"+ this.items[x][1]+"');\"><a class=" + this.style + " href=javascript:pH2.Utility.loadURL('"+ this.items[x][1]+"');>"+ this.items[x][0];
			strMenuLayer +="</a></layer>";		
			nestLayerID++;
			nestTop=nestTop+13+1;
			isFirstItem = false;
        }
	}

	strMenuLayer += "<layer id=\"division\" bgColor=\""+ this.lineColor +"\" WIDTH=" + this.width + " HEIGHT=1 Z-INDEX=4 LEFT=1 TOP="+ nestTop +">"+ separator +"</layer>";
	nestTop++;
	if(this.useCaps){
		strMenuLayer += "<layer id=\"division\" bgColor=\""+ this.lineColor +"\" WIDTH=" + this.width + " HEIGHT=" + this.capHeight + "Z-INDEX=4 LEFT=1 TOP="+ nestTop +">"+ separator +"</layer>";
		nestTop = nestTop + this.capHeight;
	}
	strMenuLayer +="</layer>";
	document.write(strMenuLayer);
		//alert(strMenuLayer);
   }


pH2.SimpleMenu.prototype.renderDropShadow = function( color, size){

	var i;
	var el = document.getElementById(this.name)
	for (i=size; i>0; i--)
	{
		var rect = document.createElement('div');
		var rs = rect.style
		rs.position = 'absolute';
		rs.left = (i) + 'px';
		rs.top = (i) + 'px';
		rs.width = el.offsetWidth + 'px';
		rs.height = el.offsetHeight + 'px';
		rs.zIndex = el.style.zIndex - i;
		//alert(rs.zIndex);
		rs.backgroundColor = color;
		var opacity = 1 - i / (i + 1);
		rs.filter = 'alpha(opacity=' + (100 * opacity) + ')';
		el.appendChild(rect);
		//el.insertAdjacentElement('afterEnd', rect);
		
	}
}

// -->




