var concat = function() {
      var args = Array.prototype.slice.call(arguments);
      return args.join("");
}
function writeNav()
{
	if (window.level == undefined)
		window.level = 0;
		
	var  levelstr = "";	
	for (i = 0 ; i < window.level; i++ )	
		levelstr += "../";

	str = concat(
				 '<div id="main_tab" class="dropdown" style="position:absolute; left:191px; top:51px; width:119px; z-index:1; display: none; background-color:#dfdfdf;">',
					  '<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/news.html">News</a></div>',
					  '<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/about.html">About us</a></div>',
					  '<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/links.html">GIS-links</a></div>',
				  '</div>',
				  '<div id="product_tab" class="dropdown" style="position:absolute; left:284px; top:51px; width:199px; z-index:1; display: none; background-color:#dfdfdf;">',
				  	'<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/download.html">Download</a></div>',
				    '<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/new_in_ET.html">New features</a></div>',
					'<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/extensions.html">Extensions</a></div>',
					'<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/upgrade.html">Upgrade for free</a></div>',
					'<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/faq.html">FAQ</a></div>',
					'<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/support.html">Support</a></div>',
				 '</div>',
				 '<div id="buy_tab" class="dropdown" style="position:absolute; left:377px; top:51px; width:133px; z-index:1; display: none; background-color:#dfdfdf;">',
					 '<div class="menu"><a rel="nofollow" href="',levelstr,'../purchase/price.html">Price</a></div>',
					 '<div class="menu"><a rel="nofollow" href="',levelstr,'../purchase/buy_form.html">Order</a></div>',
					 '<div class="menu"><a rel="nofollow" href="',levelstr,'../purchase/reseller_list.html">Resellers</a></div>',
				 '</div>',
				 '<div id="tech_tab" class="dropdown" style="position:absolute; left:658px; top:51px; width:151px; z-index:1; display: none; background-color:#dfdfdf;">',
					 '<div class="menu"><a rel="nofollow" href="',levelstr,'../technology/video_list.html">Video</a></div>',
					 '<div class="menu"><a rel="nofollow" href="',levelstr,'../technology/tech_list.html">Technology</a></div>',
				 '</div>',
				 '<div class="header_body">',
					 '<div class="header_logo"></div>',
					 '<div class="header_text">advanced intelligent software for map vectorizing</div>',
					 '<div class="header_menu">',
						 '<div class="menu_div menu_offset1">',
							 '<a href="',levelstr,'../easytracepro/news.html" id="main_btn" name="main_btn" class="menu_div">Main</a>',
						 '</div>',
						 '<div class="menu_div menu_offset2">',
							 '<a href="',levelstr,'../easytracepro/download.html" id="product_btn" name="product_btn" class="menu_div">Software</a>',
						 '</div>',
						 '<div class="menu_div menu_offset3">',
							 '<a href="',levelstr,'../purchase/price.html" id="buy_btn" name="buy_btn" class="menu_div">Buy</a>',
						 '</div>',
						 '<div class="menu_div menu_offset4">',
							 '<a href="',levelstr,'../service/digitization.html" id="service_btn" name="service_btn" class="menu_div">R2V Service</a>',
						 '</div>',
						 '<div class="menu_div menu_offset5">',
							 '<a href="',levelstr,'../technology/video_list.html" class="menu_div">Video</a>',
						 '</div>',
						 '<div class="menu_div menu_offset6">',
							 '<a href="',levelstr,'../technology/tech_list.html" id="tech_btn" name="tech_btn" class="menu_div">Technology</a>',
						 '</div>',
						 '<div class="menu_div menu_offset7">',
							 '<a href="http://www.easytrace.com/forum" class="menu_div">Forum</a>',
						 '</div>',
					 '</div>',
				 '</div>');	
	
	$("body").prepend(str);
	initNav();
}

function initNav()
{
	var tabs = {main_btn:'main_tab', product_btn:'product_tab', buy_btn:'buy_tab', service_btn:'service_tab', tech_btn:'tech_tab'};
	var states = {main_tab:0, product_tab:0, buy_tab:0, service_tab:0, tech_tab:0};
	
	function checkAndHide(name)
	{
		if (states[name] == 0)
		{
			$("#"+name).hide();
		
		}
	}
	
	function onHover(tab, over)
	{
		if (tab == undefined)
		{return;}
		
		if (over)
		{
			var obj = $('#'+ tab);
			obj.css("z-index", "2");
			$('#'+ tab).slideDown(200, function () {obj.css("z-index", "1"); } );
			states[tab]+=1;
		}
		else
		{
			states[tab]-=1;
			setTimeout(function () { checkAndHide(tab);}, 200 );
		}
	}

	
	$("div.menu_div a").hover( function() { onHover( tabs[$(this).attr('id')], true); }, function() {onHover(tabs[$(this).attr('id')], false);});
	$("div.dropdown").hover( function() { onHover($(this).attr('id'), true); }, function() {onHover($(this).attr('id'), false);});
}