var search_timeout = 0, mCur=0;
function keep_hide() { if (search_timeout == 0) {search_timeout = setTimeout('close_all()', 1000);}}
function keep_show() {if (search_timeout != 0) {clearTimeout(search_timeout); search_timeout = 0;}}

function mousePageXY(e) 
 {
   var x = 0, y = 0;
   if (!e) e = window.event;
   if (e.pageX || e.pageY) {x = e.pageX; y = e.pageY;} else if (e.clientX || e.clientY) {x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft; y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;} 
   return {"x":x, "y":y};
 }
 
function ShowTip(id)
 {
  if (mCur.x && mCur.y!=0 && mCur.x!=0)
   {
   document.getElementById('HelpTip').style.left=mCur.x+12+'px';
   document.getElementById('HelpTip').style.top=mCur.y+10+'px';
    switch(id)
    {
     case (1): document.getElementById('HelpTip').innerHTML="Классический поиск по названию модели или типу товара"; break;
	 case (2): document.getElementById('HelpTip').innerHTML="Быстрый переход к конкретной модели в выбранной рубрике"; break;
	 case (3): document.getElementById('HelpTip').innerHTML="Настройте показ товаров - тип отображения, валюта цены и т.д."; break;
	 case (4): document.getElementById('HelpTip').innerHTML="Список фирм-производителей в алфавитном порядке"; break;
    }
   }
 } 
 
function ShowTip2(id)
 {
  if (mCur.x && mCur.y!=0 && mCur.x!=0)
   {
   document.getElementById('HelpTip2').style.left=mCur.x-205+'px';
   document.getElementById('HelpTip2').style.top=mCur.y+10+'px';
    switch(id)
    {
     case (1): document.getElementById('HelpTip2').innerHTML="Зарегистрируйте свой магазин и разместите Ваши цены"; break;
	 case (2): document.getElementById('HelpTip2').innerHTML="Информация о местах и ценах на размещение рекламы на сайте"; break;
	}
   }
 }  
 
 function ShowSearch(id)
 { var count=3,i;
  close_all(); clearTimeout(search_timeout); search_timeout = 0;
  for (i=1; i<=count; i++) {document.getElementById('m'+i).style.backgroundImage='url(http://www.shoptraffic.com.ua/img/m'+i+'off.gif)'; $('#Search'+i).hide();}
  document.getElementById('m'+id).style.backgroundImage='url(http://www.shoptraffic.com.ua/img/m'+id+'on.gif)';
   $('#Search'+id).slideToggle('fast');
   switch(id)
    {
     case (1): if (document.getElementById('SearchCategoryTable').innerHTML=='') { $.ajax({url: "http://www.shoptraffic.com.ua/scripts/fill_search1.php", cache: false, success: function(html) {document.getElementById('SearchCategoryTable').innerHTML=html;}}); } break;
	 case (2): if (document.getElementById('Search2Category1Table').innerHTML=='') { $.ajax({url: "http://www.shoptraffic.com.ua/scripts/fill_search2.php?what=first", cache: false, success: function(html) {document.getElementById('Search2Category1Table').innerHTML=html;}}); } break;
	 case (3): break;
	}
 }

function close_all()
 {
  $('.menu1').hide('fast');
  $('#HelpTip').hide('slow');
  $('#HelpTip2').hide('slow');
   $('#HelpTip3').hide('slow');
 }
 
function Set_Price()
 {
  if (document.getElementById('is_price').src.indexOf("off.gif")<0) {document.getElementById('is_price').src="http://www.shoptraffic.com.ua/img/off.gif";}
  else {document.getElementById('is_price').src="http://www.shoptraffic.com.ua/img/on.gif";}
  $('#HelpTip3').show();
 } 
 
 function Set_Components()
 {
  var par;
  par="?kol="+document.getElementById('SearchKol').innerHTML;
  if (document.getElementById('SearchCurrency').innerHTML=="гривнах") {par=par+"&currency=hry";} else {par=par+"&currency=usd";}
  if (document.getElementById('SearchFormat').innerHTML=="фото с описанием") {par=par+"&show=normal";} else {par=par+"&show=table";}
  if (document.getElementById('SearchSort').innerHTML=="алфавиту") {par=par+"&sort=product_company ASC,product ASC";}
  if (document.getElementById('SearchSort').innerHTML=="кол-ву отзывов") {par=par+"&sort=resp DESC";}
  if (document.getElementById('SearchSort').innerHTML=="популярности") {par=par+"&sort=rating DESC";}
  if (document.getElementById('SearchSort').innerHTML=="цене") {par=par+"&sort=is_price DESC,usd_min_price ASC";}
  if (document.getElementById('is_price').src.indexOf("off.gif")<0) {par=par+"&is_price=1";} else {par=par+"&is_price=0";}
  $.ajax({url: "http://www.shoptraffic.com.ua/set_components.php"+par, cache: false, success: function(html) {document.location.reload();}});
 } 

function ChangeCat(id,tit)
 {
  document.getElementById('SearchCategory').innerHTML=tit;
  $('#SearchCategoryTable').slideToggle('fast');
  SearchForm.v.value=id;
 }
 
function Change2CatVid(id,tit)
 {
  var i;
  $('.menu1').hide('fast');
  for (i=3; i<6; i++) {$('#Search2Category'+i).hide(); document.getElementById('TD'+Math.round(i-1)).style.width='0px';}
  document.getElementById('Search2Category1').innerHTML=tit;
   document.getElementById('Search2Category2').innerHTML="Выберите категорию";
   $.ajax({url: "http://www.shoptraffic.com.ua/scripts/fill_search2.php?what=vid&id="+id, cache: false, success: function(html) {$('#Search2Category2Table').html(html);  $('#Search2Category2').show('fast'); }});
	document.getElementById('TD2').style.width=document.getElementById('Search2Category2Table').style.width;
 } 
 
 function Change2CatTip(vid,id,tit)
 {
  var i;
  $('.menu1').hide('fast');
  for (i=3; i<6; i++) {$('#Search2Category'+i).hide(); document.getElementById('TD'+Math.round(i-1)).style.width='0px';}
  document.getElementById('Search2Category2').innerHTML=tit;
   document.getElementById('Search2Category3').innerHTML="Выберите категорию";
   $.ajax({url: "http://www.shoptraffic.com.ua/scripts/fill_search2.php?what=tip&vid="+vid+"&id="+id, cache: false, success: function(html) {$('#Search2Category3Table').html(html); $('#Search2Category3').show('fast');}});
	document.getElementById('TD3').style.width=document.getElementById('Search2Category3Table').style.width;
 } 
 
 function Change2CatPodtip(vid,tip,id,tit)
 {
  var i;
  $('.menu1').hide('fast');
  for (i=4; i<6; i++) {$('#Search2Category'+i).hide(); document.getElementById('TD'+Math.round(i-1)).style.width='0px';}
  document.getElementById('Search2Category3').innerHTML=tit;
   document.getElementById('Search2Category4').innerHTML="Выберите фирму";
   $.ajax({url: "http://www.shoptraffic.com.ua/scripts/fill_search2.php?what=podtip&vid="+vid+"&tip="+tip+"&id="+id, cache: false, success: function(html) {$('#Search2Category4Table').html(html); $('#Search2Category4').show('fast');}});
	document.getElementById('TD4').style.width=document.getElementById('Search2Category4Table').style.width;
 }  
 
  function Change2CatTipCompany(vid,id,tit)
 {
  var i;
  $('.menu1').hide('fast');
  for (i=3; i<6; i++) {$('#Search2Category'+i).hide(); document.getElementById('TD'+Math.round(i-1)).style.width='0px';}
  document.getElementById('Search2Category2').innerHTML=tit;
  document.getElementById('Search2Category4').innerHTML="Выберите фирму";
   $.ajax({url: "http://www.shoptraffic.com.ua/scripts/fill_search2.php?what=tip_company&vid="+vid+"&id="+id, cache: false, success: function(html) {$('#Search2Category4Table').html(html); $('#Search2Category4').show('fast');}});
	document.getElementById('TD4').style.width=document.getElementById('Search2Category4Table').style.width;
 } 
 
   function Change2CatCompany(vid,tip,podtip,id,tit)
 {
  var i;
  $('.menu1').hide('fast');
  document.getElementById('Search2Category4').innerHTML=tit;
  $('#Search2Category5').hide();
   document.getElementById('Search2Category5').innerHTML="Выберите модель";
   $.ajax({url: "http://www.shoptraffic.com.ua/scripts/fill_search2.php?what=models&vid="+vid+"&tip="+tip+"&podtip="+podtip+"&id="+id, cache: false, success: function(html) {$('#Search2Category5Table').html(html); $('#Search2Category5').show('fast');}});
	document.getElementById('TD5').style.width=document.getElementById('Search2Category5Table').style.width;
 } 
 
function ChangeCur(id,tit)
 {
  document.getElementById(id).innerHTML=tit;
  $('#'+id+'Table').slideToggle('fast');
  $('#HelpTip3').show();
 } 
 
function TableOpenClose(id)
{
 $("#"+id+"_on").slideToggle("fast");
 $("#"+id+"_off").slideToggle("fast");
 if ($("#"+id).attr('class')=='Left') {$("#"+id).addClass('Left_closed'); $("#"+id).attr('title','Развернуть панель');} else {$("#"+id).removeClass('Left_closed');  $("#"+id).attr('title','Свернуть панель');}
} 

$(document).ready(function(){
 $('.navyboldhref').mousemove(function(e){mCur = mousePageXY(e);});
 $('.navythickhref').mousemove(function(e){mCur = mousePageXY(e);});
 $('.menu1').mouseover(function(){keep_show();})
 $('.menu1').mouseout(function(){keep_hide(); })
  $('.navyboldhref').mouseout(function(e){$('#HelpTip').hide();});
  $('.navyboldhref').mouseover(function(e){$('#HelpTip2').hide(); $('#HelpTip').show();});
   $('.navythickhref').mouseout(function(e){$('#HelpTip2').hide();});
   $('.navythickhref').mouseover(function(e){$('#HelpTip').hide(); $('#HelpTip2').show();});
   
    $("ul.menu li a").mouseover(function() {
     var id=$(this).attr("id");
		$(this).parent().find("ul.subnav").show(); 
		if (document.getElementById(id+'_sub').innerHTML=='')
		 {
		 $.ajax({url: "http://www.shoptraffic.com.ua/scripts/fill_left_rubricator.php?id="+id, cache: false, success: function(html) {document.getElementById(id+'_sub').innerHTML=html;}});
		 }
		$(this).parent().hover(function() {}, function(){$(this).parent().find("ul.subnav").hide();});
		});

$('.subnav').mouseover(function(e){$('#'+$(this).attr('id').replace("_sub","")).addClass('temp');});	
$('.subnav').mouseout(function(e){$('#'+$(this).attr('id').replace("_sub","")).removeClass('temp');});

$('.Left').click(function(e){TableOpenClose($(this).attr('id'));});
$('.search_divs').click(function(e){close_all(); clearTimeout(search_timeout); search_timeout=0; $("#"+$(this).attr('id')+"Table").slideToggle('fast');});

});

