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,'../news/news.html">Новости сайта</a></div>',
					  '<div class="menu"><a rel="nofollow" href="',levelstr,'../news/about.html">О компании</a></div>',
					  '<div class="menu"><a rel="nofollow" href="',levelstr,'../news/contacts.html">Контакты</a></div>',
					  '<div class="menu"><a rel="nofollow" href="',levelstr,'../news/conference.html">Конференции</a></div>',
					  '<div class="menu"><a rel="nofollow" href="',levelstr,'../news/links.html">ГИС-ссылки</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">Скачать</a></div>',
				    '<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/new_in_ET.html">Новые возможности</a></div>',
					'<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/extensions.html">Дополнения</a></div>',
					'<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/et799.html">Бесплатная версия ET 7.99</a></div>',
					'<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/87vs79.html">Преимущества ET 8.7</a></div>',
					'<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/upgrade.html">Доступный мне upgrade</a></div>',
					'<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/faq.html">Вопросы и ответы</a></div>',
					'<div class="menu"><a rel="nofollow" href="',levelstr,'../easytracepro/support.html">Техническая поддержка</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">Цены</a></div>',
					 '<div class="menu"><a rel="nofollow" href="',levelstr,'../purchase/buy_form.html">Оформить заказ</a></div>',
					 '<div class="menu"><a rel="nofollow" href="',levelstr,'../purchase/reseller_list.html">Список дилеров</a></div>',
				 '</div>',
				 '<div id="service_tab" class="dropdown" style="position:absolute; left:471px; top:51px; width:151px; z-index:1; display: none; background-color:#dfdfdf;">',
					 '<div class="menu"><a rel="nofollow" href="',levelstr,'../service/digitization.html">Оцифровка карт</a></div>',
					 '<div class="menu"><a rel="nofollow" href="',levelstr,'../service/study.html">Обучение</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">Видео-материалы</a></div>',
					 '<div class="menu"><a rel="nofollow" href="',levelstr,'../technology/tech_list.html">Технологии</a></div>',
					 '<div class="menu"><a rel="nofollow" href="',levelstr,'../technology/articles.html">Статьи</a></div>',
					 '<div class="menu"><a rel="nofollow" href=',levelstr,'"../technology/curiosity.html">Курьезы</a></div>',
				 '</div>',
				 '<div class="header_body">',
					 '<div class="header_logo"></div>',
					 '<div class="header_text">интеллектуальное програмное обеспечение для векторизации карт </div>',
					 '<div class="header_menu">',
						 '<div class="menu_div menu_offset1">',
							 '<a href="',levelstr,'../news/news.html" id="main_btn" name="main_btn" class="menu_div">На главную</a>',
						 '</div>',
						 '<div class="menu_div menu_offset2">',
							 '<a href="',levelstr,'../easytracepro/download.html" id="product_btn" name="product_btn" class="menu_div">Наш продукт</a>',
						 '</div>',
						 '<div class="menu_div menu_offset3">',
							 '<a href="',levelstr,'../purchase/price.html" id="buy_btn" name="buy_btn" class="menu_div">Как купить?</a>',
						 '</div>',
						 '<div class="menu_div menu_offset4">',
							 '<a href="',levelstr,'../service/service.html" id="service_btn" name="service_btn" class="menu_div">Услуги</a>',
						 '</div>',
						 '<div class="menu_div menu_offset5">',
							 '<a href="',levelstr,'../technology/video_list.html" class="menu_div">Видео</a>',
						 '</div>',
						 '<div class="menu_div menu_offset6">',
							 '<a href="',levelstr,'../technology/tech_list.html" id="tech_btn" name="tech_btn" class="menu_div">Технологии</a>',
						 '</div>',
						 '<div class="menu_div menu_offset7">',
							 '<a href="http://www.easytrace.com/forum" class="menu_div">Форум</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);});
}