var timer = 0;

var scrolledX, scrolledY;
var centerX, centerY;
function popupWindow(msg)
{  
	var Xwidth = 300;
	var Yheight = 100;
	if( self.pageYOffset ) {
		scrolledX = self.pageXOffset;
		scrolledY = self.pageYOffset;
	} else if( document.documentElement && document.documentElement.scrollTop ) {
		scrolledX = document.documentElement.scrollLeft;
		scrolledY = document.documentElement.scrollTop;
	} else if( document.body ) {
		scrolledX = document.body.scrollLeft;
		scrolledY = document.body.scrollTop;
	}
	
	if( self.innerHeight ) {
		centerX = self.innerWidth;
		centerY = self.innerHeight;
	} else if( document.documentElement && document.documentElement.clientHeight ) {
		centerX = document.documentElement.clientWidth;
		centerY = document.documentElement.clientHeight;
	} else if( document.body ) {
		centerX = document.body.clientWidth;
		centerY = document.body.clientHeight;
	}
	
	var leftOffset = scrolledX + (centerX - Xwidth) / 2;
	var topOffset = scrolledY + (centerY - Yheight) / 2;
	// The initial width and height of the div can be set in the
	// style sheet with display:none; divid is passed as an argument to // the function
	
	var divToOpen = $("<div/>").addClass("cartaction").css("width", Xwidth).css("height", Yheight).css("position", "absolute").css("top", topOffset).css("left", leftOffset).css("backgroundColor", "#000").css("lineHeight", "100px").css("textAlign", "center").css("opacity", 0.8).css("color", "#fff").css("fontWeight", "bold").css("z-index", 9999).html(msg);
	$("#body").append(divToOpen);
	/*
	var o=document.getElementById(divid);
	var r=o.style;
	r.position='absolute';
	r.top = topOffset + 'px';
	r.left = leftOffset + 'px';
	r.display = "block";*/
	setTimeout("removeBox()", 2000);
	 
}

function removeBox()
{
	$(".cartaction").remove();
}

function remove_result_list()
{
     if($(".searcresultpopup").hasClass("searcresultpopup_visible"))
     {
          $(".searcresultpopup").removeClass("searcresultpopup_visible");
     }
}

function remove_compareitem(id) {
	$('.item_'+id).remove();
	$('.compare_fakescroller_width').width($('.compare_table').width());
	$.cookie('compare_items', $.toJSON(jQuery.grep($.evalJSON($.cookie('compare_items')), function(value) {return value != id;})), {path: '/'});
}

function clear_compare() {
	$.cookie('compare_catid', 0, {path: '/'});
	history.go(-1);
}

$(document).ready(function() {

	$("[rel='external']").attr("target", "_blank");
	
	$('a[rel=ajaxsubmit]').ajaxSubmit();
	
	$('.noattr').hover(function() {
	   	$(this).prev().show();	
	}, function() {
		$(this).prev().hide();
	});
    
	// osszehasonlitashoz checkboxok kitoltese, kivalasztott elemek sutiben tarolasa, stb...
	if($('input[name=categoryid]').length != 0) { 
		var categoryid = $('input[name=categoryid]').val();
		if(categoryid != $.cookie("compare_catid")) {
		 	$.cookie("compare_catid", categoryid, {path: '/'});
			$.cookie("compare_items", '["0"]', {path: '/'}); 
		}
		
		if($.evalJSON($.cookie("compare_items")).length != 1)
		 	compare_selected = $.evalJSON($.cookie("compare_items"));
		else	
			compare_selected = ['0'];
			
		if(compare_selected.length > 2) {
		  	$('#comparenow').html("<a href=\"#\" onClick=\"$('form[name=compare_form]').submit();return false;\" >Összehasonlítás</a>");
		   	$('#comparenow2').html("<a href=\"#\" onClick=\"$('form[name=compare_form]').submit();return false;\" >Összehasonlítás</a>");	
		}
		$.each(compare_selected, function(dkey, item) {
			$("input[name='compare[]'][value="+item+"]").attr("checked", true);
		});
		$("input[name='compare[]']").click(function(){ 
			var id = $(this).val();
			if($(this).attr("checked") == true) {
				compare_selected = jQuery.grep(compare_selected, function(value) {return value != id;});
				compare_selected.push(id);
			}
			else { 
				compare_selected = jQuery.grep(compare_selected, function(value) {return value != id;});
			}
			if(compare_selected.length > 2) {
			  	$('#comparenow').html("<a href=\"/aruhaz/osszehasonlitas\">Összehasonlítás</a>");
			   	$('#comparenow2').html("<a href=\"/aruhaz/osszehasonlitas\">Összehasonlítás</a>");	
			}	
			else {
			 	$('#comparenow').html('Összehasonlítás');
	        	$('#comparenow2').html('Összehasonlítás');	
			}
			$.cookie("compare_items", $.toJSON(compare_selected), {path: '/'});
		});
	}
	
	
	$('.rightbox_body2').each(function() { 
	  	if($(this).parent().attr('id') != "right") {
			var clone = $(this).clone();
			$(this).remove();
			if($('#left').next().attr('id')	!= "right")
				$('<div id="right"></div>').insertAfter("#left");
			clone.appendTo('#right');
	 	}	
	 });
     
	 /*
	 //comparer
     
     if ($("input[name='compare[]']:checked").length>=2)
     {
       $('#comparenow').html("<a href=\"#\" onClick=\"$('form[name=compare_form]').submit();return false;\" >Összehasonlítás</a>");
	   $('#comparenow2').html("<a href=\"#\" onClick=\"$('form[name=compare_form]').submit();return false;\" >Összehasonlítás</a>");
       
    
     } else { 
    
        $('#comparenow').html('Összehasonlítás');
        $('#comparenow2').html('Összehasonlítás');
    
     }
     
        $("input[name='compare[]']").click(function (e) {

                 if ($("input[name='compare[]']:checked").length>=2)
                 {
                    $('#comparenow').html("<a href=\"#\" onClick=\"$('form[name=compare_form]').submit();return false;\" >Összehasonlítás</a>");
                     $('#comparenow2').html("<a href=\"#\" onClick=\"$('form[name=compare_form]').submit();return false;\" >Összehasonlítás</a>");
                    
                } else {
                    $('#comparenow').html('Összehasonlítás');
                    $('#comparenow2').html('Összehasonlítás');
                }
        }); 
	 
	 */
	 
	 
	// keresé
	$("[name='search']").keyup(function(e){
		if($(this).val().length > 2)
		{
               var key = (e.which) ? e.which : e.keyCode

               if(key != 38 && key != 40 && key != 13)
               {
                    $.ajax({
                         type: "POST",
                         url: "/gyorskereses",
                         data: {search: $(this).val()},
                         async: false,
                         dataType: "json",
                         success: function(msg){
                              $(".searcresultpopup > ul").empty();

                              if(!$(".searcresultpopup").hasClass("searcresultpopup_visible"))
                              {
                                   $(".searcresultpopup").addClass("searcresultpopup_visible");
                              }
                              
                              if(!msg.products && !msg.vendors && !msg.news)
                              {
                                   $(".searcresultpopup > ul").append("<li class=\"searcresultproducts\"><span>Nincs találat</span></li>");
                              }

                              if(msg.products)
                              {
                                   $(".searcresultpopup > ul").append("<li class=\"searcresultproducts\"><span>Termékek</span></li>");

                                   var products_count = msg.products.length-1;
                                   $.each(msg.products, function (i, p)
                                   {
                                        $(".searcresultpopup > ul").append("<li class=\"resultitem\"><a href=\"/aruhaz/termek/"+p.id+"\"><div class=\"searcresultpopupimage\"><img src=\""+p.image+"\" alt=\""+p.name_hu+"\" /></div><div class=\"searcresultpopuptext\">"+p.name_hu+"</div></a></li>");

                                        if(i != products_count)
                                        {
                                              $(".searcresultpopup > ul").append("<li class=\"separator\"></li>");
                                        }
                                   });
                              }

                              if(msg.categories)
                              {
                                   $(".searcresultpopup > ul").append("<li class=\"searcresultproducts categories\"><span>Kategóriák</span></li>");

                                   var categories_count = msg.categories.length-1;
                                   $.each(msg.categories, function (i, p)
                                   {
                                        $(".searcresultpopup > ul").append("<li class=\"resultitem\" type=\"category\"><a href=\"/aruhaz/osszetett-kereses/"+p.id+"/kif/"+$("[name='search']").val()+"\"><div class=\"searcresultpopupimage\"><img src=\""+p.image+"\" alt=\""+p.name_hu+"\" /></div><div class=\"searcresultpopuptext\">"+p.name_hu+"</div></a></li>");

                                        if(i != categories_count)
                                        {
                                              $(".searcresultpopup > ul").append("<li class=\"separator\"></li>");
                                        }
                                   });
                              }

                              if(msg.vendors)
                              {
                                   $(".searcresultpopup > ul").append("<li class=\"searcresultproducts\"><span>Gyártók</span></li>");

                                   var vendors_count = msg.vendors.length-1;
                                   $.each(msg.vendors, function (i, p)
                                   {
                                        $(".searcresultpopup > ul").append("<li class=\"resultitem\"><a href=\"/aruhaz/gyarto/"+p.id+"\"><div class=\"searcresultpopupimage\"><img src=\""+p.image+"\" alt=\""+p.name+"\" /></div><div class=\"searcresultpopuptext\">"+p.name+"</div></a></li>");

                                        if(i != vendors_count)
                                        {
                                              $(".searcresultpopup > ul").append("<li class=\"separator\"></li>");
                                        }
                                   });
                              }

                              if(msg.news)
                              {
                                   $(".searcresultpopup > ul").append("<li class=\"searcresultproducts\"><span>Hírek</span></li>");

                                   var news_count = msg.news.length-1;
                                   $.each(msg.news, function (i, p)
                                   {
                                        $(".searcresultpopup > ul").append("<li class=\"resultitem\"><a href=\"/magazin/reszletek/"+p.id+"\"><div class=\"searcresultpopupimage\"><img src=\""+p.image+"\" alt=\""+p.title_hu+"\" /></div><div class=\"searcresultpopuptext\">"+p.title_hu+"</div></a></li>");

                                        if(i != news_count)
                                        {
                                              $(".searcresultpopup > ul").append("<li class=\"separator\"></li>");
                                        }
                                   });
                              }

                              if(msg.products || msg.vendors || msg.news)
                              {
                                   $(".searcresultpopup > ul").append("<li class=\"searcresultproducts more_results\"><a href=\"/kereses?search="+$("[name='search']").val()+"\">További találatok...</span></li>");
                              }
							  
								$(".resultitem").css("cursor", "pointer").mouseenter(function(){
									$(this).css("backgroundColor", "#bacdd4");
								}).mouseleave(function(){
									$(this).css("backgroundColor", "#edf1f4");
								}).mousedown(function(){
                                             window.location = $(this).children(":eq(0)").attr("href");
//									$(this).children(":eq(0)").click();
								});
                         }
                    });
               }
               else
               {
                    var current, next;
                    switch(key)
                    {
                         case 40 : //MENNYéé
                              
                              if($(".searcresultpopup > ul").children(".selected").length == 0)
                              {
                                   current = $(".searcresultpopup > ul").children(".resultitem").get(0);
                                   $(current).addClass("selected");
                              }
                              else
                              {
                                   current = $(".searcresultpopup > ul").children(".selected").get(0);
                                   
                                   if($(current).nextAll(".resultitem").length > 0)
                                   {
                                        next = $(current).nextAll(".resultitem").get(0);
                                        $(current).removeClass("selected");
                                        $(next).addClass("selected");
                                   }
                              }

                              break;

                         case 38 : //VISSZAMENNYééé
                                   current = $(".searcresultpopup > ul").children(".selected").get(0);

                                   if($(current).prevAll(".resultitem").length >= 0)
                                   {
                                        next = $(current).prevAll(".resultitem").get(0);
                                        $(current).removeClass("selected");
                                        $(next).addClass("selected");
                                   }
                              break;
                    }
               }
          }
          else
          {
               if($(".searcresultpopup").hasClass("searcresultpopup_visible"))
               {
                    $(".searcresultpopup").removeClass("searcresultpopup_visible");
               }
          }
	});

     $("[name='search']").keypress(function(e){
		if($(this).val().length > 2)
		{
               var key = (e.which) ? e.which : e.keyCode
               
               if(key == 13)
               {
                    if($(".searcresultpopup > ul").children(".selected").length > 0)
                    {
                         e.preventDefault();
                         current = $(".searcresultpopup > ul").children(".selected").get(0);
                         //current = $(current).children(".searcresultpopuptext").get(0);
                         //var link = $(current).children("a").get(0);
                         window.location = $(current).children(":eq(0)").attr("href");
                        // return false;
                    }
               }
          }
     });

     $("[name='search']").click(function(){
          if($(".searcresultpopup > ul").children(".selected").length > 0)
          {
               current = $(".searcresultpopup > ul").children(".selected").get(0);
               $(current).removeClass("selected");
          }
     });

     $("[name='search']").blur(function(){
          setTimeout("remove_result_list()", 100);
     });

	$(".reg_box").children("h2").click(function(){
		if($(this).attr("id") == "opened")
			$(this).attr("id", "closed").removeClass("reg_box_opened").parent().animate({"height": "45px"}, 200);
		else
			$(this).attr("id", "opened").addClass("reg_box_opened").parent().animate({"height": "190px"}, 200);
	});
	
	// fooldali visszaszámlálás elindítása
	countBack();
	//setTimeout("countBack()", 1000);
	
	// tabok belövése
	$(".tabbutton").click(function(e){
		e.preventDefault();
		var container = $("." + $(this).attr("href").slice(1));
		var buttoncontainer = $("." + $(this).attr("href").slice(1) + "container");
		// eldugjuk a tartalmakat
		container.children().hide();
		// az aktuálisat megjelenítjük
		container.children("." + $(this).attr("rel")).show();
		// minden gombot normálra teszünk
		buttoncontainer.children().removeClass("activetab").addClass("normaltab");
		// a megnyomottat aktívvá tesszük
		$(this).parent().parent().parent().parent().addClass("activetab");
	})
	
	// jobboldali tab belövése
	$(".righttab").click(function(e){
		e.preventDefault();
		var tab = Number($(this).attr("rel"));
		var passive = $(".right_passive_tab");
		$(".right_active_tab").removeClass("right_active_tab").addClass("right_passive_tab");
		//passive.removeClass("right_passive_tab").addClass("right_active_tab");                
		$(this).removeClass("right_passive_tab").addClass("right_active_tab");		
		$(".righttab_box").hide();
		$("#righttab_" + tab).show();
	});
	//kereső mező submitolosa Enterre
//	$("#search").keypress(function (e) {
//		if(e.which == 13) $("#searchform").submit();
//	});
	$("#sub_search").keypress(function (e) {
		if(e.which == 13) $("#sub_search_form").submit();
	});
	
	$("a[rel='ratings']").click(function(){
		$("a[rel='tab3box']").click();
	});

	$("a[rel='technical_datas']").click(function(){
		$("a[rel='tab2box']").click();
	});
	
	$("a[rel='more_info']").click(function(){
		$("a[rel='tab1box']").click();
	});
	
	$("a[class='email']").click(function(e){
		e.preventDefault();
		if($(".question_box").attr("id") == "questionboxvisible")
		{
			$(".question_box").attr("id", "questionboxnotvisible").hide();
		}
		else
		{
			$(".question_box").attr("id", "questionboxvisible").show();
		}
	});
	
	$("a[class='belepes']").click(function(e){
		e.preventDefault();
		if($(".login_box_popup").attr("id") == "loginboxvisible")
		{
			$(".login_box_popup").attr("id", "loginboxnotvisible").hide();
		}
		else
		{
			$(".login_box_popup").attr("id", "loginboxvisible").show();
		}
	});
	
	$("#slider").easySlider();
	
	$("a", $("#slider")).click(function(e){
		e.preventDefault();
		//$(".product_images_big").children().children().attr("src",$(this).children().attr("src"));
	});
	
	$(".product_images_big").children().click(function(e){
		e.preventDefault();
		if($("#firstgalleryimage"))	$("#firstgalleryimage").click();
	});
	
	//if($("#firstgalleryimage").length == 0)
		//$(".product_images_big").children().attr("rel", "prettyPhoto");
	
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 30, /* padding for each side of the picture */
		opacity: .7, /* Value betwee 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'dark_square' /* light_rounded / dark_rounded / light_square / dark_square */
	});
	
	$("#heard_type").change(function(){
		if($(this).attr("value") == 11)	$("#heard_text_container").show();
		else $("#heard_text_container").hide();
	});
	
	$("#visszahivas").validate({
		rules: {
			"callback[description]": {
				required: true
			},
			"callback[email]": {
				email: true
			},
			"callback[name]": {
				required: true
			},
			"callback[phone]": {
				required: true
			},
			"callback[from]": {
				number: true
			},
			"callback[to]": {
				number: true
			}
		},
		messages: {
			"callback[description]": {
				required: ""
			},
			"callback[email]": {
				email: ""
			},
			"callback[name]": {
				required: ""
			},
			"callback[phone]": {
				required: ""
			},
			"callback[from]": {
				number: ""
			},
			"callback[to]": {
				number: ""
			}
		}
	});

     $("#ertekelek").click(function(){
        $("#ertekel").show("fast");
		$('#ertekelek').addClass('hidden');
     });

     $(".move_rating_stars").mousemove(function(e){
                                        var pos = $(this).offset();
                                        var width = $(this).width();
                                        var height = $(this).height();
                                        var percent;
                                        var one_percent = width/100;
                                        var e_pos;

                                             e_pos = e.pageX-pos.left;
                                             percent = e_pos/one_percent;
                                             
                                             if(percent > 0 && percent <= 20)
                                             {
                                                  percent = 20;
                                             }
                                             else if(percent > 20 && percent <= 40)
                                             {
                                                  percent = 40;
                                             }
                                             else if(percent > 40 && percent <= 60)
                                             {
                                                  percent = 60;
                                             }
                                             else if(percent > 60 && percent <= 80)
                                             {
                                                  percent = 80;
                                             }
                                             else if(percent > 80 && percent <= 100)
                                             {
                                                  percent = 100;
                                             }

                                             $(this).children(".bluestar").css("width", percent+"%");

                                   }
     );

     $(".move_rating_stars").mouseout(function(){
                                        $(this).children(".bluestar").css("width", $(this).next("input").val());
                                      });

     $(".move_rating_stars").click(function(){
          var width = $(this).children(".bluestar").css("width");
          $(this).next("input").val(width);
     });

     $(".integer_only").keypress(function(e){
        if(e.which  < 48 || e.which  > 57)
        {
          return false;
        }
     });

     $(".show_order_details").click(function(){
          $(this).next("div").show("fast");
          return false;
     });

     $(".lost-password").click(function(){
          $("#belepes").fadeOut("fast", function(){
               $("#elfelejtett_jelszo").fadeIn("fast");
          });
          return false;
     });

     $(".back-to-login").click(function(){
          if($("#uj_jelszo").css("display") == "block")
          {
               $("#uj_jelszo").fadeOut("fast", function(){
                    $("#belepes").fadeIn("fast");
               });
          }
          else
          {
               $("#elfelejtett_jelszo").fadeOut("fast", function(){
                    $("#belepes").fadeIn("fast");
               });
          }
          return false;
     });

     $(".renew-password").click(function(){
          $.ajax({
               type: "POST",
               url: "elfelejtett-jelszo",
               data: "user=" + $("#lost_username").val()+"&email="+$("#lost_email").val(),
               success: function(msg){
                    if(msg == "ok")
                    {
                         $("#elfelejtett_jelszo").fadeOut("fast", function(){
                              $("#uj_jelszo").fadeIn("fast");
                         });

                         $("#username").val($("#lost_username").val());
                         $("#lost_email").val('');   
                         $("#lost_username").val('');
                    }
                    else
                    {
                         alert("A jelszómódosítás nem járt sikkerrel!\nLehet hogy elírta a felhasználónevét vagy a jelszavát?");
                    }
             }
          });
          return false;
     });

     $("#copy").click(function(){
        $(".copyable").each(function(){
          $("#billing_"+$(this).attr("id")).val($(this).val());
        });
     });

     if($("#slider").length > 0)
     {		 
          $(".image_replace").click(function(){
               $("#main_image_popup").attr("rel", $(this).parent().attr("href"));
               $("#main_image").attr("src", $(this).attr("src"));
          });
     }
	 
	 $('#main_image_popup').click(function() {
	 	$('a[href='+$(this).attr('rel')+']').click();
	 })

     if($(".read_more").length > 0)
     {
          $(".read_more").click(function (){
               $(".more").fadeIn("slow");
          });
     }

     if($(".showdata").length > 0)
     {
          $(".showdata").click(function(e){
               e.preventDefault();
               $.ajax({
                    type: "GET",
                    url: "aruhaz/kiegeszito-popup",
                    data: "product_id=" +  $(this).parent().parent().next().next().next().children(":eq(0)").val(),
                    async: false,
                    dataType: "json",
                    success: function(data){
                         if(data){
                              $(".opinion_popup_line").text(data.name_hu);

                              if(data.first_image)
                              {
                                   $(".opinion_popup_image").children(":eq(0)").attr("src", "/files/products/"+data.id+"/images/small/"+data.first_image);
                              }

                              $(".jump_to_product").attr("href", "/aruhaz/termek/"+data.id+"/"+data.url);
								$(".add_cart").attr("onclick", "add_to_cart("+data.id+"); return false;");

                              if(data.attributes)
                              {
                                   $(".opinion_popup_content_container .product_right_details > ul").empty();
                                   var k=0;
                                   var l=0;
                                   
                                   
                                   $.each(data.attributes, function (i, p)
                                   {
                                        
									if(k<1)
									{	
									k++;	
										if(p.attributes)
                                        {
                                        	
                                             $(".product_right_details > ul").append("<li><div class=\"float_left\"><b>"+p.as_name_hu+"</b></div></li>");

                                             $.each(p.attributes, function (i2, p2){
                                            
											if(l<4)
											{
											 l++;
											      if(i2 % 2 === 0)
                                                  {
                                                       $(".product_right_details > ul").append("<li><div class=\"float_left\">"+p2.pa_name_hu+"</div>: "+p2.pav_value+"</li>");
                                                  }
                                                  else
                                                  {
                                                       $(".product_right_details > ul").append("<li class=\"dark\"><div class=\"float_left\">"+p2.pa_name_hu+"</div>: "+p2.pav_value+"</li>");
                                                  }
                                            }
											 });
                                             
                 							
                                        }
									}
                                   });
                              }
                              else
                              {
                                   $(".product_right_details > ul").append("<li><div class=\"float_left\">Nincs megadva.</div></li>");
                              }

                              $(".opinion_popup").fadeIn("fast");
                         }else{
                         //popup előjön és mindenki boldog...
                              alert("sss");
                         }
                    }
               });

               return false;
          });

          $(".close_datasheet").click(function(e){
               e.preventDefault();
               $(".opinion_popup").fadeOut("fast");
          });
     }

     if($(".add_related_to_cart").length > 0)
     {
          $(".add_related_to_cart").click(function(e){
               e.preventDefault();
               $(".related_to_cart").each(function(){
                    if($(this).is(":checked") == 1)
                    {
                         $(this).attr("checked", "");
                         add_to_cart($(this).val());
                    }
               });
          });

          return false;
     }

     if($("#flash_banner").length > 0)
     {
     	var so1 = new SWFObject("/includes/0/flash/banner.swf?regurl=/regisztracio&reszleturl=magazin/reszletek/76", "line", "697", "147", "0", "#000000");
     	so1.addParam("allowScriptAccess", "sameDomain");
     	so1.addParam("wmode", "transparent");
     	so1.write("flash_banner");
     }
	 
	 // fake scrollbar az osszehasonlitas tetejere, es egyeb nyalanksagok
	 if($.browser.msie || $.browser.opera) 
	 	$('.compare_pic img').css({margin:0}); 
	 if($('.compare_table').length > 0 && $('.compare_table').width() > 882) { 
	 	noscroll_bottom = 0;
		noscroll_top = 0;

	 	$('<div class="compare_fakescroller_scroller"><div class="compare_fakescroller_width" style="width:'+$('.compare_table').width()+'px;height:17px;line-height:0;font-size:0"></div></div>').prependTo('.bfb_container');
	  	$('.compare_fakescroller_width').width($('.compare_table').width());
	   	if($.browser.msie)
		 	$('.compare_fakescroller_scroller').css({marginTop: 6});    
		$('.compare_fakescroller_scroller').scrollLeft($('.bfb').scrollLeft());
		$('.compare_fakescroller_scroller').scroll(function() {
	  		if(noscroll_top)
				return true;
			if(typeof(noscroll_bottom_timeout) != "undefined")
				clearTimeout(noscroll_bottom_timeout);
			noscroll_bottom_timeout = setTimeout("noscroll_bottom = 0;", 300);
			noscroll_bottom = 1;
	  	   	$('.bfb').scrollLeft($(this).scrollLeft());	
	  	});
		$('.bfb').scroll(function() {
			if(noscroll_bottom)
				return true;
			if(typeof(noscroll_top_timeout) != "undefined")
				clearTimeout(noscroll_top_timeout);
			noscroll_top_timeout = setTimeout("noscroll_top = 0;", 300);
			noscroll_top = 1;
	  	   	$('.compare_fakescroller_scroller').scrollLeft($(this).scrollLeft());	
	  	});
	 }
	 
	 $('.new_dropdown').each(function() {
	 	var items1 = $('.new_dropdown_item', this);
		var items2 = $('.subsub', this);  
		$(this).width(items1.length*103);	
		if(items2.length ==  0) {
		 	$('.new_dropdown_item_top', this).css({border: 0});
			$('.new_dropdown_item_bottom', this).remove();	
		}
	 });
	 
	 $('.dropdown_right').hover(function() {
	     if($('.new_dropdown', this).length) {
        if($(this).position().left+$(this).width() > $('.new_dropdown', this).position().left+$('.new_dropdown', this).width())
            $('.new_dropdown', this).css({left:$(this).position().left+$(this).width()-$('.new_dropdown', this).width()});
            }
	 });
	
	$('#heard_type').change(function() {
	   	if($(this).val() == 4)
	   		$('#cp_name').show();
		else
		 	$('#cp_name').hide();		
	});
		
		
});

function callback_validate() {
	var _return = $("#visszahivas").validate({
		rules: {
			"callback[description]": {
				required: true
			},
			"callback[email]": {
				email: true
			},
			"callback[name]": {
				required: true
			},
			"callback[phone]": {
				required: true
			},
			"callback[from]": {
				number: true
			},
			"callback[to]": {
				number: true
			}
		},
		messages: {
			"callback[description]": {
				required: ""
			},
			"callback[email]": {
				email: ""
			},
			"callback[name]": {
				required: ""
			},
			"callback[phone]": {
				required: ""
			},
			"callback[from]": {
				number: ""
			},
			"callback[to]": {
				number: ""
			}
		}
	});
	console.log(_return);
}

function countBack() { 
	$(".timer").each(function() {
        var datas = $(this).attr("value").split(', ')[1];
		
		if(typeof(datas) == "undefined") {
		 	datas = $(this).attr("value");
			var nocalc = 0;	
		} 
	   	else {
		 	var days = $(this).attr("value").split(', ')[0].split(' ')[0];
			var nocalc = 1; 
		}
		
		datas = datas.split(':');
		if(!nocalc)
			var days = Math.floor(Number(datas[0]/24));

		if(days > 0 && !nocalc) {
		 	var hour = Number(datas[0])-(days*24);	
		}
		else {
			var hour = Number(datas[0]);	
		}
		var minute = Number(datas[1]);
		var second = Number(datas[2]) - 1;

		if(second == -1) {
			second = 59;
			minute -= 1;
		}

		if(minute == -1) {
			minute = 59;
			hour -= 1;
		}

		if(hour < 0)
		{
			hour = 0;
			minute = 0;
			second = 0;
		}

		hour = converIntegerToTwoigitString(hour);
		minute = converIntegerToTwoigitString(minute);
		second = converIntegerToTwoigitString(second);

		if(days > 0) {
			$(this).attr("value", days + " nap, " + hour + ":" + minute + ":" + second);
		}
		else {
			//$(this).attr("value", "0 nap, " + hour + ":" + minute + ":" + second);
		 	$(this).attr("value", hour + ":" + minute + ":" + second); 	
		}
	});
	setTimeout("countBack()", 1000);
}

function converIntegerToTwoigitString(i)
{
	if(i < 10)
		return '0' + String(i);
	else
		return String(i);
}
function add_to_cart(id){
	var amount = parseInt($("#product_amount_" + id).attr('value'));
	if(isNaN(amount)){
		amount = 1;
		$("#product_amount_" + id).attr('value', 1);
	}
	//alert(amount);
	//return false;
	$.ajax({
		type: "POST",
		url: "kosar/termek_belerak",
		data: "product_id=" + id + "&product_amount=" + amount,
		async: false,
		dataType: "json",
		success: function(data){
    		if(data.success){
    			$("#basketlink").html("<a href='kosar' title='Kosár'></a>");
    			$("#basket_content").html("<a href='kosar' title='Kosár'>" + data.number + " termék <br />" + data.total + " Ft</a>");
				popupWindow("A termék a kosárba került!");
    			//alert( "A termék a kosárba került!");
			}else{
				popupWindow("A terméket nem sikerült berakni a kosárba!");
				//alert( "Nem sikerült belerakni a kosárba!");
			}
			/*
			if(msg == 'true'){
				alert( "A term?k a kos?rba ker?lt!");
			}else{
				alert( "Nem siker?lt belerakni a kos?rba!");
			}
			*/
		}
	});
}

function update_cart(id)
{
	//alert(id) 
	//alert($("#product_amount_" + id).attr('value'))
	var amount = parseInt($("#product_amount_" + id).attr('value'));
	//alert(amount)
	if(isNaN(amount)){
		amount = 1;
		$("#product_amount_" + id).attr('value', 1);
	}
	//alert(amount)
	$.ajax({
		type: "POST",
		url: "kosar/termek_frissit",
		data: "product_id=" + id + "&product_amount=" + amount,
		async: false,
		dataType: "json",
		success: function(data){
    		if(data.success){
    			$("#basketlink").html("<a href='kosar' title='Kosár'></a>");
    			$("#basket_content").html("<a href='kosar' title='Kosár'>" + data.number + " termék <br />" + data.total + " Ft</a>");
    			$("#total").html("Összesen: " + data.total + " Ft");
	    		$("#tax").html("ÁFA tartalom: " + data.tax + " Ft");
	    		$("#product_total_" + id).html("<p class='strong'>" + data.p_total + " Ft</p>");
    			//alert( "A termék sikeresen módosult!");
   				popupWindow("A termék sikeresen módosult!");
			}else{
			//	alert( "Nem sikerült módosítani a terméket!");
				popupWindow("Nem sikerült módosítani a terméket!");
			}
			/*
			if(msg == 'true'){
				alert( "A termék a kosárba került!");
			}else{
				alert( "Nem sikerült belerakni a kosárba!");
			}
			*/
		}
	});
}

function delete_from_cart(id)
{
	//var conf = confirm('Biztosan törölni akarja a terméket?');
	var conf = true;
	
	if(conf){
		$.ajax({
			type: "POST",
			url: "kosar/termek_kivesz",
			data: "product_id=" + id,
			async: false,
			dataType: "json",
			success: function(data){
	    		if(data.success){
	    			$("#basketlink").html("<a href='kosar' title='Kosár'></a>");
	    			$("#basket_content").html("<a href='kosar' title='Kosár'>" + data.number + " termék <br />" + data.total + " Ft</a>");
	    			$("#total").html("Összesen: " + data.total + " Ft");
	    			$("#tax").html("ÁFA tartalom: " + data.tax + " Ft");
	    			$("#product_" + id).remove();
	    				//alert( "A term?ket sikeresen t?r?lt?k!");
	    			popupWindow("A terméket sikeresen töröltük!");
				}else{
								//alert( "Nem siker?lt t?r?lni a term?ket!");
				popupWindow("Nem sikerült törölni a terméket!");
				}
			}
		});
	}
}

function save_product_to_cookie(id)
{
	$.ajax({
		type: "POST",
		url: "kosar/termek_ment",
		data: "product_id=" + id,
		success: function(msg){
            //alert(msg);
            switch(msg){
            case "1":
                alert("Már elmentette egyszer ezt a terméket!");
                break;
            case "2":
                alert("Nem menthet több terméket! Elötte törölnie kell a listából!");
                break;
            default:
                refresh_product_from_cookie();
                break;
            }
            
        }
	});
$('#eleonora').click();
}

function delete_product_from_cookie(id,pos)
{
    //$("#saved_prod_"+pos).fadeOut('slow');
    $.ajax({
		type: "POST",
		url: "kosar/termek_torol",
		data: "product_id=" + id,
		success: function(msg){
            //alert(msg);
			refresh_product_from_cookie();
        }
	});
}

function delete_saved_product(id){
	$.ajax({
		type: "POST",
		url: "kosar/termek_torol",
		data: "product_id=" + id,
		success: function(msg){
        }
	});
	$('#saved_product_' + id).remove();
}

function refresh_product_from_cookie()
{
    $("#saved_prod_pager").html("");
    $.ajax({
		type: "POST",
		url: "kosar/termek_refresh",
		async: false,
		dataType: "json",
		success: function(data){
            //alert(data.prods);
            //$("#saved_products").html($("<textarea/>").attr("value",data.prods));
			$("#saved_products").html(data.prods);
            $("#saved_prod_pager").html(data.pager);
        }
	});
}

function last_viewed_pager(page,prods)
{
    //alert('lapoz?s'+ page);
    //alert(prods);
    switch(page)
    {
    case 1:
      for (x=0;x<10;x++){
        $("#last_viewed_"+x).removeClass("last_viewed_content_hidden");
      }
      for (x=10;x<20;x++){
        $("#last_viewed_"+x).addClass("last_viewed_content_hidden");
      }
      for (x=20;x<30;x++){
        $("#last_viewed_"+x).addClass("last_viewed_content_hidden");
      }
      $("#lv_pager").html("1-10 a "+prods);
      break;
    case 2:
      for (x=0;x<10;x++){
        $("#last_viewed_"+x).addClass("last_viewed_content_hidden");
      }
      for (x=10;x<20;x++){
        $("#last_viewed_"+x).removeClass("last_viewed_content_hidden");
      }
      for (x=20;x<30;x++){
        $("#last_viewed_"+x).addClass("last_viewed_content_hidden");
      }
      if (prods <= 20){
        $("#lv_pager").html("11-"+prods+" a "+prods);
      } else {
        $("#lv_pager").html("11-20 a "+prods);
      }
      break;
    case 3:
      for (x=0;x<10;x++){
        $("#last_viewed_"+x).addClass("last_viewed_content_hidden");
      }
      for (x=10;x<20;x++){
        $("#last_viewed_"+x).addClass("last_viewed_content_hidden");
      }
      for (x=20;x<30;x++){
        $("#last_viewed_"+x).removeClass("last_viewed_content_hidden");
      }
      if (prods <= 30){
        $("#lv_pager").html("21-"+prods+" a "+prods);
      } else {
        $("#lv_pager").html("21-30 a "+prods);
      }
      break;
    default:
      alert('Hiba történt lapozás közben!');
    }

}

function saved_product_pager(page,prods)
{
    //alert('lapoz?s'+ page);
    //alert(prods);
    switch(page)
    {
    case 1:
      for (x=0;x<4;x++){
        $("#saved_prod_"+x).removeClass("last_viewed_content_hidden");
      }
      for (x=4;x<8;x++){
        $("#saved_prod_"+x).addClass("last_viewed_content_hidden");
      }
      for (x=8;x<12;x++){
        $("#saved_prod_"+x).addClass("last_viewed_content_hidden");
      }
      $("#sp_pager").html("1-4 a "+prods);
      break;
    case 2:
      for (x=0;x<4;x++){
        $("#saved_prod_"+x).addClass("last_viewed_content_hidden");
      }
      for (x=4;x<8;x++){
        $("#saved_prod_"+x).removeClass("last_viewed_content_hidden");
      }
      for (x=8;x<12;x++){
        $("#saved_prod_"+x).addClass("last_viewed_content_hidden");
      }
      if (prods <= 8){
        $("#sp_pager").html("5-"+prods+" a "+prods);
      } else {
        $("#sp_pager").html("5-8 a "+prods);
      }
      break;
    case 3:
      for (x=0;x<4;x++){
        $("#saved_prod_"+x).addClass("last_viewed_content_hidden");
      }
      for (x=4;x<8;x++){
        $("#saved_prod_"+x).addClass("last_viewed_content_hidden");
      }
      for (x=8;x<12;x++){
        $("#saved_prod_"+x).removeClass("last_viewed_content_hidden");
      }
      if (prods <= 12){
        $("#sp_pager").html("9-"+prods+" a "+prods);
      } else {
        $("#sp_pager").html("9-12 a "+prods);
      }
      break;
    default:
      alert('Hiba történt lapozás közben!');
    }

}

function product_rating_submit()
{
     var submit = true;

     $(".starvalue").each(function(){
         if($(this).val() == "0%")
         {
              submit = false;
         }
     });

     if(submit)
     {
          document.ertekel.submit();
          return false;
     }
     else
     {
          popupWindow("Kérjük állítsa be a csillagokat!");
          return false;
     }
}

inputValuadator = '';


jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

$.fn.ajaxSubmit = function() { 
	
	$('[rel=ajaxsubmit]').parents("form").find('input[type=text], input[type=password]').live("keydown", function(e) { 
		if (e.keyCode == '13') {
     		e.preventDefault();
			$(this).parents("form").find('[submit=submit]').click();  
   		}
	}).keydown(function(e) { 
		if (e.keyCode == '13') {
     		e.preventDefault();
			$(this).parents("form").find('[submit=submit]').click();  
   		}
	});

	$(this).each(function () {
		$(this).attr("submit", "submit");
		var method = $(this).parents("form").attr('method');
		$(this).click(function() {
			var katt = $(this);
			var link = $(this).parents("form").attr('action');
			$.ajax({
				url: link,
				type: method,
				dataType: "json",
				data: $(this).parents("form").serialize(),
				success: function(data){
					if(data.reload) {
						if(data.reload == "this")
							window.location.href=window.location.href.split('#')[0];
						else
							window.location.href=data.reload;
						return false;
					}
					else if(data.error) { 
						popupWindow(data.error); 
					}
					else if(data.info) {
						popupWindow(data.info); 
					}
					if(data.callback) {
						eval(data.callback+"(data.data);");
					}
				}
			});
			return false;
		});
		$('<input type="submit" name="submit" value="submit" />').css('display', 'none').insertAfter($(this));
		$(this).parents("form").submit(function () {
			$(this).find('[submit=submit]').click();
			return false;
		});
	});
};
