// Variables
var overColor     = '#F6F6F6'
var outColor      = '#E8E8E8';
var path = "/pics/"
// border space
var borderSpace   = 2;
// Max text length before warp
var maxTextLength = 21;
// the height for the cells
var cellHeight1   = 21;
var cellHeight2   = 31;
var menuHeight    = 90;
var cellWidth     = 143;
var topCellWidth  = 122
// Menu start
var menuStartLeft = 157;
var menuStartTop  = 178;
var menuNumber    = 0;
var menuHidden    = new Array();
var menuLevel     = new Array();
 
var counter		= 0;
// menu indicator for showing submenus
var menuIndicator = "<img src=\"" + path + "arrow.gif\" width=\"8\" height=\"8\">";
// Start with vertical menu
var isVertical = false;
var menuTimer = 0;
// Finding the browsere info
var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
function getRef(id) {
	if (isDOM) return document.getElementById(id);
	if (isIE4) return document.all[id];
	if (isNS4) return document.layers[id];
}
// getting the style id object
function getStyle(id) {
	return (isNS4 ? getRef(id) : getRef(id).style);
}
function wordCount(str)
{
	var strArray = new Array;
	strArray = str.split(" ")
	return strArray.length
}
function popOver(menuID, color, parentID, subMenu, parentIDs) {
	clearTimeout(menuTimer);
	var menuIDStr = "menu" + menuID;
	var menuStyle = getStyle(menuIDStr);
	if (isNS4)
		menuStyle.bgColor = color;
	else
		menuStyle.backgroundColor = color;
	parentIDs = parentIDs + "*" + menuID + "*" 
	menu0.showMenu(parentIDs);
}
function popOut(menuID, color, parentID, subMenu, parentIDs) {
	var menuIDStr = "menu" + menuID;
	var menuStyle = getStyle(menuIDStr);
	if (isNS4)
		menuStyle.bgColor = color;
	else
		menuStyle.backgroundColor = color;
	menuTimer = setTimeout('hideMenus()', 500);
}
function showMenu(parentIDs) {
	for(i=1; i < menuLevel.length; i++) {
		var subMenuID = "menu" + i;
		var subMenuStyle = getStyle(subMenuID);
		var key1 = "*" + menuLevel[i] + "*";
		if(parentIDs.indexOf(key1) != -1) {
			subMenuStyle.visibility = "visible";
		} else {
			subMenuStyle.visibility = "hidden";
		}
	}
}
function hideMenu(menuID) {
	for(i=0; i< menuLevel.length; i++) {
		if(menuLevel[i] == menuID) {
			var subMenuID = "menu" + i;
			var subMenuStyle = getStyle(subMenuID);
			subMenuStyle.visibility = "hidden";
		}
	}
}
function hideMenus() {
	for(i=0; i < menuHidden.length; i++) {
		var subMenuStyle = getStyle(menuHidden[i]);
		subMenuStyle.visibility = "hidden";
	}
}
var popOldWidth = window.innerWidth;
nsResizeHandler = new Function('if (popOldWidth != window.innerWidth) location.reload()');
if (isNS4) document.captureEvents(Event.CLICK);
	document.onclick = clickHandle;
function clickHandle(evt)
{
 	if (isNS4) document.routeEvent(evt);
	hideMenus();
}
function Menu(text, href, target, width, height, spacing, outColor, overColor, borderClass, textClass) {
	this.text = text;
	this.href = href;
	this.target = target;
	this.width = width;
	this.height = height;
	this.spacing = spacing;
	this.outColor = outColor;
	this.overColor = overColor;
	this.borderClass = borderClass;
	this.textClass = textClass;
	this.ref = null;
	this.id = menuNumber++;
	this.parent = false;
	this.parentID = 0;
	this.isVertical = isVertical;
	this.subMenu = new Array;
	this.printMenu = printMenu;
	this.showMenu  = showMenu;
	this.hideMenu  = hideMenu;
}
function addMenu(menu, newSubMenu) {
	menu.subMenu[menu.subMenu.length]=newSubMenu;
}
function printMenu(level,cellNumber,vertical,parentMenuLeft,parentMenuTop,parentID, parentIDs)
{
	// Stop if the browser is not supported
	if (!isDOM && !isIE4 && !isNS4) return;
	var i;
	var menuID = "menu" + this.id;
	var str = "";
	
	
	this.parentID = parentID;
	if(parentID != 0)
	{
		menuHidden[counter++] = menuID;
	}
	menuLevel[this.id] = parentID;
	if(this.subMenu.length!=0)
		this.parent = true;
	if(level != 0)
	{
		if (isDOM || isIE4) {
			str += "<div id=\"" + menuID + "\" style=\"position: absolute; left: " + parentMenuLeft + "; top: " + parentMenuTop + "; width: " + (this.width+borderSpace) + "; height: " + (this.height) + "; visibility: " + (level==1? "visible" : "hidden" )  + "; z-index: " + (level + 1) + "; ";
			if (this.outColor) str += 'background: ' + this.outColor + '; ';
			str += "\" ";
		}
		if (isNS4) {
			str += "<layer id=\"" + menuID + "\" left=\"" + parentMenuLeft  + "\" top=\"" + parentMenuTop + "\" width=\"" +  (this.width) + "\" height=\"" + (this.height) + "\" visibility=\"" + (level==1? "visible" : "hidden" )  + "\" ";
			if (this.outColor) str += "bgcolor=\"" + this.outColor + "\" ";
		}
		if (this.borderClass != '')
		str += "class=\"" + this.borderClass + "\" ";
		// Add mouseover handlers
		str += "onMouseOver=\"popOver(" + this.id + ", '" + this.overColor + "', " + this.parentID + ", " + (this.parent? "1" : "0") + ",'" + parentIDs + "')\" onMouseOut=\"popOut(" + this.id + ",'" + this.outColor + "', " + this.parentID + ", " + (this.parent? "1" : "0") + ",'" + parentIDs + "')\">";
		if(level == 1)
		{
			if(cellNumber == 0)
				str += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"1\"><img src=\"" + path + "blank.gif\" width=\"5\" height=\"13\"></td><td width=\"" + (this.width-1) + "\" height=\"" + (this.height-borderSpace) + "\" align=\"left\"><a class=\"" + this.textClass + "\" href=\"" + this.href + "\"" + (this.target ? " target=\"" + this.target + "\">" : ">") + this.text + "</a></td>";
			else
				str += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"1\" valign=\"middle\"></td><td width=\"" + (this.width-1) + "\" height=\"" + (this.height-borderSpace) + "\" align=\"left\"><img src=\"" + path + "blank.gif\" width=\"3\" height=\"13\"><a class=\"" + this.textClass + "\" href=\"" + this.href + "\"" + (this.target ? " target=\"" + this.target + "\">" : ">") + this.text + "</a></td>";
		}
		else
		{
			if (isDOM || isIE4)
				str += "<table width=\"" + this.width + "\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><td align=\"left\" valign=\"top\"><tr><td width=\"6\"><img src=\"" + path + "blank.gif\" width=\"6\" height=\"" + (this.height-borderSpace) + "\"></td><td><a class=\"" + this.textClass + "\" href=\"" + this.href + "\"" + (this.target ? " target=\"" + this.target + "\">" : ">") + this.text + "</a></td>";
			if (isNS4) 
				str += "<table width=\"" + (this.width-4-borderSpace) + "\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"left\" valign=\"top\" class=\"tableTransparent\"><tr><td align=\"left\" valign=\"middle\"><img src=\"" + path + "blank.gif\" width=\"6\" height=\"" + (this.height-7-borderSpace) + "\"><a class=\"" + this.textClass + "\" href=\"" + this.href + "\"" + (this.target ? " target=\"" + this.target + "\">" : ">") + this.text + "</a></td>";
		}
		// Add a arrow indicator for the menus that have a submenu
		if(this.subMenu.length != 0 && level != 1){
			str += "<td align=\"right\" valign=\"bottom\" width=\"8\">" + menuIndicator + "</td>";
		}
		str += "</tr></table>" + (isNS4 ? "</layer>" : "</div>");
	}
	//Draw the menu
	document.writeln(str)
	// If there is any submenus
	if(this.subMenu.length != 0)
	{
		level++;
		parentID = this.id;
		if(this.id != 0)
			parentIDs =  parentIDs + parentID + "*";
		if(level == 1)
			vertical = false;
   		else
			vertical = true;
		if(level==2)
		{
			parentMenuTop += this.height;
		}
		if(level>2)
		{
			parentMenuLeft += this.width+borderSpace;
		}
		//Draw the submenus
		var subMenuID = "subMenu" + this.id;
		var menuLeft =  parentMenuLeft;
		var menuTop = parentMenuTop;
		for(i=0; i < this.subMenu.length; i++)
		{
			this.subMenu[i].printMenu(level,i,vertical,menuLeft,menuTop,parentID,parentIDs);
			// Calculate the next items start
			if (vertical)
				menuTop += this.subMenu[i].height;
			else
				menuLeft += (this.subMenu[i].width + this.spacing + borderSpace);
		}
	}
}
function initializeMenus(menu)
{
	
	menu.printMenu(0,0,isVertical,menuStartLeft,menuStartTop,0,"*0*");
	hideMenus();
}
function addMenuItem(menuText, menuLink, menuTarget, level)
{
	var levelNumber = (level*1) - 1;
	var menuHeight = cellHeight1;
	//if text length is longer than the max length then make cell height bigger 
	if(menuText.length > maxTextLength && wordCount(menuText) >2) {
		menuHeight = cellHeight2;
		var indexBlank = menuText.lastIndexOf(" ");
		menuText = menuText.substring(0,indexBlank) + "<br>" + menuText.substring(indexBlank);
	}
	if(levelNumber >= 1)
	{
		if(levelNumber == 1)
		{
			menu1 = new Menu(menuText,menuLink,menuTarget,  topCellWidth, cellHeight1, 1, "#FFFFFF", "#FFFFFF", "", "tm_text");
			addMenu(menu0, menu1);
		}
		else
		{
			tempStr = "menu" + levelNumber + " = new Menu(\"" + menuText + "\", \"" + menuLink + "\", \"" + menuTarget + "\", cellWidth, " + menuHeight + ", 0, outColor, overColor, \"tm_border\", \"tm_text\");"
			
			eval(tempStr)
			tempStr = "addMenu(menu" + (levelNumber-1) + ", menu" + levelNumber + ");";
			eval(tempStr)
		}
	}	
}
// Building the menu
menu0 = new Menu("", "#", "", 0, 0, 0, "", "", "", "");
addMenuItem("O nás","#","",2);
addMenuItem("Profil spoločnosti","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/0CFBF0FC925834C3C1256DFA00575078?OpenDocument&lang=UK","",3);
addMenuItem("Skupina Icopal","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/ABFD5286F1B8B96CC125700100594FC9?OpenDocument&lang=UK","",3);
addMenuItem("Poslanie","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/2CC9C753970E9E38C1256E5A00298197?OpenDocument&lang=UK","",3);
addMenuItem("Partnerstvo","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/E5FDD9AFA66D3352C1256E5A00771773?OpenDocument&lang=UK","",3);
addMenuItem("Novinky","#","",2);
addMenuItem("Icopal EXPRESS","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/990EFD3AEF0758DFC12571760061EADD?OpenDocument&lang=UK","",3);
addMenuItem("Hliníkové vetráky Diamond","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/99EA7F0298AEC627C125717C00404C04?OpenDocument&lang=UK","",3);
addMenuItem("SBS modifikované asfaltované pásy ELASTOBIT","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/009A9E75181D58E0C1257142005E0D15?OpenDocument&lang=UK","",3);
addMenuItem("Produkty","#","",2);
addMenuItem("Asfaltované pásy","#","",3);
addMenuItem("Klasické pásy","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/82F4CE67A5C3DF64C1256E5F007449D6?OpenDocument&lang=UK","",4);
addMenuItem("Modifikované pásy","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/6B9C48461EFB9FA2C1256E5F007B92B1?OpenDocument&lang=UK","",4);
addMenuItem("Samolepiace fólie","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/11962A342577D2C2C1256E600049331B?OpenDocument&lang=UK","",4);
addMenuItem("Asfaltové šindle","#","",3);
addMenuItem("JCP Šindle","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/27B5D607E0260237C1256E600048888C?OpenDocument&lang=UK","",4);
addMenuItem("Plano Šindle ","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/5F043A7355F2B79EC1256E6000490F39?OpenDocument&lang=UK","",4);
addMenuItem("Hliníkové vetráky Diamond","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/988EAB87F8318A02C125717C003B7DCA?OpenDocument&lang=UK","",4);
addMenuItem("Tekuté asfaltové hmoty","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/F52259EDF30E7EA0C1256EB9006051F7?OpenDocument&lang=UK","",3);
addMenuItem("Podstrešné fólie","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/DEA5538A5994D733C1256E600049866B?OpenDocument&lang=UK","",3);
addMenuItem("Parozábrany","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/AE6B62901F76E426C1256E64008114CA?OpenDocument&lang=UK","",3);
addMenuItem("Strešný systém DECRA","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/FC8EDA24A78A7BC7C1257001002F3A20?OpenDocument&lang=UK","",3);
addMenuItem("Nopové fólie","#","",3);
addMenuItem("Universal","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/82AF2E5AEB344645C1256E6500059B11?OpenDocument&lang=UK","",4);
addMenuItem("Icopal Drain","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/03E0EA8CB2EDA2D3C125717C004170B8?OpenDocument&lang=UK","",4);
addMenuItem("Strieška Fastlock ","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/6512AC5DFEDCA633C1256FFE006A5B49?OpenDocument&lang=UK","",3);
addMenuItem("Na stiahnutie","#","",2);
addMenuItem("Certifikáty - Vyhlásenia zhody","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/frmShowAttachments?openForm&query=ECDD8663370AE33AC125700100664E21&lang=UK","",3);
addMenuItem("Aplikačné návody","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/frmShowAttachments?openForm&query=A6122384C956C8F0C12570210051F11E&lang=UK","",3);
addMenuItem("Technologické návody","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/frmShowAttachments?openForm&query=74E0BD8B9A9647F0C12570210067D5F4&lang=UK","",3);
addMenuItem("Hydroizolačné systémy","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/frmShowAttachments?openForm&query=0A47420CAFE1CE8BC12571A4002836A0&lang=UK","",3);
addMenuItem("Icopal News","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/frmShowAttachments?openForm&query=B2A910C1AEA5CD82C1256FFD0058C3D8&lang=UK","",3);
addMenuItem("Brožúry","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/frmShowAttachments?openForm&query=CFE7071443962DFBC1256FFE005DF7BC&lang=UK","",3);
addMenuItem("Kontakty","#","",2);
addMenuItem("Kontakty","http://www.icopal.sk/Icopal_sk/Icopal_SK.nsf/0/FACB02FBC831CDD3C12570CF00451FB2?OpenDocument&lang=UK","",3);

function initializeMenu()
{
	initializeMenus(menu0)
}

