var ptr=0;
var mptr=0;
var lptr=0;
var menuArray = new Array();
var itemArray = new Array();
var levelArray = new Array();
var maxLevel=3;
var menuDelay=5;
var parentHashArray = new Array();
var pha=0;
var pHash;


function cleanup () {

 ptr=0;
 mptr=0;
 lptr=0;
 menuArray = new Array();
 itemArray = new Array();
 levelArray = new Array();
 maxLevel=3;
 menuDelay=5;
	}

	function addMenuItem( parentId, text, link, id, openNewWindow) {

		itemArray[ptr++]=new menuItem(parentId, text, link, id, openNewWindow);
                parentHashArray[pha++]="this." + id + "=\"" + parentId + "\"";
	//if (pha < 10 && pha > 0)
//alert(parentHashArray[pha -1]);	
	}

	function addLevel(num, mClass, lClass , color, bgcolor, mColor, mBgColor) {


		levelArray[lptr++]=new level(num, mClass
				, lClass, color, bgcolor
				, mColor, mBgColor);
		
	}

	function addMenu(name, level, left, top) {

		menuArray[mptr++]=new mMenu(name, level, left, top);
		
	}



	function menuItem (parentId, text, link, id, openNewWindow){

		this.parentId=parentId;
		this.text=text;
		this.link=link;
		this.id=id;
		if (openNewWindow != null){
		if (openNewWindow) {
			this.target="_blank";
		}else{
		        this.target="_self";
		}
		}else {this.target="_self";}
	}


	function level (num,  lClass, color, bgcolor, mColor, mBgColor) {
		this.num = num;
	    	this.lClass=lClass;
		this.color=color;
		this.bgcolor=bgcolor;
		this.mColor=mColor;
		this.mBgColor=mBgColor;
	}

	function mMenu (id, level, left, top) {
		this.id=id;
		this.level=level;
		this.left=left;
		this.top=top;
	}







//color, bgcolor, mColor, mBgColor

 function parentHash() {
       for (var j=0; j < parentHashArray.length; j++) {
         eval(parentHashArray[j]);
       }
 }

 function getParent(id) {
	if (id == null) return;
 	return eval("pHash." + id);     

 }

 function levelColorHash () {
	  for (var j=0; j < levelArray.length; j++) {
		eval("this.level_" + levelArray[j].num + "=\"" + 
			levelArray[j].color + "|" +
			levelArray[j].bgcolor +  "|" +
			levelArray[j].mColor + "|" +
			levelArray[j].mBgColor  +
			"\";");
	 }
 }
 function levelClassHash () {
	  for (var j=0; j < levelArray.length; j++) {
		eval("this.level_" + levelArray[j].num + "=\"" + 
			levelArray[j].lClass +  
			"\";");
	 }
 }

 function menuLevelHash () {
	  for (var j=0; j < menuArray.length; j++) {
		eval("this." + menuArray[j].id + "=" + menuArray[j].level + ";");
	 }
 }

 function menuLocationHash () {
	  for (var j=0; j < menuArray.length; j++) {
		eval("this." + menuArray[j].id + "=\"" + 
		"left:" + 
		menuArray[j].left + "px;" + 
		"top:" + 
		menuArray[j].top + "px;\"" +
		";");
	 }
 }

 function getColorHashLine(id) {
        if (id == null) return;
        if (id.length == 0) return;
	var lch = new levelColorHash();
	var level= getLevel(id);
	return eval("lch.level_" + level + ".split(\"|\");");
 }


 function getLevel(id) {
        if (id == null) return;
        var mlh = new menuLevelHash();
	return (eval("mlh." + id));
 }
 

   function createMainMenu() {


    var tablescript="";

	for (var j=0; j < itemArray.length; j++) {
	   if (parseInt(getLevel(itemArray[j].parentId)) == parseInt(1)) {
		var colorLine = getColorHashLine(itemArray[j].parentId);
	  if (j == 0 ) {
	    tablescript +='<table id="main" onMouseOver="setTable(\'main\')" border="0" cellpadding="0" cellspacing="0" ' +
		'style="background-color:' + 
		colorLine[1] + '"' + 
                 ' >';

	}

	    tablescript +='<tr><td height="25px" align="left" valign="middle" id="' +
		itemArray[j].id +
		'" onMouseOver="setLast(this.id);' +
		'  setCurrent(this.id, \'' +
		    colorLine[1] + '\', \'' + colorLine[0] + '\');' +

		' hide(getLast() + \'Menu\');show(this.id + \'Menu\'); ' +
		//' hideCheck(getParent(getLast()), getLast() );show(this.id + \'Menu\'); ' +
                ' rollBack(this.id); ' +
                ' changeBg(this.id,  \'' +
		 colorLine[3] + '\',' +
		' \'' + colorLine[2] + '\')" ' +
		' >' +
		' <a id="' + 
		 itemArray[j].id  + 'a" ' +
		' style="color:' + colorLine[0] + '"' +
		' class="' +levelArray[0].lClass + '" ' +
                ' href="' + 
		itemArray[j].link + '" ' + 
                ' target="' + 
		itemArray[j].target + '">' +
		itemArray[j].text + '</a></td></tr>';
		
	   }
	}

	tablescript +='</table>';

	return tablescript;

  }


  function createSubMenus() {

	var levelMHash = new menuLevelHash();
	var locationHash = new menuLocationHash();
	var lColorHash = new levelColorHash();
	var lClassHash = new levelClassHash();
	var lh, lc, mc;

	var tablescript="";
	var parent;
	var index;
	var endTable=false;
	var itemLevel;
	var name, itemName;
	var itemIndex;
	var started=false;
	var link, linkClass, target;



//0 = color, 1 = bgcolor, 2 = mcolor 3 = mbgcolor

	index=0;
	for (var j=0; j < itemArray.length; j++) {
			if (itemArray[j].parentId != parent) {
				if (started)  {
		//tablescript += '\n<tr onMouseOver="hideAll(\'' +
		//		'all\')" ><td onMouseOver="hideAll(\'' +
		//		      'all\')" height="1"></td></tr>';
					tablescript += "</table>";
}
				
				parent=itemArray[j].parentId;
				index=1;

				itemLevel= eval("levelMHash." + parent);

			if (itemLevel == 1) continue;
				lh = eval("lColorHash.level_" + itemLevel + ".split(\"|\");");

				name= parent + 'Menu';


				tablescript += '\n<table onMouseOver="setTable(\'' +
				    name + '\')"  id="' +
			 	    name  + '" name="' +
				    name + 
				    '" \n style="visibility:hidden;position:absolute; ' +
				    eval("locationHash." + parent) + 
				    'background-color:' +
				    lh[1] + 
				   '"';
				if (itemLevel != maxLevel) {
				    //tablescript += ' onMouseOut="setDelay(' +
				    //menuDelay + 
				    //', \'hideAll()\')';
				}
				
				tablescript += '"\n>';
		 	         endTable=true;
			}else{
				if (itemLevel == 1) continue;
				
				index++;
				endTable=false;

			}
		       started=true;
		       itemName = itemArray[j].id;

		       link=itemArray[j].link;
		       if (itemArray[j].link == "") 
			link="javascript:;";
                       target=itemArray[j].target; 

		       tablescript += '\n<tr><td valign="top"   id="' +
			        itemName +
				'" bgcolor="' + lh[1] + 
		        '"\n onMouseOver="setLast();';
			tablescript +=  ' setCurrent(this.id, \'' +
					lh[1] + '\', \'' + lh[0] + '\');';
			tablescript += '  rollBack(this.id); ' 
			tablescript += '  hideCheck(getParent(getLast()), ' + 
					' getLast() ); ' ;
			tablescript += '  show(this.id + \'Menu\');' ; 

			tablescript +='changeBg(this.id, \'' +
		                lh[3] + '\', \'' + lh[2] + '\')' +
				'">' +
				'\n <a href="' +
                                 link + 
				'" style="color:' + lh[0] + 
				'"\n id="' +
                                itemName + 'a" ' +
                                ' \n class="' +
				eval("lClassHash.level_" + itemLevel) +
				'" target="' + target +
				'" >' +
                                itemArray[j].text + 
			        '</a>\n</td></tr>'
				;
		     
	}

		tablescript += "</table>";

	        pHash=new parentHash();
		return tablescript;

	}//end createSubMenus




	       




