jQuery(function () {
    if (jQuery("body.productList").length > 0) {

        // Fix of last category element
        jQuery(".listFilter .categories li:last").height(20);

        // Select new employee in the "shopping for employee" section
        jQuery("div.shopForEmployee div.employeeList label, div.shopForEmployee div.employeeList input").click(function () {
            var objParent = jQuery(this).parent();
            objParent.siblings().removeClass("selected");
            objParent.addClass("selected");
            objParent.find("input").attr("checked", "checked");
            return;
        });

        // Arrow for each product list item
        jQuery(".listContent .list li").append("<span class='arrow'/>").hoverIntent(
            function () {
                if (hLib.booIE) jQuery(this).find(".arrow").css("bottom", "98px");
                else jQuery(this).find(".arrow").animate({ bottom: 98 }, 200);
            },
            function () {
                if (hLib.booIE) jQuery(this).find(".arrow").css("bottom", "70px");
                else jQuery(this).find(".arrow").animate({ bottom: 70 }, 200);
            }
        ).find(".productActions").append("<span class='borderLeft'/><span class='borderRight'/>");
    }
});

    function UpdateOneProductInList(productColorID, productID, type) {

        if (!top.processingUpdate) {
            top.processingUpdate = true;

            jQuery.post(window.url_UdpateProductInList, { productColorID: productColorID, productID: productID }, function (data) { HandleUpdateOneProductInListResult(data, type) }, 'json');
        }
    }

    function HandleUpdateOneProductInListResult(data, type) {

        var productItem = jQuery(".jProduct" + data.ProductID + "_" + type);

        jQuery(productItem).find(".photo > img").attr("src", data.ProductImageUrl);
        jQuery(productItem).find(".productHeader.fn").html(data.ProductHeader);

        jQuery(productItem).find(".productDetails.description").html(data.Description);

        jQuery(productItem).find(".price").html(data.Price);

        var sizeList = jQuery(productItem).find(".size.right");
        var selected = jQuery(sizeList).find("option:selected").text();
        jQuery(sizeList).find("option").remove();

        var found = false;
        for (var i = 0; i < data.ListOFSize.length; i++) {
            jQuery(sizeList).append(jQuery('<option></option>').val(data.ListOFSize[i].split("|")[1]).html(data.ListOFSize[i].split("|")[0]));

            if (selected == data.ListOFSize[i].split("|")[0]) {
                selected = data.ListOFSize[i].split("|")[1];
                found = true;
            }
        }
        if (found)
            jQuery(sizeList).val(selected);

        top.processingUpdate = false;
    }

    function UpdatePrice(ProductSizeID, productID, type) {
        if (!top.processingUpdate) {
            top.processingUpdate = true;

            jQuery.post(window.url_UpdatePriceOnProductList, { ProductSizeID: ProductSizeID, productID: productID }, function (data) { HandleUpdatePrice(data, type, productID) }, 'json');
        }

    }

    function HandleUpdatePrice(data, type, productID) {

        var productItem = jQuery(".jProduct" + productID + "_" + type);

        jQuery(productItem).find(".price").html(data.Price);

        top.processingUpdate = false;

    }
