$().ready(function(){
  $(".tpmi").live("mouseover", function(){
    $src = $(this).attr("src");
    $new_src = $src.replace(".png", "_a.png");
    $(this).attr("src", $new_src);    
    $(this).addClass("tpmi-a").removeClass("tpmi");
  });
  
  $(".tpmi-a").live("mouseout", function(){
    $src = $(this).attr("src");
    $new_src = $src.replace("_a.png", ".png");
    $(this).attr("src", $new_src);    
    $(this).addClass("tpmi").removeClass("tpmi-a");
  }); 

  $(".tsbm").live("mouseover", function(){
    $src = $(this).attr("src");
    $new_src = $src.replace(".png", "_a.png");
    $(this).attr("src", $new_src);    
    $(this).addClass("tsbm-a").removeClass("tsbm");
  });
  
  $(".tsbm-a").live("mouseout", function(){
    $src = $(this).attr("src");
    $new_src = $src.replace("_a.png", ".png");
    $(this).attr("src", $new_src);    
    $(this).addClass("tsbm").removeClass("tsbm-a");
  });
  

  
 //топ меню
  var $timeOut;
  var $timeOutMenu;
  var $this_id = 0;
  
  
  if($current_menuId>=0){//Если находимся внутри раздела, то подсвечиваем текущее меню и подменю
      $("#top_menu_"+$current_menuId+"").attr("class", "top-menu-item-a");
      if(document.getElementById("top_submenu_"+$current_menuId+"")){
        $current_submenu = $("#top_submenu_"+$current_menuId+"").html().toLowerCase();
        if($current_submenu != "<div style=\"padding-left: 470px;\"><a></a><div class=\"clear\"></div></div>"){
          $('.top-submenu-in').html($current_submenu).show();
        }
      }
  }
  
  
  $(".top-menu-item, .top-menu-item-a").mouseover(function(){
    //Покажем подменю
    if($timeOut){
      clearTimeout($timeOut);
    }
    $this_id = $(this).attr("id").substr(9);
    $this_submenu = $("#top_submenu_"+$this_id+"").html().toLowerCase();
    if($this_submenu != "<a></a>"){
      $(".top-submenu-in").show().html($this_submenu);
    }else{
      $(".top-submenu-in").html("");
    }
  });
  
  $(".top-menu-item, .top-menu-item-a").mouseout(function(){
      $current_submenu = $("#top_submenu_"+$current_menuId+"").html().toLowerCase();
      if($current_submenu != "<a></a>"){
        $timeOut = setTimeout("$('.top-submenu-in').html($current_submenu)", 200);
      }else{
        $timeOut = setTimeout("$('.top-submenu-in').html('<a></a>').hide()", 200);
      }
  });  
  
  $(".top-submenu-in").mouseover(function(){
    //alert($this_id)

    $("#top_menu_"+$this_id+"").attr("class", "top-menu-item-a");
    clearTimeout($timeOut);
    clearTimeout($timeOutMenu);
    
  });
  
  $(".top-submenu-in").mouseout(function(){
    //alert($current_menuId)
      $current_submenu = $("#top_submenu_"+$current_menuId+"").html().toLowerCase();
      if($current_submenu != "<a></a>"){
        $timeOut = setTimeout("$('.top-submenu-in').html($current_submenu)", 200);
      }else{
        $timeOut = setTimeout("$('.top-submenu-in').html('<a></a>').hide()", 200);
      }
    
    $timeOutMenu = setTimeout(function(){$this_id = $current_menuId}, 210); 
      
    if($this_id!=$current_menuId){
      $('#top_menu_'+$this_id+'').attr('class', 'top-menu-item');
    }
  });
  
})
