$(document).ready(function(){
  // подсветка блоков в тарифах и ревью
  switch(document.location.hash)
  {
    case('#3d'):
    case('#digit'):
    case('#35mm'):
      $(document.location.hash).css({'background':'#F7F4F4','padding':'0 10px 10px', 'margin-top': '10px','border':'1px solid #EEE8E8'}).show();
      break;
    case('#review'):
    		  $(document.location.hash+'content').css({'background':'#F7F4F4','padding':'0 10px 10px', 'margin-top': '10px','border':'1px solid #EEE8E8'}).show();
        $('#review').attr('title','Свернуть');
        $('#reviewarr').html('&uarr;');
    break;	
    case('#honors'):
          $(document.location.hash+'content').css({'background':'#F7F4F4','padding':'0 10px 10px', 'margin-top': '10px','border':'1px solid #EEE8E8'}).show();
        $('#honors').attr('title','Свернуть');
        $('#honorsarr').html('&uarr;');
    break;  
    case('#soundtrack'):
          $(document.location.hash+'content').css({'background':'#F7F4F4','padding':'0 10px 10px', 'margin-top': '10px','border':'1px solid #EEE8E8'}).show();
        $('#soundtrack').attr('title','Свернуть');
        $('#soundtrackarr').html('&uarr;');
    break;    
  }
  // тултип для телефонов в шапке
  $('#tr1 .phoneinfo').tooltip({delay: 0});
  
  // рецензия, награды, саундтрек
  $('#review, #honors, #soundtrack').click(function(){
    var _blockid = $(this).attr('id');
    if($('#'+_blockid+'content').css('display')=='block')
    {
      $(this).attr('title','Развернуть');
      $('#'+_blockid+'arr').html('&darr;'); 
    }
    else
    {
      $(this).attr('title','Свернуть');
      $('#'+_blockid+'arr').html('&uarr;');
    }
    $('#'+_blockid+'content').slideToggle();
  })
  
  if($("#sfilm").length)
  {

   $("#sfilm").sexyCombo({autoFill: true, emptyText: 'Поиск по названию', hideListCallback: function(){
     if(this.input.val()!='')
       for($i=1; $i<this.options.length; $i++)
       {
          if(this.options[$i].text==this.input.val())
          {
            $("#archiveform").trigger('submit');
          }
       } 
     //alert(this.input.val()!='');//$("#archiveform").trigger('submit');     
   }});
  
    $("#archiveform").submit(function(){
      if($("#sfilm").val()!='')
      {
         window.location.href='/afisha/archive/'+$("#sfilm").val()+'/';
         return false;
      }      
    });
    
    /*$("#sfilm").change(function(){
     if($(this).val()!='') window.location.href='/afisha/archive/'+$(this).val()+'/';      
    });*/
  }
  
  
  /**
  * я иду
  */
  $(".film_go").click(function(){
    $_this = $(this);
    if($_this.hasClass('inactive')) return false;
    $.get("/tools/ajaxtonnel.php", {"act":"film_go", "film":$(this).attr('filmid')}, function(data){
       if(data.ok)
       {
         $_this.attr('src','/fo/images/icons/go_inactive.png')
           .attr('title','Вы пойдете на этот фильм')
           .attr('alt','Вы пойдете на этот фильм')
           .addClass('inactive');
         $("#film_go_" + $_this.attr('filmid')).html(data.ok);
       }
    }, 'json');
  });
  
  /**
  * рейтинги
  */
  $('.rating').each(function(){
    $(this).find(".star").rating();
  $(this).show(); 
  });
 
});