// FG Menu (JS 1.2)
// ver. 1.75 - 20050403 (page target to new window)

function fgMenu(objName,prefix,roll) {
	this.objName = objName;
	this.menuArray = eval(prefix+"Menu");
	this.mnuPrefix = prefix+"Menu";
	this.lyrPrefix = prefix+"Layer";
	this.divPrefix = prefix+"Div";
	this.classPrefix = prefix;
	this.numBlocks = this.menuArray.length;
	this.menuLevels = new Array(1);
	this.menuLevelsTrack = new Array(1);
	this.roll = null;	// roll;
	this.delay = 600;
	this.z_index = 50;
	this.lastInitID = "";
	this.lastParentID = "";		// 0
	this.lastMenuTrack = new Array();
	this.timerID;
	this.isTimer = false;
	this.load = false;
	
	this.initMenu = initMenu;
	this.initLayer = initLayer;
	this.sniffItems = sniffItems;
	this.loopInit = loopInit;
	this.buildMenu = buildMenu;
	this.menuOn = menuOn;
	this.menuOff = menuOff;
	this.levelOver = levelOver;
	this.levelOut = levelOut;
	this.showMenu = showMenu;
	this.hideMenu = hideMenu;
	this.timeoutMenu = timeoutMenu;
	this.clearTimeoutMenu = clearTimeoutMenu;
	this.toggleColor = toggleColor;
	this.clickURL = clickURL;
	this.debug = debug;
}
var test = "";
function initMenu() {
	for (var i=1; i<this.menuLevels.length; i++) {
		test += this.lyrPrefix + this.menuLevels[i][0] + ((this.menuLevels[i][2] != 0)? '0' : '') + " = new DynLayer('" + this.divPrefix + this.menuLevels[i][0] + ((this.menuLevels[i][2] != 0)? '0' : '') + "')\n";		// DEBUG
		eval(this.lyrPrefix + this.menuLevels[i][0] + ((this.menuLevels[i][2] != 0)? '0' : '') + " = new DynLayer('" + this.divPrefix + this.menuLevels[i][0] + ((this.menuLevels[i][2] != 0)? '0' : '') + "')");
	}
	this.load = true;
}
function sniffItems() {
	var arg = eval(this.mnuPrefix + this.lastInitID);
	test += this.mnuPrefix + this.lastInitID + "\n";		// DEBUG
//	alert(test);		// DEBUG
	for (var i=1; i<arg.length; i++) {
//		alert("ITEM = " + arg[i]);		// DEBUG
		if (arg[i].length > 3) {
//			alert("NEW LEVEL");		// DEBUG
			this.loopInit(this.lastParentID,i);
		}
	}
}
function initLayer(parent,item) {
	var p = new String(parent);
	if (item) { var i = new String(item); p = p + i; }
	this.lastInitID = (item)? this.lastInitID + "[" + i + "][3]" : "[" + p + "]";
	this.lastParentID = (item)? this.lastParentID + i : p;
	this.menuLevels[this.menuLevels.length] = [p,this.lastInitID,((item)? parent : 0)];
	this.menuLevelsTrack[this.menuLevelsTrack.length] = [p,this.lastInitID,((item)? parent : 0)];
	// DEBUG
	test += this.lyrPrefix + p + ((item)? "0" : "") + " .... ";
//	alert(test);
	// DEBUG
}
function loopInit(parent,item) {
	eval("this.initLayer(" + ((item)? parent + "," + item : parent) + ")");
	this.sniffItems();
	this.menuLevelsTrack.splice(this.menuLevelsTrack.length-1,1);
	this.lastInitID = (item)? this.menuLevelsTrack[this.menuLevelsTrack.length-1][1] : "";
//	alert(this.lastParentID);		// DEBUG
	this.lastParentID = (item)? this.menuLevelsTrack[this.menuLevelsTrack.length-1][0] : "";
//	alert(this.lastParentID);		// DEBUG
}
function buildMenu() {
	for (var i=1; i<this.numBlocks; i++) {
		if (this.menuArray[i].length > 0) { this.loopInit(i); }
	}
	this.lastParentID = "";		// 0
	// DEBUG
	var levels = "LEVELS .... " + (this.menuLevels.length-1) + "\n\n";
	for (var z=1; z<this.menuLevels.length; z++) { levels += this.menuLevels[z] + "\n"; }
//	alert("FINAL\n\n" + test + "\n\n\n" + levels);
	// DEBUG
	
	// this.css and this.html
	this.css = css(this.divPrefix,null,null,null,null,null,null,this.z_index,"text-align:left");
	this.html = '<div id="'+this.divPrefix+'">\n';
	for (var i=1; i<this.menuLevels.length; i++) {
		var a = eval(this.mnuPrefix+this.menuLevels[i][1]);
		if (a.length > 0) {
			this.css += css(this.divPrefix+this.menuLevels[i][0]+((this.menuLevels[i][2] != 0)? '0' : ''),a[0][0],a[0][1],a[0][2],null,null,"hidden");
			this.html += '<div id="' + this.divPrefix+this.menuLevels[i][0]+((this.menuLevels[i][2] != 0)? '0' : '') + '"><div class="'+this.classPrefix+'Menu-1" onmouseover="' + ((this.menuLevels[i][2] == 0 && this.roll)? this.roll+'.Click('+this.menuLevels[i][0]+')' : '') + '" onmouseout="">\n';
			for (var x=1; x<a.length; x++) {
				var onclickValue;
				if (a[x][2] && a[x][2] == "_blank") { onclickValue = 'clickURL(\''+a[x][1]+'\',\''+a[x][2]+'\')'; }
				else if (a[x][2]) { onclickValue = a[x][2]; }		// Pozor chyba pri jinem targetu!
				else { onclickValue = 'clickURL(\''+a[x][1]+'\')'; }
				this.html += '<div id="' + this.divPrefix+this.menuLevels[i][0]+x + '"' + ((x == a.length-1)? ' class="lastItem"' : '') + '><div class="'+this.classPrefix+'Item-1" onmouseover="' + this.objName+'.levelOver('+this.menuLevels[i][0]+((this.menuLevels[i][2] != 0)? '0' : '') + '); ' + ((a[x][3])? this.objName+'.menuOn('+this.menuLevels[i][0]+x+0+'); ' : '') + this.objName+'.toggleColor(this)" onmouseout="' + this.objName+'.levelOut(); ' + ((a[x][3])? this.objName+'.menuOff('+this.menuLevels[i][0]+x+0+'); ' : '') + this.objName+'.toggleColor(this)" onclick="' + onclickValue + '"><div class="text' + ((a[x][2] && a[x][2] == "_blank") ? ' popup' : '') + '">' + a[x][0]+((a[x][3])? '&nbsp;&nbsp;&nbsp;&nbsp;&raquo;' : '') + '</div></div></div>\n';
			}
			//for (var x=1; x<a.length; x++) { this.html += '<div id="' + this.divPrefix+this.menuLevels[i][0]+x + '"' + ((x == a.length-1)? ' class="lastItem"' : '') + '><div class="'+this.classPrefix+'Item-1" onmouseover="' + this.objName+'.levelOver('+this.menuLevels[i][0]+((this.menuLevels[i][2] != 0)? '0' : '') + '); ' + ((a[x][2])? this.objName+'.menuOn('+this.menuLevels[i][0]+x+0+'); ' : '') + this.objName+'.toggleColor(this)" onmouseout="' + this.objName+'.levelOut(); ' + ((a[x][2])? this.objName+'.menuOff('+this.menuLevels[i][0]+x+0+'); ' : '') + this.objName+'.toggleColor(this)" onclick="clickURL(\''+a[x][1]+'\')"><div class="text">' + ((typeof(a[x][0])=="object")? a[x][0][0] : a[x][0]) + ((a[x][2])? '&nbsp;&nbsp;&nbsp;&nbsp;&raquo;' : '') + '</div></div></div>\n'; }
			this.html += '</div></div>\n';
		}
	}
	this.html += '</div>\n';
}
function debug() {
//	document.getElementById("debug").innerHTML = "lastMenuTrack = "+this.lastMenuTrack+"<br>lastInitID = "+this.lastInitID+"<br>lastParentID = "+this.lastParentID+"<br>timerID = "+this.timerID+"<br>isTimer = "+this.isTimer;
}
// -----------------------------
function menuOn(id) {
	id = String(id);
	if (id.indexOf(0) < 0 && this.roll) { eval(this.roll+".Mouse(id,'ovr')"); }
	if (!this.load || is.ns4) { return; }
	this.showMenu(id);
}
function menuOff(id) {
	id = String(id);
	if (id.indexOf(0) < 0 && this.roll) { eval(this.roll+".Mouse(id)"); }
	if (!this.load || is.ns4) { return; }
	this.timeoutMenu();
	if (id.indexOf(0) < 0) { this.lastParentID = ""; }
}
function levelOver(id) {
	this.lastParentID = id;
	this.clearTimeoutMenu();
	this.hideMenu();
	this.debug();
}
function levelOut() {
	this.lastParentID = "";
	this.timeoutMenu();
	this.debug();
}
function showMenu(id) {
	this.clearTimeoutMenu();
	this.hideMenu();
	eval(this.lyrPrefix + id + ".show()");
	if (this.lastMenuTrack[this.lastMenuTrack.length-1] != id) { this.lastMenuTrack[this.lastMenuTrack.length] = id; }
	this.debug();
}
function hideMenu() {
	if (this.lastMenuTrack.length > 0) {
		for (var i=this.lastMenuTrack.length-1; i>=0; i--) {
			if (this.lastMenuTrack[this.lastMenuTrack.length-1] != this.lastParentID) { eval(this.lyrPrefix + this.lastMenuTrack.pop() + ".hide()"); }
			else { break; }
		}
	}
	this.debug();
}
function timeoutMenu() {
	if (this.isTimer) { this.clearTimeoutMenu(); }
	this.isTimer = true;
	this.timerID = setTimeout(this.objName+".hideMenu()",this.delay);
}
function clearTimeoutMenu() {
	clearTimeout(this.timerID);
	this.isTimer = false;
	this.debug();
}
function toggleColor(obj) {
	if (!document.getElementById) { return; }
	if (obj.className == this.classPrefix+"Item-1") { obj.className = this.classPrefix+"Item-1ovr"; }
	else { obj.className = this.classPrefix+"Item-1"; }
	this.debug();
}
function clickURL(src,target) {
	if (!target) { document.location.href = src; }
	else if (target) { window.open(src,"_blank"); }
}
function writeMenu(str,showAlert) {
	document.write(str);
	if (showAlert) alert(str);
}
function stripHTML(str) {
	return str.replace(/<[^>]*>/g," ");
}
function array_pop() {		// JS 1.2 
	var response = this[this.length - 1];
	this.length--;
	return response;
}
if (typeof(Array.prototype.pop) == "undefined") Array.prototype.pop = array_pop;

function array_splice(index,delTotal) {
	var temp = new Array();
	var response = new Array();
	var A_s = 0;
	for (A_s = 0; A_s < index; A_s++) { temp[temp.length] = this[A_s]; }
	for (A_s = 2; A_s < arguments.length; A_s++) { temp[temp.length] = arguments[A_s]; }
	for (A_s = index + delTotal; A_s < this.length; A_s++) { temp[temp.length] = this[A_s]; }
	for (A_s = 0; A_s < delTotal; A_s++) { response[A_s] = this[index + A_s]; }
	this.length = 0;
	for (A_s = 0; A_s < temp.length; A_s++) { this[this.length] = temp[A_s]; }
	return response;
}
if (typeof(Array.prototype.splice) == "undefined") Array.prototype.splice = array_splice;

//window.defaultStatus = "";
