var tmOut;
var ifr;
var menu_width = '180px';

function select_menu_item(menuItem)
{	
	for(var i=1;i<=11;i++)
	// with TV link
	//for(var i=1;i<=10;i++)
	{
		if(i != menuItem)
		{
			if(i != 11)
			{
				document.getElementById(i+"_l").style.background = "url(/images/new1/menu_left.png)";
				document.getElementById(i+"_m").style.background = "url(/images/new1/menu_middle.png)";
				document.getElementById(i+"_r").style.background = "url(/images/new1/menu_right.png)";
			}
			document.getElementById(i+"_1").style.backgroundColor = "#fff";
			document.getElementById(i+"_2").style.backgroundColor = "#fff";
			document.getElementById(i+"_3").style.backgroundColor = "#fff";
			if(document.getElementById("submenu_"+i))
			{
				document.getElementById("submenu_"+i).style.display = "none";
			}
		}
	}

	if(menuItem != 11)
	{
		document.getElementById(menuItem+"_l").style.background = "url(/images/new1/menu_a_left.png)";
		document.getElementById(menuItem+"_m").style.background = "url(/images/new1/menu_a_middle.png)";
		document.getElementById(menuItem+"_r").style.background = "url(/images/new1/menu_a_right.png)";
	}
	
	
	var mainTable = document.getElementById("main_submenu_table");
	
	if(document.getElementById(menuItem+"_m").getAttribute("url"))
	{
		location.href = "/" + document.getElementById(menuItem+"_m").getAttribute("url");
		mainTable.style.height = "1";
	}
	else
	{
		if(menuItem != 11)
		{
			mainTable.setAttribute("height", "47");
		}
		else
		{
			mainTable.setAttribute("height", "1");
		}
	}
	
	if(menuItem == 11)
	{
		document.getElementById(menuItem+"_1").style.backgroundColor = "#B5950E";
		document.getElementById(menuItem+"_2").style.backgroundColor = "#B5950E";
		document.getElementById(menuItem+"_3").style.backgroundColor = "#B5950E";
	}
	else
	{
		document.getElementById(menuItem+"_1").style.backgroundColor = "#021859";
		document.getElementById(menuItem+"_2").style.backgroundColor = "#021859";
		document.getElementById(menuItem+"_3").style.backgroundColor = "#021859";
	}
	
	if(document.getElementById("submenu_"+menuItem))
	{
		document.getElementById("submenu_"+menuItem).style.display = "block";
	}
	
	return;
}

function select_menu_item2(menuItem)
{	
	for(var i=1;i<=10;i++)
	{
		if(i != menuItem)
		{
			if(i <= 3)
			{
				document.getElementById("m"+i).className = "MenuItemBig";
			}
			else
			{
				document.getElementById("m"+i).className = "MenuItem";
			}
			if(document.getElementById("submenu_"+i))
			{
				document.getElementById("submenu_"+i).style.display = "none";
			}
		}
	}

	if(menuItem <= 3)
	{
		document.getElementById("m"+menuItem).className = "MenuItemBigSelected";
	}
	else
	{
		document.getElementById("m"+menuItem).className = "MenuItemSelected";
	}
	
	if(document.getElementById("submenu_"+menuItem))
	{
		document.getElementById("submenu_"+menuItem).style.display = "block";
	}
	
	if(document.getElementById("m"+menuItem).getAttribute("url"))
	{
		location.href = "/" + document.getElementById("m"+menuItem).getAttribute("url");
	}
	
	document.getElementById("tmpSubmenu").style.display = 'none';
	return;
}

function setActiveColor(obj)
{
	obj.style.color = "#ffff00";
	return;
}

function gen_menu(menuID, dat)
{
	clearTimeout(this.tmOut);
	hide_menu();
	if(menuID >= 11 && menuID <= 13 )
	{
		var layer = document.getElementById('menu_layer2');
	}
	else
	{
		var layer = document.getElementById('menu_layer');
	}
	
	if(menuID == 12)
	{
		var posY = findPosY(document.getElementById('menu_links1'))+28;
		var realPosX = findPosX(document.getElementById('menu_login')) - 113;
		layer.style.top = posY+'px';
		layer.style.left = realPosX+'px';
		layer.innerHTML = my_data(dat);
	}
	else if(menuID == 13)
	{
		var posY = findPosY(document.getElementById('menu_links1'))+28;
		var realPosX = findPosX(document.getElementById('menu_links'+menuID));
		layer.style.top = posY+'px';
		layer.style.left = realPosX+'px';
		layer.innerHTML = menu_content2(menuID);
	}
	else if(menuID < 6)
	{
		var posY = findPosY(document.getElementById('menu_links1'))+28;
		var realPosX = findPosX(document.getElementById('menu_links'+menuID));
		layer.style.top = posY+'px';
		layer.style.left = realPosX+'px';
		layer.innerHTML = menu_content(menuID);
	}
	else if(menuID == 11)
	{
		var posY = findPosY(document.getElementById('menu_links1'))+28;
		var realPosX = findPosX(document.getElementById('menu_login')) - 113;
		layer.style.top = posY+'px';
		layer.style.left = realPosX+'px';
		layer.innerHTML = login_content(dat);
	}
	else
	{
		var posY = findPosY(document.getElementById('menu_links1'))+28;
		var realPosX = findPosX(document.getElementById('menu_links'+menuID));
		layer.style.top = posY+'px';
		layer.style.left = realPosX+'px';
		layer.innerHTML = menu_content2(menuID);
	}
	add_iframe(layer);
	layer.style.visibility = 'visible';
	
	return;
}

function add_iframe(layer)
{
	if (!window.createPopup) return;
	if (navigator.userAgent.match(/MSIE ([\d\.]+)/) && parseFloat(RegExp.$1) > 6.5)return;
	
	if(!this.ifr)
	{
		this.ifr = document.createElement('iframe');
		this.ifr.src = 'about:blank';
		with (this.ifr.style)
		{
			position = 'absolute';
			border = 'none';
			filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		}
		layer.parentNode.insertBefore(this.ifr, layer);
	}
	
	with (this.ifr.style)
	{
		left = layer.offsetLeft + 'px';
		top = layer.offsetTop + 'px';
		width = layer.offsetWidth + 'px';
		height = layer.offsetHeight + 'px';
		visibility = 'visible';
		zIndex = 3;
	}

	return;
}

function hide_menu()
{
	var layer = document.getElementById('menu_layer');
	var layer2 = document.getElementById('menu_layer2');
	layer.style.visibility = 'hidden';
	layer2.style.visibility = 'hidden';
	if(this.ifr)this.ifr.style.visibility = 'hidden';
	return;
}

function unsetTmOut()
{
	clearTimeout(this.tmOut);
	return;
}

function setTmOut(tm)
{
	this.tmOut = setTimeout('hide_menu()', tm);
	return;
}

function menu_content(id)
{
	var menu = '';
	menu += '<tr><td style="height: 1px; background-image: url(http://www.sisustus.ee/img/menu_spacer2.gif); background-repeat: repeat-x; width: 17px; height: 1px;"></td><td style="height: 1px; background-image: url(http://www.sisustus.ee/img/menu_spacer.gif); background-repeat: repeat-x; width: 100%; height: 1px;"></td></tr>';
	
	var i = 0;
	for(x in eval('menucat_name_'+id))
	{
		if(id == 1 || id == 2)
		{
			menu += '<tr><td style="background-color: #4AA3DE; width: 17px;" align="center"><table cellpadding="0" cellspacing="0" width="17px"><tr><td align="center" valign="middle"><center><img src="http://www.sisustus.ee/img/menu_pointer.gif" alt="Pointer" style="border: 0px;"></center></td></tr></table></td><td id="menu_back_'+i+'" style="cursor: pointer; color: #fff; padding-top:2px; padding-bottom:2px; padding-left:5px; padding-right:5px;" onmouseover="this.style.background=\'#4AA3DE\';" onmouseout="this.style.background=\'\';" onclick="window.location.href=\'?cmd=products&cid='+eval('menucat_cid_'+id+'[x]')+'&first=1&unset=1\'">'+eval('menucat_name_'+id+'[x]')+'</td></tr><tr><td style="height: 1px; background-image: url(http://www.sisustus.ee/img/menu_spacer2.gif); background-repeat: repeat-x; width: 17px; height: 1px;"></td><td style="height: 1px; background-image: url(http://www.sisustus.ee/img/menu_spacer.gif); background-repeat: repeat-x; width: 100%; height: 1px;"></td></tr>';
		}
		else
		{
			menu += '<tr><td style="background-color: #4AA3DE; width: 17px;" align="center"><table cellpadding="0" cellspacing="0" width="17px"><tr><td align="center" valign="middle"><center><img src="http://www.sisustus.ee/img/menu_pointer.gif" alt="Pointer" style="border: 0px;"></center></td></tr></table></td><td id="menu_back_'+i+'" style="cursor: pointer; color: #fff; padding-top:2px; padding-bottom:2px; padding-left:5px; padding-right:5px;" onmouseover="this.style.background=\'#4AA3DE\';" onmouseout="this.style.background=\'\';" onclick="window.location.href=\'?cmd=products&cid='+eval('menucat_cid_'+id+'[x]')+'&scid='+eval('menucat_scid_'+id+'[x]')+'&unset=1\'">'+eval('menucat_name_'+id+'[x]')+'</td></tr><tr><td style="height: 1px; background-image: url(http://www.sisustus.ee/img/menu_spacer2.gif); background-repeat: repeat-x; width: 17px; height: 1px;"></td><td style="height: 1px; background-image: url(http://www.sisustus.ee/img/menu_spacer.gif); background-repeat: repeat-x; width: 100%; height: 1px;"></td></tr>';
		}
		i++;
	}
	
	return '<table cellpadding="0" cellspacing="0" width="'+this.menu_width+'" style="background-color: #007DD0;">'+menu+'</table>';
}

function login_content(type)
{
	if(type == 1)
	{
		var out = '<form name="login" method="post" action="."><table cellpadding="0" cellspacing="0" width="203px" height="155px" style="padding: 3px; background-color: #007DD0;"><tr><td><table cellspacing="0" cellpadding="0" style="background-image: url(http://www.sisustus.ee/img/login_back.gif);" width="197px" height="149px"><tr><td colspan="2"><table cellpadding="0" cellspacing="0"><td style="height: 24px; width: 98px; color: #fff;" align="center"><b><a href="" style="color: #fff; text-decoration: none;" onclick="dis_log(1);gen_menu(11, 1); return false;">Tavakasutaja</a></b></td><td></td><td style="height: 24px; width: 98px; color: #fff;" align="center"><a href="" style="color: #fff; text-decoration: none;" onclick="dis_log(2);gen_menu(11, 2); return false;"><b>Sisedisainer</b></a></td></tr></table></td></tr><tr><td style="height: 5px;"></td><td></td></tr><tr><td style="color: #fff; font-size: 10px;" align="right">Kasutajanimi:&nbsp;</td><td><input type="text" name="user" style="border: 1px solid #fff; height: 20px; width: 105px; background-color: #1B8BDB; color: #fff; font-size: 12px; font-family: verdana; vertical-align: middle;"></td></tr><tr><td style="height: 3px;"></td></tr><tr><td style="color: #fff; font-size: 10px; text-align: right;">Parool:&nbsp;</td><td><input style="border: 1px solid #fff; height: 20px; width: 105px; background-color: #1B8BDB; color: #fff; font-size: 12px; font-family: verdana; vertical-align: middle;" type="password" name="pass"></td></tr><tr><td style="height: 10px;"></td></tr><tr><td colspan="2" align="right"><input type="image" src="http://www.sisustus.ee/img/log_btn.gif" alt="Login" >&nbsp;</td></tr><tr><td style="height: 5px;"></td></tr><tr><td colspan="2" align="center"><a href="" class="white_link2">Unustasid oma salas&otilde;na?</a></td></tr><tr><td style="height: 5px;"></td></tr></table><input type="hidden" name="do" value="login">1</td></tr></table></form>';
	}
	else if(type == 2)
	{
		var out = '<form name="login" method="post" action="."><table cellpadding="0" cellspacing="0" width="203px" height="155px" style="padding: 3px; background-color: #007DD0;"><tr><td><table cellspacing="0" cellpadding="0" style="background-image: url(http://www.sisustus.ee/img/login_back2.gif);" width="197px" height="149px"><tr><td colspan="2"><table cellpadding="0" cellspacing="0"><td style="height: 24px; width: 98px; color: #fff;" align="center"><b><a href="" style="color: #fff; text-decoration: none;" onclick="dis_log(1);gen_menu(11, 1); return false;">Tavakasutaja</a></b></td><td></td><td style="height: 24px; width: 98px; color: #fff;" align="center"><a href="" style="color: #fff; text-decoration: none;" onclick="dis_log(2);gen_menu(11, 2); return false;"><b>Sisedisainer</b></a></td></tr></table></td></tr><tr><td style="height: 5px;"></td><td></td></tr><tr><td style="color: #fff; font-size: 10px;" align="right">Kasutajanimi:&nbsp;</td><td><input type="text" name="user" style="border: 1px solid #fff; height: 20px; width: 105px; background-color: #000; color: #fff; font-size: 12px; font-family: verdana; vertical-align: middle;"></td></tr><tr><td style="height: 3px;"></td></tr><tr><td style="color: #fff; font-size: 10px; text-align: right;">Parool:&nbsp;</td><td><input style="border: 1px solid #fff; height: 20px; width: 105px; background-color: #000; color: #fff; font-size: 12px; font-family: verdana; vertical-align: middle;" type="password" name="pass"></td></tr><tr><td style="height: 10px;"></td></tr><tr><td colspan="2" align="right"><input type="image" src="http://www.sisustus.ee/img/log_btn2.gif" alt="Login">&nbsp;</td></tr><tr><td style="height: 5px;"></td></tr><tr><td colspan="2" align="center"><a href="" class="white_link2">Unustasid oma salas&otilde;na?</a></td></tr><tr><td style="height: 5px;"></td></tr></table><input type="hidden" name="do" value="login">2</td></tr></table></form>';
	}
	
	return out;
}

function dis_log(type)
{
	x_set_login(type, return_nothing2);
	return;
}

function my_data(dat)
{
	var out = '<table style="width: 203px; background-color: #007DD0;"><tr><td style="color: #fff; font-size: 10px; font-family: verdana;">Oled sisse loginud kui '+dat+'. (Kui sa ei ole '+dat+' siis palun vajuta <a href="?do=logout" style="color: #fff; font-size: 10px; font-family: verdana;">siia</a>)</td></tr><tr><td style="padding-top: 5px; color: #fff; font-size: 10px; font-family: verdana;">Oma andmete muutmiseks kliki <a href="?cmd=join&type=7" style="color: #fff; font-size: 10px; font-family: verdana;">siia</a></td></tr></table>';
	
	return out;
}

function menu_content2(id)
{
	menu_9 = new Array(/*new Array('Taaskasutuskeskuse asjad', '?cmd=reuse'),*/ new Array('K&uuml;si n&otilde;u sisekujundajalt', '?cmd=dis&sec=1'), new Array('Ruumiplaneerija', '?cmd=rp'), new Array('Milline on Sinu v&auml;rv?', '?cmd=cp'), new Array('Milline on Sinu stiil?', '?cmd=style&page=1'), new Array('M&uuml;&uuml; kasutatud sisustust', '?cmd=ad'), new Array('Kujundushoroskoop', '?cmd=hor&sec=1'), new Array('Kunstniku t&ouml;&ouml;tuba', '?cmd=art&section=4'));
	menu_9.sort();
	menu_8 = new Array(new Array('Pealeht???', '?cmd=front&sec=2'));
	menu_8.sort();
	menu_10 = new Array(new Array('J&auml;ta enda tagasiside', '?cmd=gettouch'), new Array('Kasutajad r&auml;&auml;givad', '?cmd=showtext&id=18'), new Array('Unustasid oma parooli', '?cmd=join&type=4'), new Array('KKK', '?cmd=kkk'), new Array('Liitu kunstnikuks', 'http://www.sisustus.ee/kunstnikud/'), new Array('Liitu ettev&otilde;tjana', 'http://tulu.sisustus.ee/'), new Array('Mis on Sisustus.ee?', '?cmd=faq'), new Array('Privaatsus', '?cmd=privacy'));
	menu_10.sort();
	menu_7 = new Array(new Array('Artiklid', '?cmd=articles'), new Array('Foorum', '?cmd=forum'), /*new Array('Kunst', '?cmd=art'),*/ new Array('Inspireerivad interj&ouml;&ouml;rid', '?cmd=igal&sec=1')/*, new Array('Sisustusblog', '?cmd=blog')*/);
	menu_7.sort();
	menu_13 = new Array(new Array('Tavakasutaja', '?cmd=join&type=1'), new Array('Sisedisainer', '?cmd=join&type=2'));
	menu_13.sort();
	var menu = '';
	menu += '<tr><td style="height: 1px; background-image: url(http://www.sisustus.ee/img/menu_spacer2.gif); background-repeat: repeat-x; width: 17px; height: 1px;"></td><td style="height: 1px; background-image: url(http://www.sisustus.ee/img/menu_spacer.gif); background-repeat: repeat-x; width: 100%; height: 1px;"></td></tr>';

	for(x in eval('menu_'+id))
	{
		if(id ==  10 && x >= 4 && x <= 5)
		{
			var target = 'target="_new"';
		}
		else
		{
			var target = 'target="_self"';
		}
		
		menu += '<tr><td style="background-color: #4AA3DE; width: 17px;" align="center"><table cellpadding="0" cellspacing="0" width="17px"><tr><td align="center" valign="middle"><center><img src="http://www.sisustus.ee/img/menu_pointer.gif" alt="Pointer" style="border: 0px;"></center></td></tr></table></td><td style="color: #fff; padding-top:2px; padding-bottom:2px; padding-left:5px; padding-right:5px;" onmouseover="this.style.background=\'#4AA3DE\';" onmouseout="this.style.background=\'\';"><a style="text-decoration: none; color: #fff; display: block;" href="'+eval('menu_'+id+'['+x+'][1]')+'" '+target+'>'+eval('menu_'+id+'['+x+'][0]')+'</a></td></tr><tr><td style="height: 1px; background-image: url(http://www.sisustus.ee/img/menu_spacer2.gif); background-repeat: repeat-x; width: 17px; height: 1px;"></td><td style="height: 1px; background-image: url(http://www.sisustus.ee/img/menu_spacer.gif); background-repeat: repeat-x; width: 100%; height: 1px;"></td></tr>';
	}
	
	if(id == 13)
	{
		this.menu_width = '162px';
	}

	var html = '<table cellpadding="0" cellspacing="0" width="'+this.menu_width+'" style="background-color: #007DD0;">'+menu+'</table>';
	
	this.menu_width = '180px';
	
	return html;
}

