function bwrcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var brw = new bwrcheck();

var oMenuList = new Array();
var menDiv;

function setUpMenuPopup()
{
  if(brw.ns4)document.captureEvents(Event.MOUSEMOVE)
  
	var sStyleStr = ""
		
	if( brw.mac )
		sStyleStr = "style='position:absolute; top:0; left:0;'"
		
	document.writeln( "<div onMouseOut='PopDown( event );' id='idDivMenu' class='clDescriptionCont' align='center' " + sStyleStr + "></div>" );
	menDiv = new GetCompObj( 'idDivMenu' );	
}

// Event Position
var posx = 0;
var posy = 0;

function Menpopmousemove(e)
{
	posx = brw.ns4||brw.ns6?e.pageX:event.x; 
	posy = brw.ns4||brw.ns6?e.pageY:event.y;
}

function Write_It(text)
{
	if (brw.ns4)
	{
		this.wref.open();
		this.wref.write(text);
		this.wref.close();
	}
	else 
		this.wref.innerHTML = text
}

function GetCompObj(objId)
{							
  this.obj=brw.dom? document.getElementById(objId):brw.ie4?document.all[objId]:brw.ns4?document.layers[objId]:0;
	if(!this.obj) return false

	this.css=brw.dom||brw.ie4?this.obj.style:brw.ns4?this.obj:0;	
  this.wref=brw.dom||brw.ie4?this.obj:brw.ns4?this.css.document:0;		
	this.WriteIt = Write_It;
	return this
}


function GetCompIMGObj( objId ){							
	
  this.obj=brw.dom? document.getElementById(objId):brw.ie4?document.all[objId]:brw.ns4?document.images[objId]:0;
	if(!this.obj) return false
	this.css=brw.dom||brw.ie4?this.obj.style:brw.ns4?this.obj:0;
	this.X = getAbsX( this.obj );
	this.Y = getAbsY( this.obj );
	
	return this;
}


// get the true offset of anything on NS4, IE4/5 & NS6, even if it's in a table!
function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
function getAbsPos(elt,which) {
 iPos = 0;
 while (elt != null) {
  iPos += elt["offset" + which];
  elt = elt.offsetParent;
 }
 return iPos;
}


var spx = bw.ns4||window.opera?"":"px";


// ####  MENU SETTINGS  ######
// Menu Offset position
var offsetX = 0;
var offsetY = 3;

var ns4TimerId;
var ns4TimeOut = 15000;

// ###########################


function MenuObject()
{
	this.Div;
	this.Id;
	this.Delimiter;
	
	this.Text;
	this.Top;
	this.Left;
	this.Width;
	this.Height;
	
	this.StyleClass;
	this.Align = "left";
	this.Nowrap = true;
	this.table;
	
	this.ShowMenu = Show_Menu;
}

function Show_Menu( showPosX, showPosY , bDoCenter )
{
		var XPos = showPosX;
		var sTableBegin = "<div style='position:relative;'><table onMouseOut='event.cancelBubble=true;' id='tbl" + this.Id + "'width='0' class='" + this.StyleClass + "'>";
		
		var sTableEnd = "</table></div>\n";

		this.Div.WriteIt( sTableBegin + this.Text + sTableEnd  );
		
		if( brw.ie5||brw.ie6 ) posy = posy + document.body.scrollTop;

		var tblname = 'tbl' + this.Id ;
		
		if( !brw.ns4 )
		{
			var tblXOffset = 5;
			var tbl = GetCompObj( tblname );
			tbl.css.width = tbl.obj.offsetWidth + tblXOffset + spx;

			this.Div.css.width = tbl.obj.offsetWidth + tblXOffset + 5 + spx;
			this.Div.css.height = tbl.obj.offsetHeight + 5 + spx;
					
			if( bDoCenter )
			{
				XPos = XPos - ( tbl.obj.offsetWidth + tblXOffset ) / 2 ;
			}
		}

		this.Div.css.left = ( offsetX + XPos )+ spx;
		this.Div.css.top = ( offsetY + showPosY ) + spx;

		this.Div.css.visibility = "visible";
		
		if( brw.ns4 )
		{
			window.clearTimeout( ns4TimerId );
			ns4TimerId = setTimeout( "PopDown( null )", ns4TimeOut );
		}
}
	


function CreateMenu( szMenuID, szDelimiter, szStyleClass , iIdx )
{
	var oMenu = new MenuObject();

	oMenu.Div = menDiv;
	oMenu.Id = szMenuID;
	oMenu.Delimiter = szDelimiter;
	oMenu.StyleClass = szStyleClass;
	oMenu.Text = "";
	
	oMenuList[ iIdx ] = oMenu;
	
	return oMenu;
}

function AddItem( iIdx, szItem )
{	
	var oMenu = GetMenu( iIdx );
	var sCls = "";
		
	var sTrTdBegin = "<tr align='center'><td onMouseOut='event.cancelBubble=true;' nowrap align='center'>";
	sTrTdBegin += "<div id='level3' onMouseOut='PopDown( event );'><div id='level3Items'></div></div>";
	var sTdTrEnd = "</td></tr>";
	
	if( oMenu )
	{
		if( oMenu.Text != "" )
			oMenu.Text += sTrTdBegin + oMenu.Delimiter + sTdTrEnd;
			
		oMenu.Text += sTrTdBegin + szItem + sTdTrEnd;
	}	
}

function GetMenu( iIdx )
{
	if( iIdx < oMenuList.length )
		return oMenuList[iIdx];
	
	return false;
}

function HideMenu( e , iIdx )
{
	var oSource;
	
	Menpopmousemove( e );
	
	if (!window.event) 
		oSource = e.target;
	else
		oSource = e.srcElement;

	if( brw.ie5||brw.ie6 ) posy = posy+document.body.scrollTop;
	
	var so_y = posy;
	var oMenu = GetMenu( iIdx );
	
	if( oMenu )
	{
		oSource = new GetCompIMGObj( oMenu.Id ); 
		
		if( so_y >= ( oSource.obj.height + oSource.Y ) )
			return true;
	}


	menDiv.css.visibility = "hidden";
	hideLevel3();
}

function PopDown( e )
{
	menDiv.css.visibility = "hidden";
	hideLevel3();
}


function PopupMen( e, iIdx ) 
{
	var oSource;

	Menpopmousemove( e );
	
	if (!window.event) 
		oSource = e.target;
	else
		oSource = e.srcElement;

	if( oSource )
	{
		var oMenu = GetMenu( iIdx );
		
		if( oMenu )
		{
			oSource = new GetCompIMGObj( oMenu.Id );
			
			if( brw.ns4 )
				oMenu.ShowMenu( oSource.X, oSource.Y + oSource.obj.height, false );
			else
				oMenu.ShowMenu(  oSource.X + ( oSource.obj.width / 2 ) , oSource.Y + oSource.obj.height, true );			
		}
	}
}

setUpMenuPopup();

function hideLevel3() {
	document.getElementById("level3").style.visibility="hidden";
}
