var DataStruct = new Array();
var showtimeout; 
var hidetimeout;

function TopItem(count) {
	this.itemcount = eval("menu" +count+ "_items");
	this.text = eval("menu" +count+ "_text");
	this.picn = eval("menu" +count+ "_picn");
	this.pich = eval("menu" +count+ "_pich");
	this.islink = (this.itemcount > 0) ? false : true;
	//this.url = (this.islink) ? eval("menu" +count+ "_url") : "Javascript: void(0)";
	this.url = eval("menu" +count+ "_url");
	this.items = new Array();
	this.x = (document.all) ? eval("menu_x"): eval("menu_x-2");
	this.y = (document.all) ? eval("menu_y"): eval("menu_y");
	this.hidetimeout;
	this.overtop = false;
	this.oversub = false;
	this.opensub = false;
}

function SubItem(count,subcount) {
	this.text = eval("menu" +count+ "_item" +subcount+ "_text");
	this.picn = eval("menu" +count+ "_item" +subcount+ "_picn");
	this.pich = eval("menu" +count+ "_item" +subcount+ "_pich");
	this.url = eval("menu" +count+ "_item" +subcount+ "_url");
}

function BuildDataStruct() {
	for(topc=0;topc<menu_topics;topc++) {
		DataStruct[topc] = new TopItem(topc+1);
		for(subc=0;subc<DataStruct[topc].itemcount;subc++)
			DataStruct[topc].items[subc] = new SubItem(topc+1,subc+1); 
	}
}

function MenuLayer(lyr) {
	if (document.layers) {
		this.obj = this.css = document.layers[lyr];
		this.x = this.obj.clip.left;
		this.y = this.obj.clip.top;
		this.w = this.obj.clip.width;
		this.h = this.obj.clip.height;
	}
	else {
		this.obj = document.all[lyr];
		this.css = this.obj.style;
		this.x = parseInt(this.css.pixelLeft);
		this.y = parseInt(this.css.pixelTop);
		this.w = this.obj.scrollWidth;
		this.h = this.obj.scrollHeight;
	}
	this.v = this.css.visibility = (document.layers)? "hide" : "hidden";
	this.id = lyr;
	this.zdx = this.css.zIndex;
	this.show = ShowLayer;
	this.hide = HideLayer;
	this.moveto = MoveLayerTo;
}
		
function ShowLayer() {
	this.v = this.css.visibility = (document.layers)? "show" : "visible"
}
	
function HideLayer() {
	this.v = this.css.visibility = (document.layers)? "hide" : "hidden";
}
	
function MoveLayerTo(x,y) {
	if (x != null)
		this.x = this.css.left = x;
	if (y != null)
		this.y = this.css.top = y;
}

function BuildMenuCode() {
	var MenuCode = new String();
	// --- main menu table - start ----
	MenuCode = 	'<table border="0" cellspacing="0" cellpadding="0"><tr>'
	for(topc=0;topc<DataStruct.length;topc++) {
		MenuCode +=	'<td>'
				 +  '<div class="tablyr" id="tab' +topc+ '">'
				 +	'<table border="0" cellspacing="0" cellpadding="0">'
				 +	'<tr>'
				 +	'<td ' +((text_version&&top_class_name)?('class="' +top_class_name+ '"'):(''))+ '>';
		if(text_version)				 
			MenuCode +=	'<a ' +( (!DataStruct[topc].islink)?('onmouseover="ShowSubMenu(' +topc+ ')" onmouseout="HideSubMenu(' +topc+ ')"'):'')+ ' href="' +DataStruct[topc].url+ '">'
				 	 +	DataStruct[topc].text
				 	 +	'</a>';
		else		 
			MenuCode +=	'<a ' +((!DataStruct[topc].islink) ? ('onmouseover="ShowSubMenu(' +topc+ ');PicOverTop(' +topc+ ')" onmouseout="HideSubMenu(' +topc+ ');PicOutTop(' +topc+ ')"'):('onmouseover="PicOverTop(' +topc+ ')" onmouseout="PicOutTop(' +topc+ ')"'))+ ' href="' +DataStruct[topc].url+ '">'
				 	 +	'<img name="t' +topc+ '" src="' +DataStruct[topc].picn+ '" border="0" alt="">'
				 	 +	'</a>';
		MenuCode +=	'</td></tr></table>'
				 + 	'</div>'
				 +	'</td>';
	}
	MenuCode +=	'</tr></table>'
	// --- main menu table - end ----
		
	return MenuCode;
}

function BuildDivCode() {
	var MenuCode = new String('');
	
	for(topc=0;topc<DataStruct.length;topc++)
		
		if(!DataStruct[topc].islink) {
		MenuCode += '<div class="menulyr" id="m' +topc+ '">'
				 +	'<table border="0" cellspacing="0" cellpadding="0">';
		for(subc=0;subc<DataStruct[topc].items.length;subc++) 
			if(text_version) {
				MenuCode += '<tr>'
						 +	'<td ' +((text_version&&sub_class_name)?'class="' +sub_class_name+ '"':'')+ '>'
						 +	'<a onmouseover="DataStruct['+topc+'].oversub=true;" onmouseout="DataStruct['+topc+'].oversub=false; HideSubMenu(' +topc+ ')" href="' + DataStruct[topc].items[subc].url + '">'						 
						 +	DataStruct[topc].items[subc].text
						 +	'</a>'
						 +	'</td>'
						 +	'</tr>';
			}
			else {
				MenuCode += '<tr>'
						 +	'<td>'
						 +	'<a onmouseover="DataStruct['+topc+'].oversub=true;PicOver('+topc+','+subc+')" onmouseout="DataStruct['+topc+'].oversub=false; HideSubMenu(' +topc+ ');PicOut('+topc+','+subc+')" href="' + DataStruct[topc].items[subc].url + '">'
						 +	'<img name="t' +topc+ 's' +subc+ '" src="' +DataStruct[topc].items[subc].picn+ '" border="0" alt="">'
						 +	'</a>'
						 +	'</td>'
						 +	'</tr>';
			}
		MenuCode += '</table>'
				 +	'</div>';
		}
	return MenuCode;
	}

function ShowSubMenu(count) {
	clearTimeout(showtimeout);
	OverTop = DataStruct[count].overtop = true;
	DataStruct[count].showtimeout=setTimeout("DataStruct["+count+"].lyr.show();DataStruct["+count+"].opensub=true",pause);
}

function HideSubMenu(count) {
	clearTimeout(DataStruct[count].showtimeout);
	clearTimeout(DataStruct[count].hidetimeout);
	DataStruct[count].overtop = false;
	if (text_version)
		var advice = "if(!DataStruct["+count+"].overtop && !DataStruct["+count+"].oversub) { DataStruct[" +count+ "].lyr.hide(); DataStruct["+count+"].opensub=false } else void(0)"; 
	else
		var advice = "if(!DataStruct["+count+"].overtop && !DataStruct["+count+"].oversub) { DataStruct[" +count+ "].lyr.hide(); DataStruct["+count+"].opensub=false; PicOutTop(" +count+ "); } else void(0);"; 
	DataStruct[count].hidetimeout=setTimeout(advice,pause);
}

function PicOver(item,count) {
	var tempImage = (document.all) ? eval("document.all.t" +item+ "s" +count) : eval("document.m" +item+ ".document.images[" +count+ "]");
	tempImage.src = DataStruct[item].items[count].pich;
}

function PicOut(item,count) {
		var tempImage = (document.all) ? eval("document.all.t" +item+ "s" +count) : eval("document.m" +item+ ".document.images[" +count+ "]");
		tempImage.src = DataStruct[item].items[count].picn;
}

function PicOverTop(item) {
	var tempImage = eval("document.t" +item);
	tempImage.src = DataStruct[item].pich;
}

function PicOutTop(item) {
	if (!DataStruct[item].opensub)
		{
		var tempImage = eval("document.t" +item);
		tempImage.src = DataStruct[item].picn;
		}
}

function InsertMenu() {
	document.write(BuildMenuCode());
	}	


function InsertDivs() {
	document.write(BuildDivCode());
	
	var x = DataStruct[0].x
	for(topc=0;topc<DataStruct.length;topc++) {
		DataStruct[topc].tab = new MenuLayer("tab" + topc);
		x += ((topc < 1) ? 0 : (DataStruct[topc-1].tab.w));
		if(!DataStruct[topc].islink) {
			DataStruct[topc].lyr = new MenuLayer("m" + topc);
			DataStruct[topc].lyr.moveto(x, DataStruct[topc].y);
			}
		DataStruct[topc].tab.show();
	}
}

BuildDataStruct();