		
// ContainerDirections
var East=0;var West=1;var South=2;
var Horizontal = 1;var Vertical=2;
var PUBhtml = "";
var MenuSelected=false;
var BarObjects = new ObjectCollection();
var GlobalObjects = new ObjectCollection();

// Global stuff///////////////////////////////////////
document.onclick  = onDocumentClick;
function onDocumentClick()
{
  if(!MenuSelected)
	 CollapseMenuBars();	
}
function CollapseMenuBars()
{
  for (var menubar=0;menubar<BarObjects.Items.length;menubar++)
		BarObjects.Items[menubar].Collapse();		
}
function ObjectCollection()
{
  this.index=0;
  this.Items = new Array();
  this.Add	 = function(item)
				 {
				  this.Items[this.index] = item; 
				  this.index++;
				  return (this.index-1);
				 }
 }
 
function findObject(GlobalIndex)
{		 
 return GlobalObjects.Items[GlobalIndex];
}
////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////
function MenuItem(text,url,target)
{   
  //PL: target added for frames
  this.NavigateURL     = url;
  this.CssClassDefault = "MenuItemDefault";
  this.CssClassActive  = "MenuItemActive";  
  this.Items = new itemContainer(); // Container for the children
  this.Items.Parent = this;
  this.Text = text;
  this.Expanded = false;  
  this.Render = function()
   { 
   	if(this.Parent.Parent){this.Items.ContainerDirection = East; }
    var style="";
	if(document.location.href.indexOf(this.NavigateURL)>-1)
	{
		//style ="color:#E55401;";
		if(this.Parent.Parent)
		{
		// document.getElementById(this.Parent.Parent.ID).style.color="#E55401";
		 
		 this.Items.ContainerDirection = East;  
	 	}
	 	else
	 	{
	 		//style+="color:#E55401;";
	 	}
	 	//style="style='"+style+"'"; 	
	}
      
       
     Render
     (
	     "<div "+style+" id=\""+this.ID+"\"" +
	     " class=\""+this.CssClassDefault+"\""+
	     " onClick=\"findObject("+this.GlobalIndex+").Click();\""+
		 " onMouseOut=\"findObject("+this.GlobalIndex+").MouseOut();\""+
		 " onMouseover=\"findObject("+this.GlobalIndex+").MouseOver();\""+
	     ">"+this.Text+"</div>"  
     );
   }   
	this.Expand = function()
	{
	
		if (!this.Expanded)
		{
			document.getElementById(this.ID).className = this.CssClassActive;
			this.Expanded = true;
			// Collapse children of parents children
			for (var item=0;item<this.Parent.Items.length;item++)
				if ((this.Parent.Items[item]!=this) && (this.Parent.Items[item].Expanded))
					this.Parent.Items[item].Collapse();
			
			if (this.Items.Items.length>0)
				document.getElementById(this.Items.ID).style.visibility = 'visible';
		}
	}
	this.Collapse = function()
	{
	 if(this.Expanded)
	 {		
	 
		document.getElementById(this.ID).className = this.CssClassDefault;
	 
		
		this.Expanded = false;
		if (this.Items.Items.length>0)
		{
	  		document.getElementById(this.Items.ID).style.visibility = 'hidden';	
	  		for (var item =0;item<this.Items.Items.length;item++)
	  		{
	  			this.Items.Items[item].Collapse();
	  		}	  		
	  	}		
	  }
	}
	
	this.MouseOver = function()
				{
				  MenuSelected = true;
				  this.Expand();				  					
				}
	this.MouseOut = function()
				{
  				  MenuSelected = false;  				  
				}	
	this.Click = function()
				{	
				    if((target != null)&&(target!=""))
				    {		
				        window.frames[target].document.location.href = this.NavigateURL
				    }
				    else
				    {
				        document.location.href = this.NavigateURL;					
				    }
				}						
 }
////////////////////////////////////////////////////////////////





////////////////////////////////////////////////////////////////
function itemContainer()
{   
	
  this.CssClass = "itemGroup";
  this.ContainerDirection = East;  
  this.ItemPositioning    = Vertical; 
  this.Items  = new Array(); // Array of MenuItems  	
  this.GlobalIndex = GlobalObjects.Add(this); 
  this.ID = "C" + this.GlobalIndex;
  BarObjects.Add(this); 
  this.Add = function(item)
  { 
    item.Index  = this.Items.length;    
    item.Parent = this;
    item.GlobalIndex = GlobalObjects.Add(item);
    item.ID			 = this.ID + "." + item.Index; 
  	this.Items[this.Items.length] = item;
  } 	

  this.Create = function()
  {
   this.Render();
   this.Equalize(); 
    // Reder Containers of children      
	  for(var item=0;item<this.Items.length;item++)
	  {
	    if (this.Items[item].Items.length>0)
			this.Items[item].Items.Create();			
	  }	  
  }
  this.Collapse = function()
  {
   for(var item=0;item<this.Items.length;item++)
	this.Items[item].Collapse();		
  }
  
  this.Render = function()
  {
		 if (this.Items.length>0)
		  {
	     // Render Cointainer div
			Render("<div id=\""+this.ID+"\" class=\""+ this.CssClass +"\" style=\"position:absolute;"+
			"visibility:"+(this.Parent?"hidden":"visible")+"\">");
			for(var item=0;item<this.Items.length;item++)
	   			this.Items[item].Render();		
			 Render("</div>"); 	 
		  }    
			// render children
	 	   for(var item=0;item<this.Items.length;item++)
	   			this.Items[item].Items.Render();		
  }
  
  this.Equalize = function()
  {
    if (this.ItemPositioning == Vertical)
	  {
		// make Items same width
		var maxwidth=0;
		// get max width
  		for(var item=0;item<this.Items.length;item++)
			maxwidth = Math.max(maxwidth,document.getElementById(this.Items[item].ID).offsetWidth);
			//make  all Items maxwidth
		for(var item=0;item<this.Items.length;item++)
			  	document.getElementById(this.Items[item].ID).style.width = maxwidth; 				  	
	 }
	 
	if (this.ItemPositioning == Horizontal)
		{
			// make Items same height
			var maxheight=0;
			// get max height
  			for(var item=0;item<this.Items.length;item++)
				maxheight = Math.max(maxheight,document.getElementById(this.Items[item].ID).offsetHeight);
			//make  all Items maxheight			
			for(var item=0;item<this.Items.length;item++)
			{
				document.getElementById(this.Items[item].ID).style.height = maxheight; 				 		
		  		document.getElementById(this.Items[item].ID).style.display = 'inline'; 		
		  		
			}
			document.getElementById(this.ID).style.height = maxheight;
		}		
		
		// equalize children	  	
		for(var item=0;item<this.Items.length;item++)
	  			this.Items[item].Items.Equalize();	
  }
  
  this.Position = function()
  {
    if(this.Items.length>0)
    {
		if(this.Parent!=null) 
		{		
		
	

		
		  
			if (this.ContainerDirection == East)
				{
					document.getElementById(this.ID).style.left =  document.getElementById(this.Parent.Parent.ID).offsetLeft + document.getElementById(this.Parent.Parent.ID).offsetWidth;
				  	document.getElementById(this.ID).style.top  = document.getElementById(this.Parent.ID).offsetTop + document.getElementById(this.Parent.Parent.ID).offsetTop;
				}
			if (this.ContainerDirection == West)
				{
					document.getElementById(this.ID).style.left = document.getElementById(this.Parent.Parent.ID).offsetLeft - document.getElementById(this.ID).offsetWidth;
					document.getElementById(this.ID).style.top  = document.getElementById(this.Parent.ID).offsetTop + document.getElementById(this.Parent.Parent.ID).offsetTop;
				}
			if (this.ContainerDirection == South)
				{				     				
					document.getElementById(this.ID).style.left = document.getElementById(this.Parent.Parent.ID).offsetLeft + document.getElementById(this.Parent.ID).offsetLeft;
					document.getElementById(this.ID).style.top  = document.getElementById(this.Parent.Parent.ID).offsetTop + 
																	document.getElementById(this.Parent.ID).offsetTop + 
																	document.getElementById(this.Parent.ID).offsetHeight;
				}	
		}
		
		for(var item=0;item<this.Items.length;item++) this.Items[item].Items.Position();		   
	 }
	}	
}
////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////
function Render(html)
{
	document.write(html);
}

function init()
{
    //
}
