function myInitDeliver(html) {
	$(function() {
		var form = $("#theForm").get(0);
		if (!form) return;
		var deliver = form.deliver;
		if (!deliver) return;
		var $deliver = $(deliver);
		var $address = $(form.address).parents("tr").eq(0);
		var $addressLabel = $address.prev("tr");
		var $message = $(html);
		var onDeliver = function() {
			if ($deliver.is(":checked")) {
				$message.show();
				$address.show();
				$addressLabel.show();
			} else {
				$message.hide();
				$address.hide();
				$addressLabel.hide();
			}
		};
		$deliver.click(onDeliver);
		$deliver.after($message);
		onDeliver();
	});
}

function initKorzina() {
	$('.div_click').click (function() {
		var wid = $('.korzina2').width();
		if (wid == 255) wid = 29;
		else wid = 255;
		$('.korzina2').animate({width: wid}, "fast");
	})
}

function cool_basket(a,id) {
	$.post(
        "/SiteNN/request/?a=add_cart&buy=" + encodeURIComponent(id),
        { id: id },
        function(result) {
			$('.korzina2').animate({width: 255}, "fast");
            var $img = $(a).parents("div.cat-price").children("div.left").children("img.image");
			if ($img.length == 0) $img = $("a.price-fancy>img");
            var $clone = $img.clone();
            var offset = $img.offset();
            $clone.css({
                top: offset.top,
                left: offset.left,
                position: "absolute",
                zIndex: "1000"
            });
            $("body").append($clone);
            $clone.animate({
                top: $(".korzina2").offset().top + 50,
                left: $(".korzina2").offset().left,
                opacity: 90,
                height:0,
                width:0
            }, 1000, function() {
                $clone.remove();
            });
		    $("#cart-html").fadeOut("slow", function() {
				$("#cart-html").html(result.html).fadeIn("slow");
            });
        }
    );
	return false;    
}

function myHideMenu() {
    var $t = $("#tc td>div");
    $t.children("a").removeClass("hover");
    $t.children("div.level1").hide();
}

function myInitMenu() { 
    $("#tc td>div").mouseover(function() {
        if (window.myMenuTimeout) {
            clearTimeout(window.myMenuTimeout);
            window.myMenuTimeout = null;
        }
        myHideMenu();
        $(this).children("a").addClass("hover");
        $(this).children("div.level1").show();
    }).mouseout(function() {
        if (window.myMenuTimeout) {
            clearTimeout(window.myMenuTimeout);
            window.myMenuTimeout = null;
        }
        window.myMenuTimeout = setTimeout(myHideMenu, 300);
    });
}

function init() {
    if (typeof($) === "undefined") return setTimeout(arguments.callee, 100);
    $(function() {
		initKorzina();
		myInitMenu();
    });
}

init();

