



jQuery.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
  while(x<c.length){var m=r.exec(c.substr(x));
    if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
    }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
    o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;},
URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
  while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);
  t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
});


jQuery.extend({
    random: function(X) {
        return Math.floor(X * (Math.random() % 1));
    },
    randomBetween: function(MinV, MaxV) {
      return MinV + jQuery.random(MaxV - MinV + 1);
    }
});



jQuery.fn.DefaultValue = function(text){
    return this.each(function(){
		//Make sure we're dealing with text-based form fields
		if(this.type != 'text' && this.type != 'password' && this.type != 'textarea')
			return;
		
		//Store field reference
		var fld_current=this;
		
		//Set value initially if none are specified
        if(this.value=='') {
			this.value=text;
		} else {
			//Other value exists - ignore
			return;
		}
		
		//Remove values on focus
		$(this).focus(function() {
			if(this.value==text || this.value=='')
				this.value='';
		});
		
		//Place values back on blur
		$(this).blur(function() {
			if(this.value==text || this.value=='')
				this.value=text;
		});
		
		//Capture parent form submission
		//Remove field values that are still default
		$(this).parents("form").each(function() {
			//Bind parent form submit
			$(this).submit(function() {
				if(fld_current.value==text) {
					fld_current.value='';
				}
			});
		});
    });
};  	



$(document).ready(function(){
	
	$("#studio88").text("");
	
	$('.box_skitter').skitter({numbers:false,hideTools:true,navigation:false});
	$("#boxes div").hover(function(){
	  $("span", this).stop().animate({height: 30,marginTop:-5},100);
	}, function(){
	  $("span", this).stop().animate({height: 25,marginTop:0},100);
	});
	
	
	
	

	$("#studio88").hover(function(){ 	
		$(this).stop().animate({backgroundPosition: "0px -15px"},200); 
	}, function(){ 
		$(this).stop().animate({backgroundPosition: "0px 0px"},200); 
	});
		

	var i, previous, pos;
	  $("#iddesign-nyito").everyTime(5000, function() {
	    i = $.randomBetween(0, 7);
	    if (i == previous) { i = $.randomBetween(0, 3); }
	    if (i == previous) { i = $.randomBetween(0, 3); }
	    if (i == previous) { i = $.randomBetween(0, 3); }
	    previous = i;
	    pos = i*380;
	    $("div", this).animate({opacity:0,left:-936},600, function(){
	      $(this).css({backgroundPosition:"0px "+pos+"px"});
	      $("#iddesign-nyito").animate({backgroundPosition:"0px "+pos+"px"},600, function(){
	        $("div", this).animate({opacity:1,left:0},600);
	      })
	    });
	    
	  });
	  
	  

	$('img').attr('galleryimg', 'no');


  /* Footer fő kategóriábol kiszedi az anchort */


$('#footerjobb .section strong').each(function(){
	$(this).text($('a', $(this)).text()).css('color', 'rgb(170, 170, 170)')
	$('a', $(this)).remove()
})

$('#footerjobb .section:last').hide()


  /* FOMENU */
  
  
  
  
  
  $("#header ul ul").css({height:"0px",opacity:0});
  
  $("#header ul ul").each(function(){

  	var w = 0 ;
	
  	$('li', this).each(function(i){
  	
  		
  		w += $(this).innerWidth() + 5 + parseInt($(this).css('marginRight'));
  	})
  	
  	$(this).width(w)
  
  })
  
  $("#header ul>li").hover(
    function(e){ $(this).addClass('hover'); $("ul",this).stop().animate({height:30,opacity:1}, 200);},
    function(e){ $(this).removeClass('hover'); $("ul",this).stop().animate({height:0,opacity:0},200);
  });

  /* LOGO */
 // $("#logo span").hide(); setInterval("logoanim()",3000);

  /* TERMEKEK MENU KINYITASA */
  $("#products .show").parent().find("ul").show(700);$("#products .show").parent().find("h2").animate({paddingLeft:"40px"},700);

  /* TERMEKEK MENU MUKODTETESE */
  $("#products ul li h2").click(
    function(){ $("#products ul ul").hide(350);$(this).parent().find("ul").show(350);
    $("#products h2").animate({paddingLeft:0}, 350); $(this).animate({paddingLeft:"40px"},700);});
    
    
    $("#products ul li .aktiv").parents('ul').show()
    $("#products h2.aktiv").next('ul').show()
    
    
  /* MARKETINGBLOKK */




	if($("#marketingblokk div ul li").length > 1){ 
	  $("#marketingblokk div").jCarouselLite({
	      	mouseWheel:true,
			circular:false,
			visible:1,
			speed:350,
			scroll:1,
			btnNext:"#mnext",
			btnPrev:"#mprev",
			afterEnd: function(e){
				$("#marketingblokk ol li").css({backgroundColor:"#fff"});
	      		var idx = $("#marketingblokk div li").index(e);$("#marketingblokk ol").find("li:eq("+idx+")").css({backgroundColor:"#000"})
			}
	  });
  }else{
  	$('#mprevnext').hide()
  	$('#marketingblokk ol').hide()
  }



  /* TERMEKLISTA */
  
  
  if($("#carousel  ul li").length > 1){ 
  
    /* lista nézet elkészítése */
  
  $("#carousel ul").clone().hide().insertAfter($("#carousel")).addClass('product-thumb-boxes')
  
  $('#product-view-toggle').toggle(function(){
  		$('.product-thumb-boxes').slideDown(500)
  	 	$("#carousel").hide()
 	 },function(){
  		$('.product-thumb-boxes').hide()
   		$("#carousel").slideDown(500)
  })
  
  
	$("#carousel").each(function(){
		
			var isVertical = ($(this).hasClass("product-thumb-boxes-vertical")) ? true : false ;
			
			if(isVertical) return false;
			
			$(this).jCarouselLite({
				vertical:isVertical,mouseWheel:true,circular:false,visible:1,speed:700,scroll:1,btnNext:"#cnext",btnPrev:"#cprev",easing: "jswing",afterEnd:
				function(e){$("#carousel ol li").css({backgroundColor:"#eee"});var idx=$('#carousel ul li').index(e);
				$("#carousel ol").find("li:eq("+idx+")").css({backgroundColor: "#000"})}
			});
		
	});

/*
  $("#carousel").jCarouselLite({
				mouseWheel:true,circular:false,visible:1,speed:700,scroll:1,btnNext:"#cnext",btnPrev:"#cprev",easing: "jswing",afterEnd:
				function(e){$("#carousel ol li").css({backgroundColor:"#eee"});var idx=$('#carousel ul li').index(e);
				$("#carousel ol").find("li:eq("+idx+")").css({backgroundColor: "#000"})}
  });
*/
	
	}else{
  	$('#cprevnext').hide()
  	  	$('#carousel ol').hide()
  	
	}
	
	
	
	
	
  /* TERMEKFOTOK */
  $("#prev, #next, #fotok ol").animate({opacity:0},400);$("#fotok").hover(
    function(){ $("#prev, #next, #fotok ol").stop().animate({opacity:1},400);},
    function(){ $("#prev, #next, #fotok ol").stop().animate({opacity:0},400);});
    
  if($("#fotok ul li").length > 1){   
  $("#fotok").jCarouselLite({btnNext:"#next",btnPrev:"#prev",visible:1,mouseWheel:true,circular:false,afterEnd:
      function(e){$("#fotok ol li").css({backgroundColor:"#eee"});var idx=$('#fotok ul li').index(e);
      $("#fotok ol").find("li:eq("+idx+")").css({backgroundColor: "#000"})}
  });
	}else{
	 $("#prev, #next,  #fotok ol").hide()
	}
  /* TOVABBI TERMEKEK */
  $("#tovabbiak div.inner, .product-thumb-boxes div.inner").each(function(){var i=$(this).find("img").attr("src");$(this).css({backgroundImage: "url("+i+")"});});

  /* SCROLLBAR-OK ELOKESZITESE */
 elemek = $("#marketingblokk ul li").length;while (elemek>1) { $("#marketingblokk ol").append("<li/>"); elemek-- }
   elemek = $(".product-thumb-boxes ul li").length;while (elemek>0) { $(".product-thumb-boxes ol").append("<li/>"); elemek-- }
  elemek = $("#fotok ul li").length;while (elemek>0) { $("#fotok ol").append("<li/>"); elemek-- }
  
  $("ol li:first").css({backgroundColor: "#000"});$(".product-thumb-boxes ol li:eq(0)").css({backgroundColor: "#000"});

  /* TERMEKFOTO NAGYITAS 

  $("#fotok ul li img").click(function(){var i = $(this).attr("src").replace(".jpg", "");
  $("#nagykep").css({ backgroundImage: "url("+i+"-big.jpg"+")"}).show(400);z = $(this)});


	*/
	
	$("#nagykep").click(function(){$(this).hide(400)});
	
	$("#fotok ul li a").click(function(e){
	
	e.preventDefault();
	
	var i = $(this).attr("href");
	
	$("#nagykep").css({ 
	backgroundImage: "url("+i+")"
	}).show(400);
	
	z = $(this)
	});
	

  /* PREVNEXT TIPP */
  $("#mprevnext p").css({opacity:0}); $("#cprevnext p").css({opacity:0}); $("#karpitnagy").css({opacity:0}).hide(0);
  $("#mprevnext").hover( function(){ $(this).find("p").stop().animate({opacity:1},200); }, function(){ $(this).find("p").stop().animate({opacity:0},200); });
  $("#cprevnext").hover( function(){ $(this).find("p").stop().animate({opacity:1},200); }, function(){ $(this).find("p").stop().animate({opacity:0},200); });



	$("#tabs span").click(function(e){ 
		e.preventDefault()
		$("#tabs span").removeClass("activetab"); 
		$(this).addClass("activetab"); 
		$(".scroller").hide(); 
		$($('a', this).attr('href')).fadeIn(200); 
	});
	
	$("#tabs span:last").trigger('click')
	
	if($(".scroller").length > 0){
	
	$(".scroller").hover(function(){ $("#karpitnagy, #karpitnagy img").show(0).stop().animate({opacity:1},400);}, function(){ $("#karpitnagy, #karpitnagy img").stop().animate({opacity:0},400, function(){$(this).hide()}); });
	$(".scroller ul li img").hover(function(){  i = $(this).attr("src"); $("#karpitnagy img").attr("src", i); var i = $(this).attr("alt"); $("#karpitnagy span").html(i); });
	
	
	$('.scroller ul').each(function(){
		
		$(this).width($('li', this).length * 35)
	})
	
	$('.scroller').mousemove(function(e){ 
		
		var ratio = ($("ul", this).width()- $("ul", this).parent().width()) / $("ul", this).parent().width() 
		
		if(ratio <= 0) {return false}
		
		var targetLeft = (-e.pageX + $("ul", this).parent().offset().left) * ratio
		
		$("ul", this).css({left: targetLeft})

		return true

	});

	}

  /* PRODUCTS H3 */
  $("#products h3:not(.aktiv)").hover(function(){
    $(this).css({backgroundPosition:"0"});
  }, function(){
    $(this).css({backgroundPosition:"-30px"});
  });

  /* BORDER-ANIM */
  $("#tovabbiak div p,#tovabbiak div.bg, .product-thumb-boxes div.bg, .product-thumb-boxes  li div p").css({opacity:0});
  $("#tovabbiak div.inner, .product-thumb-boxes  li div.inner").hover(function(){
  
  // $(this).stop().animate({borderTopColor:"#ccc",borderLeftColor:"#ccc",borderRightColor:"#ccc",borderBottomColor:"#ccc"},300);
  
    $("p", this).stop().animate({opacity:1},400).css({fontWeight:"bold"});
   $("span", this).stop().animate({'text-indent':7},200).css({fontWeight:"bold"});
   $(".bg", $(this).parent()).stop().animate({opacity:1},400);
  }, function(){
 
 
 //  $(this).stop().animate({borderTopColor:"#fff",borderLeftColor:"#fff",borderRightColor:"#fff",borderBottomColor:"#fff"},300);
 
   $(".bg", $(this).parent()).stop().animate({opacity:0},400);
 
    $("p", this).stop().animate({opacity:0},400).css({fontWeight:"bold"});
   $("span", this).stop().animate({'text-indent':0},400).css({fontWeight:"normal"});
  });

  /* KATEGORIAK */
  $("#categories div").each(function(){
    $(this).css({backgroundImage:"url("+$('img', this).attr('src')+")"}); $("img", this).hide();
  });

  $(".categorie").hover(function(){
    $(this).stop().css({opacity:1,borderBottomColor:"#000",borderLeftColor:"#000",borderRightColor:"#000" },200);
    $("span", this).stop().css({color:"#fff",backgroundColor:"#000"},200);
  }, function(){
   $(this).stop().css({opacity:1,borderBottomColor:"#fff",borderLeftColor:"#fff",borderRightColor:"#fff" },400);
    $("span", this).stop().css({color:"#000",backgroundColor:"#fff"},400);
  });


  /*
  $("#carousel").click(function(){
    $("#carousel").css({overflow: "visible !important"});
    $("#carousel ul").css({width: "auto !important"});
    $("#carousel li").css({"float": "none !important"});
  });
  */
  
    /* INSPIRACIO */

//
//  $("#inspiracio #lapozo").hover(function(){ $(this).stop().animate({opacity:1},200); },function(){ $(this).stop().animate({opacity:0},200); });
//  
//  $("#inspiracio #bg img").css({display:"none"});
//  $("#inspiracio #bg img.show").css({display:"block"});
//  $("#inspiracio #lapozo #lapozElore").click(function(){
//    var current = $("#inspiracio #bg img.show"); var next = ((current.next().length) ? (current.next()) : $('#inspiracio #bg img:first'));
//    current.removeClass("show"); current.css({display:"none"}); next.css({display:"block"}); next.addClass("show");
//  });
//  $("#inspiracio #lapozo #lapozHatra").click(function(){
//    var current = $("#inspiracio #bg img.show"); var next = ((current.prev().length) ? (current.prev()) : $('#inspiracio #bg img:last'));
//    current.removeClass("show"); current.css({display:"none"}); next.css({display:"block"}); next.addClass("show");
//  });
//
//  $("#lapozo").css({opacity:0});
//  $(window).bind("load", function() {
//    $("#loading").animate({dummy:1},200,function(){ $("#loading").css({backgroundImage:"none"}).animate({opacity:0},200, function(){ $("#loading").hide(); $("#lapozo").animate({opacity:1},200); }); $("#infoBar").animate({dummy:1},1000, function(){ $("#infoBar").animate({bottom:0}); }) });
//    
//    
//    
//    
//    
//  });
//
//  $("#infoBar div p").css({opacity:1});
//
//  $("#infoBar div").hover(function(){
//    $("p", this).css({display:"block"});
//  }, function(){
//    $("p", this).css({display:"none"});
//  });
//
//  $("#bg img").each(function(){
//    var i = $(this).attr("src");
//    $("<img />").attr("src",i).appendTo("#thumbnails p");
//  });
//
//  $("#thumbnails p img").click(function(){
//    var i = $("#thumbnails p img").index(this);
//    $("#bg img").css({display:"none"}).removeClass("show");
//    $("#bg img").eq(i).css({display:"block"}).addClass("show");
//  });
//
  	var fb = '<fb:comments href="{href}" simple="true" numposts="3" width="470" publish_feed="true"></fb:comments></div>';
  	
  					$("#inspiration-list").cycle({
  						speed: 500, timeout: 0, prev: "#inspiration_prev", next: "#inspiration_next", pager: "#inspiration_thumbs",
  						before: function() {
  							var i = window.location.toString().split("?")[0]+"?"+$("img", this).attr("src");
  							if($(this).attr("id")=="inspiration_thumbs") {
  								i = window.location.toString().split("?")[0];
  								}
  							$("#fbcomment").empty().html(fb.replace("{href}", i));
  							FB.init({appId: 107091302704136, status: true, cookie: true, xfbml: true});
  							},
  						after: function(){
  							//
  						}
  					});
  	
  					$("#inspiration_thumbs a:eq(0)").remove();
  	
  					$("#inspiration_thumbs a").each(function(){
  						var a = $(this).text()-1;
  						var img = $("#inspiration-list li:eq("+a+")").find("img").attr("src");
  						$(this).html("<img src='"+img+"' />");
  					});
  	
  					//$("img").css({opacity:0}).load(function(){ $(this).animate({opacity:1},100) });
  	
  					var urlQuery = location.search;
  					urlQuery = urlQuery.replace('?', '');
  					var split = urlQuery.split('=');
  	
  					$(window).load(function(){
  						$("#inspiration_thumbs img[src='"+$.URLDecode(split[0])+"']").parent().click();
  					});
  	
  					$(window).load(function(){
  						$("#inspiration_thumbs").jScrollPane({ wheelSpeed: 36, animateStep: 6 });
  						$(".jScrollPaneContainer").hover(function(){
  							$(".jScrollPaneDrag, .jScrollPaneTrack").fadeIn(200);
  						}, function(){
  							$(".jScrollPaneDrag, .jScrollPaneTrack").fadeOut(200);
  						});
  					});
  	
  					$("#inspiration_thumbs a").hover(function(){
  						$(this).stop().animate({opacity:1},100);
  					}, function(){
  						$(this).stop().animate({opacity:.6},400);
  					});
  	
  					$("#inspiration_thumbs").hover(function(){
  						$("a", this).stop().animate({opacity:.6},100);
  					}, function(){
  						$("a", this).stop().animate({opacity:1},100);
  					});
  					
  					
  					
  					
  					
  					
  					
  	////  FELIRATKOZO FORM  ////

  	$("input[name=email]").DefaultValue($("input[name=email]").attr('defaultvalue'));
  	$("input[name=first_name]").DefaultValue($("input[name=first_name]").attr('defaultvalue'));
  	
  	////  KERESÉS  ////
  	
  	// ide nem kell keresés:
  	// $("#home #searchResults, #inspiracio #searchResults").remove()
  	 
  	 $("#searchResults").prependTo("#mainwrapper")
  	
  		$("#keress").click(function(){
  			$("#kereses form").submit();
  		})
  	
  	$("#kereses form").submit(function(){
  	
  	
  		var $input = $('input[name=s]', this)
  		
  		$input.keydown(function(){
  		  			$(this).removeClass('error')
  		
  		})
  		
  		if($input.val().length < 3){
  			$input.addClass('error')
  			return false
  		}else{
  			$input.removeClass('error')
  		}
  		
  		var u = $(this).attr('action')
  		var d = $(this).serialize();
  		
  	
  	  /* lebuktatni a #searchResult-ot */
  	  $("#searchResults").empty().stop().addClass('loading').removeClass("closed-has-results").animate({height:396,marginBottom:10},100).show(1000, function(){
  	  
  	  
  	  /* betolteni a result fajlt */
  	  loadResults(u,d);

	  	 
	  });
	  	 
  	  return false;
  	});
  	
$(window).bind("load", function() {
     if($("div#promo").length > 0){
     
         $("div#promo").slideViewerPro({
             thumbs: 3,
             autoslide: true,
             asTimer: 4000,
             typo: false,
             galBorderWidth: 0,
             thumbsBorderOpacity: 0,
             buttonsTextColor: "#707070",
             buttonsWidth: 40,
             thumbsActiveBorderOpacity: 0.8,
             thumbsActiveBorderColor: "white",
             shuffle: false,
             leftButtonInner: "<img src='/assets/shared/images/p.png' />",
             rightButtonInner: "<img src='/assets/shared/images/n.png' />"
         });
     
     }
 });


  var inp = $("input[name=s]").val()
  if (inp) {
  		var u = $("#kereses form").attr('action')
  		var d = $("#kereses form").serialize();
      loadResults(u,d, function(){
      	$("#searchResults").css({height:50,marginBottom:10}).addClass("closed-has-results").click(function(){
      		$(this).animate({height:396,marginBottom:10},100).removeClass("closed-has-results")
      	})
      	
      });
      
    }

	$("#product-view-toggle").click(function(){
		$(this).toggleClass("view-type")
	}).click()


});


function loadResults(u,d, callback){

	  	 $.ajax({
	  	 	url: u,
	  	 	data: d,
	  	 	type: 'GET',
	  	 	dataType: 'html',
	  	 	success: function(data){
          $("#searchResults").removeClass('loading').html(data).css({border:"1px solid #ddd !important"})
	  	    $("#searchResults").jCarouselLite({
	  	      mouseWheel: true, visible: 1, circular: false, btnNext: "#srNext", btnPrev: "#srPrev",
	  	      afterEnd: function(e){
	  	        idx = $("#searchResults ul li").index(e);
	  	        $("#searchResults ol li").removeClass("act");
	  	        $("#searchResults ol").find("li:eq("+idx+")").addClass("act");
	  	      }
	  	      
	  	      });
	  	    $("#srClose").click(function(){ $("#searchResults").stop().animate({height:0,marginBottom:0,border:"0 !important"},300); return false;});
	  	    $("#searchResults ul li").each(function(){
	  	      $("<li></li>").appendTo("#searchResults ol");
	  	    });
	  	    
	  	    $("#searchResults ol li:first").addClass("act");

			if(callback) callback();

	  	  }

	  	 });


};




$(function(){
	
	
	
	/* 2012 new year sale kieg. */

	$("span").each(function(){
		var $thisspan = $(this)
		if ($thisspan.text()=="nys") { $thisspan.css({color:"#000000 !important"}); }
	});

	/* 2012 new year sale kieg. */
	
	
})
