function do_search(type, cmd, id) {
    $(".prod_results").fadeTo(300, 0, function() {
	ajax_cmd('search', type, cmd, id);
    });
}

function set_price(type) {
    if($("#price_from").val() != '') ajax_cmd('search2', type, 'change_from', $("#price_from").val());
    else ajax_cmd('search2', type, 'change_from', 0);
    if($("#price_to").val() != '') ajax_cmd('search2', type, 'change_to', $("#price_to").val());
    else ajax_cmd('search2', type, 'change_to', 0);
    do_search(type, '', '');
}

function change_search(type, cmd, obj, id) {
    if(obj.attr("src") == '/images/box.png') {
	obj.attr("src", '/images/boxc.png');
	do_search(type, 'add_' + cmd, id);
    } else {
	obj.attr("src", '/images/box.png');
	do_search(type, 'del_' + cmd, id);
    }
}

function rotate_offers() {
    $(".offer_right2").click();
    setTimeout('rotate_offers();', 6000);
}

﻿$(document).ready(function() {

	$(".menu_item_bg").css("opacity", 0.8);
	$(".menu_bg").css("opacity", 0.8);
	$(".menu_line").css("opacity", 0.6);
	
	$("#header_logo").click(function() { window.location = '/'; });
	
	$(".menu").hover(
		function() {
			$(this).find(".menu_items").css("display", "block");
			if($(this).find(".menu_items").width() < $(this).width()) $(this).find(".menu_items").width($(this).width());
			$(this).find(".menu_item_bg").width($(this).find(".menu_items").width());
			$(this).find(".menu_item_bg").height($(this).find(".menu_items").height());
			$(".menu_line").each(function() { $(this).width($(this).parent().width()-4); });
		}, function() {
			$(this).find(".menu_items").css("display", "none");
		}
	);
	
	$("#reg_newsletter").click(function() {
		if($(this).val() == 'Az Ön e-mail címe') $(this).val('');
	});
	
	$("#reg_newsletter").blur(function() {
		if($(this).val() == '') $(this).val('Az Ön e-mail címe');
	});
	
	$(".newsletter_ok").click(function() {
	    ajax_cmd('newsletter', $("#reg_newsletter").val());
	});
	
	$("#login_password").click(function() {
		$(this).val('');
	});
	
	$("#login_username").click(function() {
		if($(this).val() == 'felhasználói név') $(this).val('');
	});
	
	$("#login_username").blur(function() {
		if($(this).val() == '') $(this).val('felhasználói név');
	});
	
	if($.browser.msie) { 
		if($.browser.version == '6.0') {
			$("#left_box").css("margin-left", "10px");
			$("#pop_menu").css("left", "271px");
			$("#login_box").css("right", "39px");
			$("#main_offers").pngFix();
			$("#small_offers").pngFix();
			$(".discount").pngFix();
			$(".offer_right").css("right", "-5px");
		}
	} else if($.browser.safari) {
		$("#pop_menu > .menu").css("font-size", "11px");
		$("#pop_menu > .menu").css("margin-right", "5px");
		$(".menu_name").css("padding-top", "10px");
		$(".menu_name").css("padding-right", "34px");
		$(".menu_name > img").css("top", "9px");
		$(".menu_name > img").css("right", "10px");
		$("#login_box").css("top", "37px");
		$(".small_orange_menu > .menu").css("font-size", "11px");
		$(".small_blue_menu > .menu").css("font-size", "11px");
	} else if($.browser.opera) {
		$(".menu_items > a").css("color", "#ffffff");
	}

	$(".menu_bg").each(function() {
		$(this).width($(this).parent().width());
	});
	
	$(".subcats").each(function() {
		$(this).parent().attr("rel", $(this).height());
		$(this).css("height","0px");
	});
	
	$(".catn").click(function() {
		if($(this).parent().find(".subcats").height() == 0) {
			$(".subcats").each(function() {
				if($(this).height() > 0) {
					$(this).animate({
						height: '0px'
					}, 300, function() {
						//$(this).css("height", "0px");
					});
					
					$(this).parent().find(".catn").animate({
						backgroundColor: "#e5e5e5"
					});
					$(this).parent().find(".catn").find("img").attr("src", "/images/cat_plus.png");
				}
			});
			
			$(this).parent().find(".subcats").animate({
				height: $(this).parent().attr("rel") + 'px'
			}, 300);
			$(this).find("img").attr("src", "/images/cat_minus.png");
			$(this).css("background-color", "#cfc7bb");
		} else {
			$(this).find("img").attr("src", "/images/cat_plus.png");
			$(this).parent().find(".subcats").animate({
				height: '0px'
			}, 300, function() {
				//$(this).parent().find(".subcats").css("height", "0px");
				$(this).parent().find(".catn").css("background-color", "#e5e5e5");
			});
//			$(this).css("background-color", "#cfc7ba");
//			$(this).css("background-color", "#e5e5e5");
		}
	});
	
	$(".catn").hover(
		function() {
			if(($(this).css("background-color") != 'rgb(207, 199, 187)') && ($(this).css("background-color") != '#cfc7bb')) $(this).css("background-color", "#cfc7ba");
		}, function() {
			if(($(this).css("background-color") != 'rgb(207, 199, 187)') && ($(this).css("background-color") != '#cfc7bb')) $(this).css("background-color", "#e5e5e5");
		}
	);
	
	$(".subcat").hover(
		function() {
			$(this).css("background-color", "#cfc7ba");
		}, function() {
			$(this).css("background-color", "#dddbd7");
		}
	);
	
	$(".subcat").each(function() {
	    $(this).click(function() {
		window.location = $(this).find("a").attr("href");
	    });
	});
	
	$(".wish_item > .item_form").find("img").click(function() {
		if($(this).attr("src") == '/images/box.png') $(this).attr("src", "/images/boxc.png");
		else $(this).attr("src", "/images/box.png");
	});
	
	var offers = [];
	
	$(".offer_trunk").each(function() {
		offers[offers.length] = $(this).find("img").attr("src");
	});
	
	var acto = 0;
	
	$(".offer_right").click(function() {
		if(acto+1 > offers.length-1) {
			acto = 0;
		} else {
			acto++;
		}
		$(".offer_obj").fadeTo(300, 0, function() {
		$(".offer_trunk").each(function() {
			if(offers[acto] == $(this).find("img").attr("src")) {
			    $(".offer_obj").html($(this).html());
			    $(".offer_obj").fadeTo(300, 1);
			}
		    });
		});
	});
	
	$(".offer_left").click(function() {
		if(acto == 0) {
			acto = offers.length-1;
		} else {
			acto = acto-1;
		}
		$(".offer_obj").fadeTo(300, 0, function() {
		$(".offer_trunk").each(function() {
			if(offers[acto] == $(this).find("img").attr("src")) {
			    $(".offer_obj").html($(this).html());
			    $(".offer_obj").fadeTo(300, 1);
			}
		    });
		});
	});


	var offers2 = [];
	
	$(".offer_trunk2").each(function() {
		offers2[offers2.length] = $(this).find("img").attr("src");
	});
	
	var acto2 = 0;
	
	$(".offer_right2").click(function() {
		if(acto2+1 > offers2.length-1) {
			acto2 = 0;
		} else {
			acto2++;
		}
		$(".offer_obj2").fadeTo(300, 0, function() {
		$(".offer_trunk2").each(function() {
			if(offers2[acto2] == $(this).find("img").attr("src")) {
			    $(".offer_obj2").html($(this).html());
			    $(".offer_obj2").fadeTo(300, 1);
			}
		    });
		});
	});
	
	$(".offer_left2").click(function() {
		if(acto2 == 0) {
			acto2 = offers2.length-1;
		} else {
			acto2 = acto2-1;
		}
		$(".offer_obj2").fadeTo(300, 0, function() {
		$(".offer_trunk2").each(function() {
			if(offers2[acto2] == $(this).find("img").attr("src")) {
			    $(".offer_obj2").html($(this).html());
			    $(".offer_obj2").fadeTo(300, 1);
			}
		    });
		});
	});
	
	setTimeout('rotate_offers();', 6000);
	
	$("#login_form").find("img").click(function() {
	    ajax_cmd('login', $("#login_username").val(), $("#login_password").val());
	});
	
	$("#login_form2").find("img").click(function() {
	    ajax_cmd('login', $("#login_username2").val(), $("#login_password2").val());
	});
	
        $("#login_username, #login_password").keydown( function(event) {
                if(event.keyCode == 13) {
		    $("#login_form").find("img").click();
		}
	});
	
	$("#popup_msg_bg").css("opacity", 0.7);
	$("#popup_msg_bg").css("height", $(document).height());
	
	$("#popup_msg_bg, #popup_msg_data").fadeIn(1000);
	
	$("#popup_msg_button").click(function() {
	    $("#popup_msg_data, #popup_msg_bg").fadeOut(1000, function() {
		$("#popup_msg_data, #popup_msg_bg").remove();
	    });
	});
	
	$(".add_wish").click(function() {
	    if($(this).parent().find("input[name^='id']").val()) {
		ajax_cmd('add_wish', $(this).parent().find("input[name^='id']").val());
	    } else {
		ajax_cmd('add_wish', $(this).parent().parent().find("input[name^='id']").val());
	    }
	    window.location = '#core';
	});
	
	$(".add_basket").click(function() {
	    if($(this).parent().find("input[name^='id']").val()) {
		ajax_cmd('add_basket', $(this).parent().find("input[name^='id']").val());
	    } else {
		ajax_cmd('add_basket', $(this).parent().parent().find("input[name^='id']").val());
	    }
	    window.location = '#core';
	});

	$(".add_basket2").click(function() {
	    if($("#prod_size").val() == 'null') {
		alert('Elfelejtettél méretet választani!');
	    } else {
		ajax_cmd('add_basket2', $(this).parent().parent().find("input[name^='id']").val(), $("#prod_size").val());
	    }		
	    window.location = '#core';
	});

	$(".pack_all .basket").click(function() {
	    var id = $(".prod_results input[name='id']").val();
	    
	    if($(".size1").val() == '' || $(".size2").val() == '' || $(".size3").val() == '') {
		alert('Minden terméknél válaszd ki a méretet!');
	    } else {
		ajax_cmd('add_basket3', id, $(".size1").val(), $(".size2").val(), $(".size3").val());
	    }
	    window.location = '#core';
	});
	
	$(".reg_right > input").keyup(function() {
	    if($(this).val()) {
		if($(this).parent().parent().parent().hasClass("order")) ajax_cmd('reg_check', $(this).attr("id"), $(this).val(), 1);
		else ajax_cmd('reg_check', $(this).attr("id"), $(this).val());
	    }
	});
	
	$(".reg_right > input").blur(function() {
	    if($(this).val()) {
		if($(this).parent().parent().parent().hasClass("order")) ajax_cmd('reg_check', $(this).attr("id"), $(this).val(), 1);
		else ajax_cmd('reg_check', $(this).attr("id"), $(this).val());
	    }
	});
	
	$("#reg_same").click(function() {
	    if($(this).attr("src") == '/images/box.png') {
		$(this).attr("src", "/images/boxc.png");
		$("#reg_name2").val($("#reg_name").val()); $("#reg_name2").keyup();
		$("#reg_city2").val($("#reg_city").val()); $("#reg_city2").keyup();
		$("#reg_address2").val($("#reg_address").val()); $("#reg_address2").keyup();
		$("#reg_zip2").val($("#reg_zip").val()); $("#reg_zip2").keyup();
	    } else {
		$(this).attr("src", "/images/box.png");
		$("#reg_name2").val(' '); $("#reg_name2").keyup();
		$("#reg_city2").val(' '); $("#reg_city2").keyup();
		$("#reg_address2").val(' '); $("#reg_address2").keyup();
		$("#reg_zip2").val(' '); $("#reg_zip2").keyup();
	    }
	});
	
	if($("#prod_images").length > 0) {
	    $("#prod_images > img").css("opacity", 0).css("display", "block");
	    var i = 0;
	    $("#prod_images > img").each(function() {
		if(i == 0) $(this).css("opacity", 1);
		i++;
	    });
	    $("#prod_thumbs > img").click(function() {
		var i = 0;
		var src = $(this).attr("src");
		$("#prod_thumbs > img").each(function() {
		    i++;
		    if(src == $(this).attr("src")) {
			var j = 0;
			var actn;
			var act; 
			$("#prod_images > img").each(function() {
			    j++;
			    if($(this).css("opacity") == 1) act = $(this);
			    if(j == i) actn = $(this);
			});
			if(actn.attr("src") != act.attr("src")) {
			    act.fadeTo(300, 0);
			    actn.fadeTo(300, 1);
			}
		    }
		});
	    });
	}
	
	$(".wish_buttons > img").click(function() {
	    var i = 0;
	    var j = 0;
	    $(".wish_item").each(function() {
		j++;
		var wish = Array();
		if($(this).find(".item_form > img").attr("src") == '/images/boxc.png') {
		    wish[i] = $(this).find("input").val();
		    ajax_cmd('add_basket', $(this).find("input").val());
		    ajax_cmd('del_wish', $(this).find("input").val());
		    $(this).animate({
			height: '0px',
			opacity: 0
		    }, 500, function() {
			$(this).remove();
		    });
		    i++;
		}

	    });
	    if(i == j) {
	        $("#wishlist_box").css("overflow", "hidden");
	        $("#wishlist_box").animate({
		    height: '0px',
		    opacity: 0,
		    marginBottom: '0px'
		}, 500, function() {
		    $(this).css("visibility", "hidden");
		});
	    }
	});

	$(".prod_results").css("opacity", 1);
	
	$(".filter_header > .button > img").click(function() {
	    if($(this).attr("src") == '/images/filter_down.png') {
		$(this).attr("src", "/images/filter_up.png");
		$(".prod_filters").animate({
		    height: $(".prod_filters > .filters").height()+84
		});
	    } else {
		$(this).attr("src", "/images/filter_down.png");
		$(".prod_filters").animate({
		    height: '69px'
		});
	    }
	});

	$(".page").hover(
	    function() {
		$(this).css("background-color", "#e2e2e2");
	    }, function() {
		$(this).css("background-color", "#ffffff");
	    }
	);

	$(".item_del > img").click(function() {
	    $(this).parent().parent().animate({
		height: '0px'
	    }, 500, function() {
		ajax_cmd('del_basket', $(this).find("input").val());
		$(this).remove();
	    });
	});
	
	var dc = $("#prod_docomment").height();
	
	$("#prod_docomment > .title").click(function() {
	    $(this).parent().animate({
		height: dc
	    }, 300, function() {
		$(this).find(".title").css("cursor", "default");
		
	    });
	});
	
	$("#prod_docomment").css("display","block").height(14);
	
	$(".comment_ok > img").click(function() {
	    var t = 0;
	    $(".form_rate").each(function() {
		if($(this).attr("checked") == true) t = 1;
	    });
	    if(t == 0) alert('Elfelejtettél értékelést választani!');
	    else if($("#form_comment").val() == '') alert('Elfelejtettél megjegyzést írni!');
	    else $("#comment_form").submit();
	});
	
	$('.flash').media({ width: 431, height: 214, params: { wmode: 'transparent'} });

	$("#random_prods > table").css("opacity", 0);
	var rc = 0;
	$("#random_prods > table").each(function() {
	    if(rc == 0) {
		$(this).css("display","block").css("opacity", 1);
		$("#random_prods").height(210);
	    }
	    rc++;
	});
	
	$(".small_blue_menu > .menu").click(function() {
		var tmp = $(this).html();
		var rc = 0;
		var fin = 0;
		$(".small_blue_menu > .menu").each(function() {
		    if($(this).html() == tmp) fin = rc;
		    rc++;
		});
		var pr = 0;
		$("#random_prods > table").each(function() {
		    if($(this).css("display") == 'block') 
			if(pr != fin) $(this).fadeTo(300, 0, function() { $(this).css("display", "none"); });
		    pr++;
		});
		var rc = 0;
		$("#random_prods > table").each(function() {
		    if(rc == fin) {
			$(this).css("display", "block").fadeTo(300, 1);
			$("#random_prods").height($(this).height()+10);
		    }
		    rc++;
		});
	});
	
	$("#action_prods > table").css("opacity", 0);
	var ac = 0;
	$("#action_prods > table").each(function() {
	    if(ac == 0) {
		$(this).css("display","block").css("opacity", 1);
		$("#action_prods").height(220);
	    }
	    ac++;
	});
	
	$(".small_orange_menu > .menu").click(function() {
		var tmp = $(this).html();
		var ac = 0;
		var fin = 0;
		$(".small_orange_menu > .menu").each(function() {
		    if($(this).html() == tmp) fin = ac;
		    ac++;
		});
		var pr = 0;
		$("#action_prods > table").each(function() {
		    if($(this).css("display") == 'block') 
			if(pr != fin) $(this).fadeTo(300, 0, function() { $(this).css("display", "none"); });
		    pr++;
		});
		var ac = 0;
		$("#action_prods > table").each(function() {
		    if(ac == fin) {
			$(this).css("display", "block").fadeTo(300, 1);
			$("#action_prods").height($(this).height()+10);
		    }
		    ac++;
		});
	});
	
	$(".brand_logo").hover(
	    function() {
//		$(this).attr("id").replace("logo_", "");
		$(this).attr("src", $(this).attr("src").replace("_1", "_2"));
	    }, function() {
		$(this).attr("src", $(this).attr("src").replace("_2", "_1"));
	    }
	);
	
	$(".brand_logo").click(function() {
	    var tmp = $(this).attr("id").replace("logo_", "");
	    var not = 0;
	    $(".subcat > a").each(function() {
		if(($(this).attr("href").indexOf("/marka/" + tmp + "_") != -1) && (not != 1)) {
		    $(this).parent().parent().parent().find(".catn").click();
		    not = 1;
		}
	    });
	});
	
});
