var visible = false;
var hittest = false;
$(document).ready(function(){
  $("#div_body_rect").click(function () {
    if (!hittest){   
      visible = false;
      $("#div_search_categories").fadeOut(300, function(){
        $("#div_search_container").stop().animate({height: '42px'}, 400);
      });
      $('#div_catalogue_button_hover').stop().animate({opacity: '0.0'}, 400);
    }
   // alert("body");
  });
  $("#div_catalogue_button").click(function () {
    if (!visible){
      visible = true;
      $("#div_search_container").stop().animate({height: '450px'}, 400, function(){
        $("#div_search_categories").fadeIn(300);
      
      });
    }else{
      visible = false;
      $("#div_search_categories").fadeOut(300, function(){
        $("#div_search_container").stop().animate({height: '42px'}, 400);
      });
    }
  });
  
  
  $("#input_search").keyup(function (even) {      
    isSearchningString();
  }); 
  
  
  
  $("#div_disable_search").click(function () { 
    //$("#input_search").attr("value", ""); tady   
      $("#input_search").attr("value", "Hledat...");
      $("#input_search").css("color", "#848484");
      $("#input_search").css("font-weight", "normal");     
    isSearchningString();
    geSlidesByTop();
  });   

  $("#div_search_container").hover(
  function () {      
    hittest = true;
  }, 
  function () {
    hittest = false;
  });  

  $("#div_catalogue_button").hover(
  function () {      
    $(this).children('#div_catalogue_button_hover').stop().animate({opacity: '1.0'}, 100);
  }, 
  function () {
    if (!visible){
      $(this).children('#div_catalogue_button_hover').stop().animate({opacity: '0.0'}, 400);
    }
  });

}); 

function isSearchningString(){
  var string = $("#input_search").attr("value");
  if ((string != "") && (string != "Hledat...")){
    $("#div_disable_search").fadeIn(250);
  }else{
    $("#div_disable_search").fadeOut(250);
  }
}                                       
