/*
 Color animation jQuery-plugin
 http://www.bitstorm.org/jquery/color-animation/
 Copyright 2011 Edwin Martin <edwin@bitstorm.org>
 Released under the MIT and GPL licenses.
*/
(function(d){function i(){var b=d("script:first"),a=b.css("color"),c=false;if(/^rgba/.test(a))c=true;else try{c=a!=b.css("color","rgba(0, 0, 0, 0.5)").css("color");b.css("color",a)}catch(e){}return c}function g(b,a,c){var e="rgb"+(d.support.rgba?"a":"")+"("+parseInt(b[0]+c*(a[0]-b[0]),10)+","+parseInt(b[1]+c*(a[1]-b[1]),10)+","+parseInt(b[2]+c*(a[2]-b[2]),10);if(d.support.rgba)e+=","+(b&&a?parseFloat(b[3]+c*(a[3]-b[3])):1);e+=")";return e}function f(b){var a,c;if(a=/#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/.exec(b))c=
[parseInt(a[1],16),parseInt(a[2],16),parseInt(a[3],16),1];else if(a=/#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])/.exec(b))c=[parseInt(a[1],16)*17,parseInt(a[2],16)*17,parseInt(a[3],16)*17,1];else if(a=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(b))c=[parseInt(a[1]),parseInt(a[2]),parseInt(a[3]),1];else if(a=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9\.]*)\s*\)/.exec(b))c=[parseInt(a[1],10),parseInt(a[2],10),parseInt(a[3],10),parseFloat(a[4])];return c}
d.extend(true,d,{support:{rgba:i()}});var h=["color","backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","outlineColor"];d.each(h,function(b,a){d.fx.step[a]=function(c){if(!c.init){c.a=f(d(c.elem).css(a));c.end=f(c.end);c.init=true}c.elem.style[a]=g(c.a,c.end,c.pos)}});d.fx.step.borderColor=function(b){if(!b.init)b.end=f(b.end);var a=h.slice(2,6);d.each(a,function(c,e){b.init||(b[e]={a:f(d(b.elem).css(e))});b.elem.style[e]=g(b[e].a,b.end,b.pos)});b.init=true}})(jQuery);

(function($){$.InFieldLabels=function(label,field,options){var base=this;base.$label=$(label);base.$field=$(field);base.$label.data("InFieldLabels",base);base.showing=true;base.init=function(){base.options=$.extend({},$.InFieldLabels.defaultOptions,options);base.$label.css('position','absolute');base.$label.css('display','block');var fieldPosition=base.$field.position();base.$label.css({'left':fieldPosition.left,'top':fieldPosition.top}).addClass(base.options.labelClass);if(base.$field.val()!=""){base.$label.hide();base.showing=false;};base.$field.focus(function(){base.fadeOnFocus();}).blur(function(){base.checkForEmpty(true);}).bind('keydown.infieldlabel',function(e){base.hideOnChange(e);}).change(function(e){base.checkForEmpty();}).bind('onPropertyChange',function(){base.checkForEmpty();});};base.fadeOnFocus=function(){if(base.showing){base.setOpacity(base.options.fadeOpacity);};};base.setOpacity=function(opacity){base.$label.stop().animate({opacity:opacity},base.options.fadeDuration);base.showing=(opacity>0.0);};base.checkForEmpty=function(blur){if(base.$field.val()==""){base.prepForShow();base.setOpacity(blur?1.0:base.options.fadeOpacity);}else{base.setOpacity(0.0);};};base.prepForShow=function(e){if(!base.showing){base.$label.css({opacity:0.0}).show();base.$field.bind('keydown.infieldlabel',function(e){base.hideOnChange(e);});};};base.hideOnChange=function(e){if((e.keyCode==16)||(e.keyCode==9))return;if(base.showing){base.$label.hide();base.showing=false;};base.$field.unbind('keydown.infieldlabel');};base.init();};$.InFieldLabels.defaultOptions={fadeOpacity:0.5,fadeDuration:300,labelClass:'infield'};$.fn.inFieldLabels=function(options){return this.each(function(){var for_attr=$(this).attr('for');if(!for_attr)return;var $field=$("input#"+for_attr+"[type='text'],"+"input#"+for_attr+"[type='password'],"+"textarea#"+for_attr);if($field.length==0)return;(new $.InFieldLabels(this,$field[0],options));});};})(jQuery);

$(document).ready(function(){

    $('.valuelabel').valueLabel(true);
	
	/* var dokutar_item_height = $('#dokutar li:first').height();
	$('#dokutar .directory').click(function() {
		var sub_items = $(this).next().children('li').length;
		$(this).addClass('expanded');
		$(this).parent().css({height:'auto'});
		$(this).next().stop().animate({height:sub_items*dokutar_item_height}, 500, 'easeOutCubic', function() {
		  	$(this).css({height:'auto'});	
		});
		$(this).parent().nextAll().stop().animate({height:dokutar_item_height}, 500, 'easeOutCubic');
		$(this).parent().prevAll().stop().animate({height:dokutar_item_height}, 500, 'easeOutCubic');
		$(this).next().children('li').height(dokutar_item_height);

		return false;
	});
*/
				$('#dokutar').fileTree({ root: '', script: '/dokumentumtar/konyvtar', multiFolder: false ,folderEvent: 'click', expandSpeed: 750, collapseSpeed: 750, expandEasing: 'easeOutBounce', collapseEasing: 'easeOutBounce', loadMessage: 'Kis türelmet...' }, function(file) { 
					window.location = "/dokumentumtar/letolt/"+file;
				});

    $('#new_prod_list').show();
	$('.discount_row').each(function() {
	 	var name_height = 0;
		var price_height = 0;
		$('.discount_prod_item', this).each(function() {
			if($('.discount_item_name', this).height() > name_height)
			 	name_height = $('.discount_item_name', this).height();	
			if($('.discount_item_price', this).height() > price_height)
			 	price_height = $('.discount_item_price', this).height();	
		});
		$('.discount_prod_item', this).each(function() {
			$('.discount_item_name', this).height(name_height);	
			$('.discount_item_price', this).height(price_height);	
		});
	});
	$('#new_prod_list').hide();  

    $("input.required_product").click(function(e){
        var id=$(this).val();
        if($(this).is(":checked")){
            $('#rq_h_'+id).show();
        }else{
            $('#rq_h_'+id).hide();
        }
    }).each(function(e){
        var id=$(this).val();
        if($(this).is(":checked")){
            $('#rq_h_'+id).show();
        }else{
            $('#rq_h_'+id).hide();
        }
    });
	
	$('.news_more').each(function() {
	 	if($(this).height() > 60) {
	 	   	var btn = $('.more_btn:first').clone();
			btn.show().insertAfter(this);	
			$(this).height(60);	 
	 	}
		
	});
	$('.more_btn').click(function() { 
		if($(this).prev().height() > 60) {
		 	$(this).prev().stop(true, true).animate({height:60},500,'easeOutCubic');
			$('a', this).text("Teljes hír"); 	
		}
		else {
			$(this).prev().height('auto');
			var height = $(this).prev().height();
			$(this).prev().height(60);  
		   	$(this).prev().stop(true, true).animate({height:height},500,'easeOutCubic');
			$('a', this).text("Bezárás"); 
		}
		return false;
	});
	
    
    var gen = 0;
    var cc = $("#image_switcher_images_wrapper a").length - 1;
    $("#image_switcher_images_wrapper").css({width:(cc+1)*43});
    var chk=function(){
       if(gen>=(cc-3)){
            $("#image_switch_right").css({backgroundPosition:"0 -250px",cursor:'default'});
       }else{
            $("#image_switch_right").css({backgroundPosition:"center center",cursor:'pointer'});
       }
       
       if(gen>0){
            $("#image_switch_left").css({backgroundPosition:"center center",cursor:'pointer'});
       }else{
            $("#image_switch_left").css({backgroundPosition:"0 -250px",cursor:'default'});
       }
    };
    chk();
    var rotateleft = function() {
            if(gen<(cc-3)){
                gen++;
                var cs = gen * 43;
                $("#image_switcher_images").animate({scrollLeft:cs}, 400, function() {chk();});
            }
         };
     
     var rotateright = function() {
            if(gen>0){
               gen--;
               var cs = gen * 43;
               $("#image_switcher_images").animate({scrollLeft:cs}, 400, function() {chk();});
            }
         };         

         
     $("#image_switch_right").click(function(e){
        e.preventDefault();
        e.stopPropagation();
        rotateleft();
     });
     $("#image_switch_left").click(function(e){
        e.preventDefault();
        e.stopPropagation();
        rotateright();
     });    
    
    $("a[rel='fancybox']").fancybox({
				transitionIn	: 'none',
				transitionOut	: 'none'
			});
			
	
	$("a[rel='fancypopup1']").fancybox({
		'width'				: '75%',
		'height'			: '75%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$("a[rel='fancypopup2']").fancybox({
		'width'				: '75%',
		'height'			: '75%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});

    $(".tooltipped").each(function(i,e){
        var tooltip=$(e).attr('title');
        $(e).attr('title','');
        $(e).qtip({
        content: tooltip,
        position: {
                  corner: {
                     tooltip: 'bottomLeft', 
                     target: 'topMiddle' 
                  }
               },
       style: {
          border: {
             width: 5,
             radius: 10
          },
          padding: 10, 
          textAlign: 'center',
          tip: true, 
          name: 'blue' 
        }
        });    
    });     
    
       $('.keszlet').qtip({
         content: '<div class="red_dot" title="Szállítás: 1-6 munkanap"></div>Szállítás: 1-6 munkanap<br/><div class="orange_dot" title="Termék fogyóban"></div>Termék fogyóban<br/><div class="green_dot" title="Készleten"></div>Készleten<br/><div class="green_dot" title="Termék bőven"></div><div class="green_dot" title="Termék bőven"></div>Termék bőven',
         position: {
                  corner: {
                     tooltip: 'bottomLeft', 
                     target: 'topLeft' 
                  }
               },
       style: {
          border: {
             width: 5,
             radius: 10
          },
          padding: 10, 
          textAlign: 'center',
          tip: true, 
          name: 'blue' 
        }
       });

    
	set_sp_events();
		$("a[rel='ertekeles']").click(function(e) {
		e.preventDefault();
		$("#ertekeles").show();
	});

	
	$("#store_product_link").click(function(e){
	
		e.preventDefault();
				
		var p_id = $(this).attr("rel");
		
		refresh_stored_products({add : p_id, type: 'saved', active_tab: 'saved'});	
	
	});
	
	$(".store_product_link").click(function(e){
	
		e.preventDefault();
				
		var p_id = $(this).attr("rel");
		
		refresh_stored_products({add : p_id, type: 'saved', active_tab: 'saved'});	
	
	});
	
	$("input[class='top_login']").keyup(function(e){
	
		if(e.keyCode == 13) 
		{   	      	
	      	$("form[name='login_form']").submit();      	
	    }
	
	});

	$(".submit_button").click(function(e){
	
		e.preventDefault();
		
		$("form[name='" +  $(this).attr("rel") + "']").submit();
	
	});

	$("#reg_submit").click(function(e){
	
		e.preventDefault();
		
		$("form[name='reg_form']").submit();
	
	});

	
	$("a[rel='discount_items']").click(function(e){

		e.preventDefault();

		$("#new_prod_list").hide();
		$("#new_prod_container").hide();

		$("#discount_prod_list").show();
		$("#discount_prod_container").show();

		$(this).parent().removeClass().addClass("tab_style1_right");

		$(this).parent().parent().removeClass().addClass("tab_style1_left");

		$(this).parent().parent().parent().removeClass().addClass("tab_style1_content");

		$(this).parent().parent().parent().next().removeClass().addClass("tab_style2_content");

		$(this).parent().parent().parent().next().children().removeClass().addClass("tab_style2_left");

		$(this).parent().parent().parent().next().children().children().removeClass().addClass("tab_style2_right");

	});

	$("a[rel='new_items']").click(function(e){

		e.preventDefault();

		$("#discount_prod_list").hide();
		$("#discount_prod_container").hide();

		$("#new_prod_list").show();
		$("#new_prod_container").show();

		$(this).parent().removeClass().addClass("tab_style1_right");

		$(this).parent().parent().removeClass().addClass("tab_style1_left");

		$(this).parent().parent().parent().removeClass().addClass("tab_style1_content");

		$(this).parent().parent().parent().prev().removeClass().addClass("tab_style2_content");

		$(this).parent().parent().parent().prev().children().removeClass().addClass("tab_style2_left");

		$(this).parent().parent().parent().prev().children().children().removeClass().addClass("tab_style2_right");

	});

	



	$("a[rel='next_tab']").click(function(e){

		e.preventDefault();

		$("a[rel='next_tab']").parent().removeClass("active_tab").addClass("default_tab");

		$(this).parent().addClass("active_tab").removeClass("default_tab");

		$("div[class='tab_content']").hide();

		$("div[id='" + $(this).attr("href").slice(1) + "']").show();

	});

	

	$("a[rel='next_tab_2']").click(function(e){

		e.preventDefault();

		$("a[rel='next_tab_2']").parent().removeClass("active_tab").addClass("default_tab");

		$(this).parent().addClass("active_tab").removeClass("default_tab");

		$("div[class='tab_content']").hide();

		$("div[id='" + $(this).attr("href").slice(1) + "']").show();

	});

	

	$("a[rel='gyik']").click(function(e) {

		e.preventDefault();

		$(".gyik_a").hide();

		$(this).parent().next().show();

	});

	

	$("a[rel='print']").click(function(e) {

		e.preventDefault();

		$("#printbox").show();

	});

	$("#printbox").mouseleave(function(e) {

		e.preventDefault();

		$(this).delay(1500).fadeOut(600);

	});


    $("a[rel='productContent']").click(function(e){
		e.preventDefault();
		$(".productDeliveryContent").slideUp();
		$(".productDeliveryTitle").removeClass("productDeliveryTitleUp").addClass("productDeliveryTitleDown");
		$(this).parent().removeClass("productDeliveryTitleDown").addClass("productDeliveryTitleUp");
		$(this).parent().next().slideDown();
	});


    $('a[rel ^= "to_basket_"]').click(function (e){ 
    	var cartpopup = $(this).hasClass('cartpopup');
        e.preventDefault();
        e.stopPropagation();

        var rec_prod_ids = new Array();
        if($("input.required_product").length > 0)
        {
            var cv = 0;
            var every_cb_ok = true;
            $.each($("input.required_product"), function(key, value){
                
                if(!$(value).is(":checked"))
                {
                    every_cb_ok = false;
                }
                else
                {
                    var reqid=$(value).val();
                    rec_prod_ids[cv] = reqid+'|'+$('#rq_'+reqid).val();
                    cv++;
                }

            });

/*
             if(!every_cb_ok)
             {
                 if(!confirm("A termék működésképtelen a felsorolt tartozékok nélkül, biztosan ki akarja hagyni a nem kiválasztott tartozékokat?"))
                 {
                     return false;
                 }
             }
 */

        }
        
        var amount=$('input[name = "'+$(this).attr('rel')+'"]').val();
        var id=$(this).attr('rel').slice(10);
        var add_type=$('input[name="type_'+id+'"]').val();
        if(add_type == "set")
			var url = "/kosar/add";
		else
			var url = "/kosar/add";
        $.post(url, { 'id': id, 'amount': amount, 'type' : add_type, 'rec_prod_ids' : rec_prod_ids },
            function (data) { 
            	if (data.status == 'ok' && cartpopup) {
            	 	popupWindow(data.message); 
					$('#logo').next().next().html("<p> </p><p>"+data.count+" tétel</p><p>"+data.sum+" Ft</p>");	
            	}
                else if (data.status == 'ok')
                {
                    window.location = '/kosar';    
                }
                else if(data.status == 'recommended_categories')
                {
                     window.location = '/kiegeszito-kategoriak/'+data.id;
                }
                else
                {
                    popupWindow(data.message);
                }
            },
            "json");
			
			
    });
	
    
    
    //TAB BEÁLLÍTÓ SZUPERFUNKCIÓK 
    $("div[id^='tab_content_']:first").show();
    $("a[rel='next_tab_2']:first").parent().removeClass('default_tab').addClass('active_tab');
    
    
    //PRODUCT RATER
    $("ul[id^='pr'] > li > a").click(function(e){
        e.preventDefault();
        e.stopPropagation();
        var r_name=$(this).parent().parent().attr('id');
        var r_rate=$(this).text();
        var r_links=$("ul[id='"+r_name+"'] > li > a");
        $(r_links).removeClass('selected');
        for(var i=0;i<r_rate;i++){
            $(r_links[i]).addClass('selected');
        }
        $("input[name='rate["+r_name+"]']").val(r_rate);
    }).mouseenter(function(e){
        e.preventDefault();e.stopPropagation();
        $("ul[id='"+$(this).parent().parent().attr('id')+"'] > li > a").removeClass('selected');
    }).mouseleave(function(e){
        e.preventDefault();
        e.stopPropagation();
        var r_name=$(this).parent().parent().attr('id');
        var r_links=$("ul[id='"+r_name+"'] > li > a");
        $(r_links).removeClass('selected');
        var r_rate=$("input[name='rate["+r_name+"]']").val();
        for(var i=0;i<r_rate;i++){
            $(r_links[i]).addClass('selected');
        }
    });
    
    if($(".identical_with_the_billing_data").length > 0)
    {
        $(".identical_with_the_billing_data").click(function(){
            
            if($(this).is(":checked"))
            {
                $("#shipping_name").val($("#bill_name").val());
                $("#shipping_code").val($("#bill_code").val());
                $("#shipping_city").val($("#bill_city").val());
                $("#shipping_street").val($("#bill_street").val());
            }
            else
            {
                /*$("#shipping_name").val('');
                $("#shipping_code").val('');
                $("#shipping_city").val('');
                $("#shipping_street").val('');*/
            }
        });
    }

    if($("[name=shipping_mode]").length > 0)
    {
        $("[name=shipping_mode]").click(function(){
            enable_pay_modes($(this).val());
        });
        
        enable_pay_modes($("[name=shipping_mode]").val());
    }
    if(jQuery.url.attr("anchor")) $("a[href='#"+jQuery.url.attr("anchor")+"']").click();
	
	compareGroupFormat();
   	initCompareArrows();
	
	$('.compare_next, .compare_prev').click(function() {
		var _current = $('.compare_group:visible');
		var _next = $('.compare_group:visible').next('.compare_group');
		var _prev = $('.compare_group:visible').prev('.compare_group');
		if($(this).hasClass('compare_next')) {
			if(_next.length != 0) {
				_current.slideUp(500);
				_next.slideDown(500, function() {
					initCompareArrows();
				});
			}
		}
		else {
			if(_prev.length != 0) {
				_current.slideUp(500);
				_prev.slideDown(500, function() {
					initCompareArrows();
				});
			}
		}
		compareGroupFormat();
		return false;
	});
    
    
    
$("label").inFieldLabels();	
	
});

function initCompareArrows() {
	if($('.compare_group').length < 2) {
		$('.compare_next, .compare_prev').hide();
		return true;
	}
	var _current = $('.compare_group:visible');
	var _next = $('.compare_group:visible').next('.compare_group');
	var _prev = $('.compare_group:visible').prev('.compare_group');
	if(_next.length == 0)
		$('.compare_next').hide();
	else
	 	$('.compare_next').show();
	if(_prev.length == 0)
		$('.compare_prev').hide();
	else
	 	$('.compare_prev').show();	
}

function compareGroupFormat() {
	$('.compare_group:visible').each(function() {
		var cur_group = this;
		_height = {};	
		$('.crow', this).each(function() {
			var rowid = $(this).attr('class').split(' ')[1];
			if(!_height[rowid])
				_height[rowid] = 0;
			if($(this).height() > _height[rowid]) {       
				_height[rowid] = $(this).height();	 
			}
		}); 
		$.each(_height, function(key, val) {
			$('.'+key, cur_group).height(val);		
		});
		var comp_cont_height = 0;
		$('.newcompareContainer2, .newcompareContainer1', this).each(function() {
			if($(this).height() > comp_cont_height)
				comp_cont_height = $(this).height();	
		});
		$('.newcompareContainer2, .newcompareContainer1', this).height(comp_cont_height);
		$('.compare_tul', this).css({marginTop:comp_cont_height+22});
	});
}
  
function enable_pay_modes(shipping_mode_id)
{
	
/*
Átutalás: ha az ügyfélnél enegedélyezve van, futár és személyes átvételnél is látható
Bankkártya: futár és személyes átvételnél is látható
Előre utalás: csak futár
Utánvétel: csak futár, bruttó 1 millió rendelési értékhatár alatt
Személyesen, készpénzben: csak személyes átvételnél

Alapértelmezett kiválasztás:

Kiszállítás
- Átutalás
- ha nem fizethet átutalással és 1 millió alatt van a bruttó rendelési érték, akkor utánvétel
- ha nem fizethet átutalással és 1 millió felett van a bruttó rendelési érték, akkor előre utalás

Személyes átvétel
- Átutalás
- ha nem fizethet átutalással, akkor Személyesen, készpénzben
*/
    var pay_modes = new Array();
    var limit = 1000000;

    if(shipping_mode_id > 0)
    {
        $("#shipping_data > div").slideUp("slow");
        $("#shipping_prices > div").slideUp("slow");
    }
    else
    {
        if($("#shipping_data > div").css("display") == "none")
        {
            $("#shipping_data > div").slideDown("slow");
            $("#shipping_prices > div").slideDown("slow");
        }
    }

    if($("#tax_sum").val() < limit)
    {
        pay_modes[0] = new Array(1,2,3,4);
    }
    else
    {
        pay_modes[0] = new Array(1,2,3); 
    }

    pay_modes[1] = new Array(0,1,2);
    pay_modes[2] = new Array(0,1,2)

    $(".mode_0").css('display','none');
    $(".mode_1").css('display','none');
    $(".mode_2").css('display','none');
    $(".mode_3").css('display','none');
    $(".mode_4").css('display','none');

    $.each(pay_modes[shipping_mode_id], function(index, value){
        $(".mode_"+value).css('display','block');
    });

    if(shipping_mode_id == 0)
    {   
    	if($('.mode_1').length > 0) { 
    	 	$(".mode_1 > input").attr("checked", true); 	
    	}
		else {
	        if($("#tax_sum").val() < limit)
	        { 
	            $(".mode_4 > input").attr("checked", true);
	        }
	        else
	        {
	            $(".mode_3 > input").attr("checked", true);
	        } 
        }
    }
    else
    { 
    	if($('.mode_1').length > 0)
			$(".mode_1 > input").attr("checked", true);
		else 	
        	$(".mode_0 > input").attr("checked", true);
    }
}

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").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()", 3000);
	 
}

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

function refresh_stored_products(send_data)
{
    var add_message=(typeof send_data.add != 'undefined')? 'A terméket sikeresen elmentette!':'A terméket sikeresen törölte!';
	$.post("termek_mentes/frissites", send_data, function(data) {
	
		$("#sp_box").html(data);
		
		set_sp_events();	
		
		popupWindow(add_message);		
	
	});	
}

function set_sp_events()
{	

	$(".sp_pager").click(function(e){
		
		e.preventDefault();		
		
		var r = $(this).attr("rel");
		
		if(r.indexOf("last_seen") != -1)
		{
			var to_hide = $("div[id^=stored_last_seen_]");
			var to_narrow = $(".sp_pager_last_seen");			
		}
		else
		{
			var to_hide = $("div[id^=stored_saved_]");
			var to_narrow = $(".sp_pager_saved");			
		}
		
		$(to_narrow).each(function(i, element){
		
			$(element).removeClass("sp_pager_active");
		
		});
		
		$(this).addClass("sp_pager_active");
		
		$(to_hide).each(function(i, element){
			
			$(element).attr("style", "display:none");
			
		});
		
		$("." + r).each(function(i, element){
		
		 	$(element).attr("style", "display:block");
		 
		 });
							
	
	});

	$(".sp_del").click(function(e){
	
		e.preventDefault();
		
		var to_del = $(this).attr("rel");
		
		if(to_del.indexOf('last_seen_') != -1)
		{
			var p_id = to_del.replace('last_seen_', '');
			var del_type = 'last_seen'; 
		}
		else
		{
			var p_id = to_del.replace('saved_', '');
			var del_type = 'saved'; 
		}		
		
		var a_tab = get_active_tab();
		
		refresh_stored_products({del : p_id, type: del_type, active_tab: a_tab});
	
	});
	
	$("a[rel='r_tab_1']").click(function(e){

		e.preventDefault();

		$("#tab_box_2").hide();

		$("#tab_box_1").show();

		$(this).parent().addClass("right_tab_1_active");

		$(this).parent().next().removeClass("right_tab_2_active");

	});

	$("a[rel='r_tab_2']").click(function(e){

		e.preventDefault();

		$("#tab_box_1").hide();

		$("#tab_box_2").show();

		$(this).parent().addClass("right_tab_2_active");

		$(this).parent().prev().removeClass("right_tab_1_active");

	});	
	
}

function get_active_tab()
{
	if($("#right_tab_2").hasClass("right_tab_2_active"))
		return 2;
	else
		return 1;
}

countBack();

function countBack() {

	var t1 = setTimeout("countBack()", 1000);

	$(".timer").each(function() {    	

		var datas = $(this).html().split(':');
		var days = $("#days_remaining").html();
		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;
			days -= 1;
		}

		if(days < 1 && hour < 1 && minute < 1 && second < 1)
		{
			clearTimeout(t1);
			$("#timer_all").html('Az akció már lejárt!');
			return true;
		}

		hour = convertIntegerToTwoigitString(hour);
		minute = convertIntegerToTwoigitString(minute);
		second = convertIntegerToTwoigitString(second);


		$(this).html(hour + ":" + minute + ":" + second);
		
		$("#days_remaining").html(days);
        
        
        
		
		
	});
		
}

function convertIntegerToTwoigitString(i)
{
	if(i < 10)
		return '0' + String(i);
	else
		return String(i);
}

$.fn.valueLabel = function(setfvalue) {
	$(this).each(function() {
		if(setfvalue == true) {
			var curr_value = $(this).attr('cvalue');
			$(this).attr('fvalue', $(this).val());

			if($(this).attr('type') == 'password') {
				$(this).attr('ftype', 'password');
				var new_input = changeInputType(this, "text");
				//$(new_input).focus();
				$(new_input).valueLabel(false);
				return true;
			}
		}
		$(this).focus(function() {
			if($(this).val() == $(this).attr('fvalue') || $(this).val() == "") {
				$(this).val('');
				if($(this).attr('ftype') == 'password') {
					$(this).attr('ftype', 'password2');
					$(this).unbind('blur');
					var new_input = changeInputType(this, "password");
					$(new_input).attr('ftype', 'password2');
					$(new_input).focus();
					$(new_input).valueLabel(false);
					$(new_input).focus();
				}
			}
		}).blur(function() {
			if($(this).val() == $(this).attr('fvalue') || $(this).val() == "") {
				$(this).val($(this).attr('fvalue'));
				if($(this).attr('ftype') == 'password2') {
					$(this).attr('ftype', 'password');
					var new_input = changeInputType(this, "text");
					$(new_input).attr('ftype', 'password');
					$(new_input).valueLabel(false);
				}
			}
		});
	});
};

function changeInputType(oldObject, oType) {
	var newObject = document.createElement('input');
	newObject.type = oType;
	if(oldObject.size) newObject.size = oldObject.size;
	if(oldObject.value) newObject.value = oldObject.value;
	if(oldObject.name) newObject.name = oldObject.name;
	$(newObject).attr('fvalue', $(oldObject).attr('fvalue'));
	$(newObject).attr('ftype', $(oldObject).attr('ftype'));
	if(oldObject.id) newObject.id = oldObject.id;
	if(oldObject.className) newObject.className = oldObject.className;
	oldObject.parentNode.replaceChild(newObject,oldObject);
	return newObject;
}

$(function() {
	var $container = $('#start_img'),
		$items = $container.find('a'),
		$control = $('#slider_control'),
		$detail = $control.find('a.detail'),
		$triggers = $control.find('a').filter('.trigger'),
		act = 0,
		length = $items.length,		
		timer,
		lock = false,

		slide = function(force) {
			var next;
		
			if (!lock || (typeof force !== 'undefined')) {		
				if (typeof force !== 'undefined') {
					next = force;
				} else {
					next = act + 1;									
				}					
				
				if (next >= length) next = 0;		
											  
				var $act = $items.eq(act),
					$next = $items.eq(next);

				$act.stop().css({ display: 'block', opacity: 1 }).animate({ opacity: 0 }, 500, 'swing', function() {
					$(this).css({ display: 'none' });
				});

				$next.stop().css({ display: 'block', opacity: 0 }).animate({ opacity: 1 }, 500, 'swing');

				act = next;

				$triggers.stop().animate({ backgroundColor: '#108CD2' }, 500, 'swing').eq(act).stop().animate({ backgroundColor: '#474747' }, 500, 'swing');
				$detail.attr('href', $items.eq(act).attr('href'));								                              
			}

			if (timer)
				clearTimeout(timer);
				
			timer = setTimeout(function() { slide(); }, 10000);
		};

	if (!$container.length || ($items.length <= 1)) return;

	$control.show();

	$container.unbind().bind("mouseover", function() { lock = true; })
					   .bind("mouseout", function() { lock = false; });
					   
	$triggers.unbind('click.changeSlider').bind('click.changeSlider', function(e) {
		e.preventDefault();
		slide(parseInt($(this).text(), 10) - 1);
	});

	$triggers.eq(act).css({ backgroundColor: '#474747' });
	$detail.attr('href', $items.eq(act).attr('href'));
	timer = setTimeout(function() { slide(); }, 10000);
});

