$(document).ready(function(){
  //TO FAVOURITE
  $("#header .links a:last").jFav(); 
  
  
  //PRINT
  $("a.print").click(function(){
    print();
    
    return false;
  });
  
  
  //LOGIN BOX
  $(".login_box_link").click(function(){
    $(this).hide();
    $(".login_box").fadeIn();
    
    return false;
  });
  

  //TOOLTIP
  $(".termek_nezet_page .links .float_right a").tooltip({
    track: true, 
    delay: 0, 
    showURL: false, 
    opacity: 1, 
    fixPNG: true, 
    showBody: " - ", 
    top: -40, 
    left: -90 
  });  
  
  
  //LEFT MENU
  $(".leftMenu1").click(function(){
    if ($(this).is(":last-child")) {return true;}

    else {
      if ($(this).hasClass(".open")) {
        $(this).next("ul").hide();
        $(this).removeClass("open");        
      }

      else {
        $(this).next("ul").show();
        $(this).addClass("open");
      }
      
      return false;      
    }
  });
  
  
  //GYIK
  $(".gyik_page .item .bottom a").click(function(){
    $(this).parents(".bottom:eq(0)").hide().parents(".item").find(".slide_container").show();
    
    return false;
  });
  $(".gyik_page .slide_container a").click(function(){
    $(this).parents(".slide_container").hide().parents(".item").find(".bottom:eq(0)").show();
    
    return false;
  });
  
  
  //HIDDEN MENU
  $(".hidden_menu .adatlap").click(function(){
    $(".hidden_menu .kosar_box, .hidden_menu .ugyfelvalaszto_box").hide();
    $(".hidden_menu .adatlap_box").toggle();
    
    return false;
  });
  $(".hidden_menu .kosar").click(function(){
    $(".hidden_menu .adatlap_box, .hidden_menu .ugyfelvalaszto_box").hide();
    $(".hidden_menu .kosar_box").toggle();
    
    return false;
  }); 
  $(".atvetel_box .submit a").click(function(){
    $(".atvetel_box").hide();
    $(".kosar_form").show();
    
    return false;
  });     
  $("a.close, .kosar_box .continue_shopping").click(function(){
    $(".hidden_menu .kosar_box, .hidden_menu .adatlap_box, .hidden_menu .ugyfelvalaszto_box").hide();
    $(".kosar_box .kosar_form").show();
    $(".kosar_box .atvetel_box").hide();
    
    return false;
  });
  $(".kosar_box .kosar_form .submit input").click(function(){
    if (!cartChanged) {
      $(".kosar_box .kosar_form").hide();
      $(".kosar_box .atvetel_box").show();
      $(".atvetel_box select").selectbox();
    }
    else {
      alert ("Kérem előbb számolja újra a kosár tartalmát!");
    }
    
    return false;
  });


  //CAROUSEL 
  $(".jquery_gallery").jcarousel();
  $(".jquery_gallery_vertical").jcarousel({auto: 3, wrap: 'last', scroll: 1, vertical: true});
    
  
  //FANCYBOX
  $(".jquery_gallery a:not(.video), .fancybox, .jquery_gallery_vertical a:not(.video)").fancybox({
    'titleShow' : true,
    'transitionIn' : 'elastic',
    'transitionOut' : 'elastic',
    'easingIn' : 'easeOutBack',
    'easingOut' : 'easeInBack',
    'titlePosition' : 'over' 
  });  
   
	$(".jquery_gallery a.video, .jquery_gallery_vertical a.video").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 640,
			'height'		: 385,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			'wmode'				: 'transparent',
			'allowfullscreen'	: 'true'
			}
		});

		return false;
	});

  

   
  
  
  //SEARCH FOCUS 
  $("#header .search input, .comment_now input, .search_page .search_form input:eq(0), .login_box input:eq(0)").focus(function(){
    t = $(this);
    
    var eredetiErtek = t[0].defaultValue;        
    
    if (t.val() == eredetiErtek) {t.val("");}
  });
  
  $("#header .search input, .comment_now input, .search_page .search_form input:eq(0), .login_box input:eq(0)").blur(function(){
    t = $(this);
    
    var eredetiErtek = t[0].defaultValue;    
  
    if (t.val() == "") {t.val(eredetiErtek);}
  });    
});
