function popup() {
  $(".popup").show();
  $("body").append("<div class='layer'></div>")  
};


$(document).ready(function(){
  //POPUP
  $(".closePopup").click(function(){
    $(".popup").hide();
    $(".layer").remove();
    
    return false;
  });
  $(".forgottenPassLink").click(function(){
    popup();
    
    return false;
  });

  
  //COMMENTS
  $(".comments .subTitle a").click(function(){
    if ($(this).hasClass("click")) {
      $(this).removeClass("click");
      
      $(".comments .container").slideDown();
      $(".comments .subTitle a").html("Hozzászólások elrejtése");
    }
    
    else {
      $(this).addClass("click");
      
      $(".comments .container").slideUp();
      $(".comments .subTitle a").html("Hozzászólások mutatása");
    }
    
    return false;
  });
  
  
  //FANCYBOX
  $(".gallery a").fancybox({
    'titleShow' : true,
    'transitionIn' : 'elastic',
    'transitionOut' : 'elastic',
    'easingIn' : 'easeOutBack',
    'easingOut' : 'easeInBack',
    'titlePosition' : 'over' 
  });  
  $("a.fancybox").fancybox({
    'titleShow' : true,
    'transitionIn' : 'elastic',
    'transitionOut' : 'elastic',
    'easingIn' : 'easeOutBack',
    'easingOut' : 'easeInBack',
    'titlePosition' : 'over' 
  }).hover(function() {
    $(this).click();
  });
  
    
  //LOGIN
  $(".loginBoxOpen").hide();
  $(".loginBox a:eq(0)").click(function(){ $(".loginBoxOpen").show(); });
  $(".loginBoxOpen .closeLogin").click(function(){ $(".loginBoxOpen").hide(); });
  
  
  //SEARCHBOX
  $(".searchBox input").focus(function(){
    $(".searchBox input").css("background" , "url(images/searchBoxFocus.gif)");
    $(".searchBox input:eq(1)").css("background-position" , "-173px 0");
  });
  $(".searchBox input").blur(function(){
    $(".searchBox input").css("background" , "url(images/searchBox.gif)");
    $(".searchBox input:eq(1)").css("background-position" , "-173px 0");
  });
    
  
  //CUSTOM FORMOK
  $(".languageSelect select, .cartRightBox select").selectbox();  
  $(".form .checkbox input").uniform();  
  
  
  //LEFT MENU
  $(".leftSideBoxRepeat ul ul").each(function(){
    if(!$(this).prev("h4").hasClass("open")) {$(this).hide();}
  });

  $(".leftSideBoxRepeat ul h4").click(function(){
    if ($(this).is(":last-child")) {return true;}

    else {
      if ($(this).hasClass(".open")) {
        $(this).next("ul").slideUp();
        $(this).removeClass("open");        
      }

      else {
        $(this).next("ul").slideDown();
        $(this).addClass("open");
      }
      
      return false;      
    }
  });
  
  
  //INPUT FOCUS 
  $(".inputFocus span").css('display' , 'block');
  function checknextInput(t, event) {
    nextParent = t.parents("div:eq(0)").next("div");
    nextInput = nextParent.find("input");
    nextSpan = nextParent.find("span");
  
    if (  nextInput.attr("type") == "password" && 
          nextInput.val() == "" && 
          event == "focus") { 
            nextSpan.hide(); 
          }
    if (  nextInput.attr("type") == "password" && 
          nextInput.val() == "" && 
          event == "blur") { 
            nextSpan.show();
          }
  }
  function thisspanHide(t) { t.next("span").hide(); }
  
  
  $(".inputFocus").click(function(){
    $(this).find("span").hide().prev("input").focus();
    $(this).find("textarea").focus();
    checknextInput($(this), "focus");    
    
    return false;    
  });
  $(".inputFocus input").focus(function(){ thisspanHide($(this)); });  
  $(".inputFocus input, .inputFocus textarea").blur(function(){
    checknextInput($(this), "blur");
    
    if ($(this).val() == "") {
      $(this).next("span").show();
    }
  });
  $(window).load(function(){
    $(".inputFocus input, .inputFocus textarea").each(function(){ 
      if ($(this).val() != "" ) { thisspanHide($(this)); }
    });  
    
  })   
});
