var timeout    = 50;
var closetimer = 0;
var ddmenuitem = 0;


$(document).ready(function(){
  $('#towns_list_id div.towns_list').hover(function(event){$(this).addClass('hover');},function(event){$(this).removeClass('hover');});

  $("a.h_button").click(function(event){
    event.preventDefault();
    $($(this).attr('href')).toggle("fast");
  });
  
  $('#top_menu > ul > li').bind('mouseover', jsddm_open);
  $('#top_menu > ul > li').bind('mouseout',  jsddm_timer);

  $('#inner_menu_path_id > ul > li').bind('mouseover', jsddm_open);
  $('#inner_menu_path_id > ul > li').bind('mouseout',  jsddm_timer);
  
  document.onclick = jsddm_close;
  
  $(".follow a").addClass('select_town_link');
  
  var selectTown=function(e){
      if(!$(this).hasClass('select_town_link')){
          mtop=document.documentElement.clientHeight/2-110;
          mtop=Math.floor(mtop*0.9)+getBodyScrollTop();
          $("#st_frame").css('margin-top',mtop+'px');

          e.preventDefault();
          $("#select_town_fullscreen").toggleClass("hide");
          click_url=$(this).attr('rel');
          $("#st_frame ul li a").each(function(){
              $(this).attr('href',$(this).attr('rel')+click_url);
          });
      }
  }
  
  $('#header a').click(selectTown);
  $('#footer_block a').click(selectTown);
  
  
  $("#close_st_frame").click(function(e){
      e.preventDefault();
      $("#select_town_fullscreen").toggleClass("hide");
  });
  
  $("#select_town_fullscreen").css('height',$("body").outerHeight(true)+'px');
});

function jsddm_open() {
  jsddm_canceltimer();
  jsddm_close();
  ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}
 
function jsddm_close() {
  if (ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}
 
function jsddm_timer() {
  closetimer = window.setTimeout(jsddm_close, timeout);
}
 
function jsddm_canceltimer() {
  if (closetimer) {
    window.clearTimeout(closetimer);
    closetimer = null;
  }
}

function getBodyScrollTop(){
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

