var n_predefSubm = 6;

function Menu(nm,pt,ty,vt,lf,tp,dv,vs,sp,act_pt)//name,img_path,type,vertical,left,top,layer(div),vertical space,separator,action path
{
	this.name = nm;
	this.path = pt;
	this.img_type = ty;
	this.vert = vt || false;
	this.separat = sp || "";
	this.layer = dv || "dmenu";
	
	this.left = lf || 15;
	this.top = tp || 0;
	this.vspace = vs || 0;
	
	this.actpath = act_pt || "";
	
	this.items = new Array();
	//this.buttons = new Array();
	this.overs = new Array();
	this.actions = new Array();
	this.titles = new Array();
	
	this.AddMenuItem = AddMenuItem;
	this.WriteMenu = WriteMenu;
	
	//this.MenuAction = MenuAction;
	//if (!window.menus) window.menus = new Array();
/*	if(!vt) window.menus = this;
		else  
		   window.smenus = this;
*/
	window.menus = this;		   
	document.open("text/html");
	//document.writeln("<div id='dmenu' style='position:absolute;z-index:100; left:"+this.left+"; top:"+this.top+"'>ghghgh</div>");
	//document.writeln("<div id='dmenu'></div>");
	//document.writeln(content);
	
	document.close();
}

function AddMenuItem(lbl,tit,lnk)
//class Menu function
//adds an item to the existing menu
{
	this.items[this.items.length] = lbl; //item label
	//this.buttons[this.buttons.length] = this.path+btn+'.'+this.img_type;
	//this.overs[this.overs.length] = this.path+btn+'_over.'+this.img_type;
	this.actions[this.actions.length] = lnk || lbl + '.htm'; //on click item action
	this.titles[this.titles.length] = tit || ''; //title for on mouse over (ALT attribute on IMG tag)
	
	this.overs[this.overs.length] = pict.length;
	preloadImages(this.path+lbl+'.'+this.img_type, this.path+lbl+'_over.'+this.img_type);


//	MM_preloadImages("'"+this.path+lbl+'.'+this.img_type+"','"+this.path+lbl+'_over.'+this.img_type+"'");
}
var l;

function WriteMenu(op)
{
	var opt = op || 0;
	content = this.separat;
	for(i=0;i<this.items.length;i++)
	 {
		//if(i==4) content += "<br>";
		//if(i==6) content += '<img src="pictures/spaceer.gif" width="50" height="1">';
		if(i==op)
		{
			if(this.name=='root')crt = '_crt';else crt='_over';
		}
		else
		{
			crt = "";
			//lnk = (this.submenus[i]) ? "#" : (this.items[i]+".html");
			content += '<a href="'+this.actions[i] + '" title="' + this.titles[i] + '" ';
				content += 'onMouseOut="changeImages(' + "'" + this.items[i] + "',";
				content += (this.overs[i]) +  ',0);"';
				content += 'onMouseOver="changeImages(' + "'" + this.items[i] + "',";
				content += (this.overs[i]+1) +  ',1);"';
				content +=   '">';
		}
		content += '<img name="' + this.items[i] + '" border="0" vspace="'  + '" ';
			content += 'src="' + this.path + this.items[i] + crt + '.' + this.img_type + '" ';
			content += 'alt="' + this.titles[i]+ '">';
		content += '</a>'+this.separat;
	}
	
	//alert(content);
	document.getElementById(this.layer).innerHTML = content;
	
}



function MenuAction(opt,subopt)
{
	//this = window.menus;
	//window.menus.WriteMenu(opt,subopt);
	/*if(subopt) 
		{
			if(document.images)
				{
					document.location.replace(window.menus.actpath + window.menus.submenus[opt-1].items[subopt-1] + '.htm');
					//if(!window.menus.vert) document.location.replace(window.menus.actpath + window.menus.submenus[opt-1].items[subopt-1] + '_top.htm');
				}
				else
				{
					document.location = window.menus.actpath + window.menus.submenus[opt-1].items[subopt-1] + '.htm';
				//	if(!window.menus.vert) document.location = window.menus.actpath + window.menus.submenus[opt-1].items[subopt-1] + '_top.htm';
				}
		}
	   else
	    {
			if(document.images)
				{
					document.location.replace(window.menus.actpath + window.menus.items[opt-1] + '.htm');
					//if(!window.menus.vert) document.location.replace(window.menus.actpath + window.menus.items[opt-1] + '_top.htm');
				}
				else
				{
					document.location = window.menus.actpath + window.menus.items[opt-1] + '.htm';
					//if(!window.menus.vert) document.location = window.menus.actpath + window.menus.items[opt-1] + '_top.htm';
				}					
		}
	//window.status = window.menus.actions[opt-1];
	*/
}


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	var a = changeImages.arguments;
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<a.length; i+=3) {
			/*if(a[i+2])
					document[a[i]].src = pict[window.menus.overs[a[i+1]]].src;
				else
					document[a[i]].src = pict[window.menus.buttons[a[i+1]]].src;
			*///alert(pict[window.menus.overs[a[i+1]]].src);
			//alert(document[a[i]].src + " " +a[i+1]+" "+pict[a[i+1]*2].src);
			document[a[i]].src = pict[a[i+1]].src;
		}
	}
}

var preloadFlag = false;
var pict = new Array();
var nrpict = 0;

function preloadImages()
{
	var d=document, a=preloadImages.arguments;
	if(d.images)
		{
			for(i=0; i<a.length; i++)
				pict[pict.length] = newImage(a[i]);
				
			preloadFlag=true;
		}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
