﻿$(document).ready(function() {
        if($.browser.msie) {
		$("#header_fix").css("top", "141px");
		$("#core_data").width(996);
	}
	
	$("#search_key").click(function() {
	    if($(this).val() == 'keresés') $(this).val('');
	})
	
	$("#search_key").blur(function() {
	    if($(this).val() == '') $(this).val('keresés');
	});
	
});



$(window).load(function () {
var dir = -1;
var tmpdir = dir;
var i = 0;
function scroll() {

    if(dir == -1) {
        if(parseInt($("#header_scroll > div:first").css("margin-left").replace("px","")) == parseInt($("#header_scroll > div:first").width())*-1) {
	    $("#header_scroll").append("<div>" + $("#header_scroll > div:first").html() + "</div>");
	    $("#header_scroll > div:first").remove();
	}
    } else {
        if(parseInt($("#header_scroll > div:first").css("margin-left").replace("px", "")) == 0) {
    	    $("#header_scroll > div:first").before("<div>" + $("#header_scroll > div:last").html() + "</div>")
	    $("#header_scroll > div:first").css("margin-left", parseInt($("#header_scroll > div:last").width()*-1)+1);
	    $("#header_scroll > div:last").remove();
	}
	
    }
    $("#header_scroll > div:first").animate({
        marginLeft: (parseInt($("#header_scroll > div:first").css("margin-left").replace("px", ""))+dir) + 'px'
    }, 10, "swing", function() {
	scroll();
    });
}
    
	$("#header_left").click(function() {
	    dir = -1;
	});
	
	$("#header_right").click(function() {
	    dir = 1;
	});

	$("#header_scroll").hover(function() {
	    tmpdir = dir;
	    dir = 0;
	}, function() {
	    dir = tmpdir;
	});

	$(".png").pngfix({ sizingMethod: 'scale' });
	$(".prod_image").pngfix();

	$(".preview").media({width: 300, height: 20});
	$(".flv").media({width: 320, height: 264});

	if($("#core_data").height() < 502) $("#core_data").height(502);
	
	$("img[src^='/images/menu_']").each(function() {
			if($(this).attr("src").indexOf('2.png') == -1) {
				$(this).hover(
					function() {
						$(this).attr("src", $(this).attr("src").replace(".png", "2.png"));
					}, function() {
						$(this).attr("src", $(this).attr("src").replace("2.png", ".png"));
				});
			}
	});
	


	
	//alert($("#data_box").height());
	
	if($("#data_box").height() < 350) $("#data_box").height(350);
	
	//if($("#data_box").height() < 250) $("#data_box").height(250);
	$("#data_center").height($("#data_box").height()-229);
	
	
	$("#form_submit").click(function() {
	
	    if($("#order_type").val() == 'null') var error = 'Kérem válasszon szállítási módot!';

	    if($("#order_card").val() == '') var error = 'Kérem adja meg klubkártyája számát!';
	    if($("#order_email").val() == '') var error = 'Kérem adja meg e-mail címét!';
	    if($("#order_phone").val() == '') var error = 'Kérem adja meg telefonszámát!';
	    if($("#order_name").val() == '') var error = 'Kérem adja meg a nevét!';


	    if($("#order_type").val() == 'posta') if($("#order_address").val() == '') var error = 'Kérem adja meg címét!';
	    if($("#order_type").val() == 'pickpack') if($("#order_pack").val() == '') var error = 'Kérem válasszon átvevő pontot!';

	    if(error) alert(error);
	    else $("#form").submit();
	});
	
	$("#order_type").change(function() {
	    if($(this).val() == 'posta') {
		$("#address").show();
		$(".form_block.area").hide();
		$(".form_block.city").hide();
		$(".form_block.pack").hide();
	    }
	    if($(this).val() == 'null') {
		$("#address").hide();
		$(".form_block.area").hide();
		$(".form_block.city").hide();
		$(".form_block.pack").hide();	    
	    }
	    if($(this).val() == 'pickpack') {
		$("#address").hide();
		$(".form_block.area").hide();
		$(".form_block.city").hide();
		$(".form_block.pack").show();
		$(".pack_megye").val('null');
		$(".pack_city").val('null');
		$(".pack_street").val('null');
		$("#order_pack").val('');
	    }
	    if($(this).val() == 'szemelyes') {
		$("#address").hide();
		$(".form_block.area").hide();
		$(".form_block.city").hide();
		$(".form_block.pack").hide();
	    }
	    $("#data_center").height($("#data_box").height()-229);
	});
	
	$(".pack_megye").change(function() {
	    $(".form_block.area").removeClass("active").hide();
	    $(".form_block.city").removeClass("active").hide();
	    $(".pack_city").val('null');
	    $(".pack_street").val('null');
	    $("#order_pack").val('');
	    if($(this).val() != 'null') {
		var area = $(this).val();
		$("#" + area).show().addClass("active");
		$("#data_center").height($("#data_box").height()-229);
	    }
	});
	
	$(".pack_city").change(function() {
	    $(".form_block.city").removeClass("active").hide();
	    $(".pack_street").val('null');
	    $("#order_pack").val('');
	    if($(this).val() != 'null') {
		var city = $(this).val();
		$("#" + city).show().addClass("active");
		$("#data_center").height($("#data_box").height()-229);
	    }
	});
	
	$(".pack_street").change(function() {
	    $("#order_pack").val($(this).val());
	});

	$("#bg").css("opacity", 0.5);
	$("#bg").height(2500);
	
	$("#popup_close").click(function() {
	    $("#popup_window").remove();
	    $("#bg").remove();
	});
	

	scroll();	

});
