
// Hover fade plugin - drops opacity on selcted objects

$(function() {
    $.fn.hoverFade = function(options) {
        var defaults = {
            from: 1.0,
            to: 1.0,
            speed: 400

        };
        options = $.extend(defaults, options);
        var rFrom = options["from"];
        var rTo = options["to"];
        var rSpeed = options["speed"];
        $(this).css("opacity", rFrom);
        $(this).hover(function() {
            $(this).stop().fadeTo(rSpeed, rTo);
        },
							function() {
							    $(this).stop().fadeTo(rSpeed, rFrom);
							});
    }

    $(".blanket").hoverFade({
        from: 0.0,
        to: 0.7
    });
    $("#nav ul li.logo a").hoverFade({
        from: 1.0,
        to: 0.8
    });
    $("#callouts li a").hoverFade({
        to: 0.8
    });

    $("#cart .product-img a ").hoverFade({
        from: 1.0,
        to: 0.85
    });

    // Drop down menus

    $.fn.ddMenu = function() {
        $(this).children("li").each(function() {
            $(this).bind("mouseover", function() {
                $(this).children("ul").css("display", "block");
            });
            $(this).bind("mouseout", function() {
                $(this).children("ul").css("display", "none");
            });
        });
    }

});

// Custom selects + remove item ajax

$(function() {
    $(".add a").live("click", function() {
        var product_id = $("[id*=hfProductId]").val();
        var size = $("[id*=ddlSizes]").val();
        var quantity = $("[id*=ddlQuantities]").val();

        if (size != undefined) {
            if (size == "0") {
                alert("Please select a shoe size and Qty, then choose Add.");
                return;
            }
        }
        else {
            size = null;
        }
        if (quantity == "0") {
            alert("Please select a shoe size and Qty, then choose Add.");
            return;
        }
        if (quantity == undefined)
            quantity = "1";
        var cancel_update = false;
        $.ajax({
            type: "POST",
            url: "ajax/ajax-door.aspx/CheckIfSameSizeExistsWithoutOriginalSize",
            contentType: "application/json; charset=utf-8",
            data: "{product_id:" + product_id + ",size:" + size + "}",
            dataType: "json",
            success: function(msg) {
                if (msg.d == true) {
                    var answer = confirm("This " + (size == null ? "product" : "size") + " is already in your Basket. Do you want to change the quantity of this size? ( new quantity is " + quantity + ")");
                    if (answer == false)
                        cancel_update = true;
                }

                if (!cancel_update) {
                    $.ajax({
                        type: "POST",
                        url: "ajax/ajax-door.aspx/AddBasketItem",
                        contentType: "application/json; charset=utf-8",
                        data: "{ product_id:" + product_id + ", size:" + size + ",quantity:" + quantity + "}",
                        dataType: "json",
                        success: function(msg) {
                            window.location = "basket.aspx";
                        }
                    });
                }
            }
        });

    });
    $.fn.updateMainBasket = function() {

        if ($("#cart").length > 0 && $("#checkout_basket").length == 0)
            $.ajax({
                type: "GET",
                cache: false,
                url: "ajax/main-basket.aspx",
                success: function(html) {
                    var new_html = $("div.form", html).wrap("<div class=\"form\">");
                    $("#cart").html(new_html);
                    $(".custSelect").customSelect();
                }
            });
    };
    $.fn.updateCheckoutBasket = function() {
        var lbtContinue = $("[id*=lbtContinue]");

        if ($("#checkout_basket").length > 0)
            $.ajax({
                type: "GET",
                cache: false,
                url: "ajax/checkout-basket.aspx",
                success: function(html) {
                    var new_html = $("div#checkout_basket", html).html();

                    $("#checkout_basket").html(new_html);
                    $(".custSelect").customSelect();

                    $("[id*=lbtContinue]").attr("href", $(lbtContinue).attr("href"));
                    $("[id*=lbtContinue]").attr("id", $(lbtContinue).attr("id"));

                }
            });
    };
    $.fn.updateRightBasket = function(onSuccess) {
        if ($("#basket").length > 0) {

            $.ajax({
                type: "GET",
                cache: false,
                url: "ajax/right-basket.aspx",
                success: function(html) {

                    $("#basket").html(html);
                    if (onSuccess != null)
                        onSuccess();
                }
            });
        }
    };
    $(".ajaxbye").live("click", function() {
        var sender = $(this);
        var product_id = sender.attr("prel");
        var size = sender.attr("srel");
        if (size == undefined || size == "")
            size = null;

        $.ajax({
            type: "POST",
            url: "ajax/ajax-door.aspx/RemoveBasketItem",
            contentType: "application/json; charset=utf-8",
            data: "{product_id:" + product_id + ",size:" + size + "}",
            success: function() {

                $().updateRightBasket(function() {
                    if (sender.parent().attr("class") == "basket-item") {
                        $("#btn_basket ~ div").toggle();
                        $("#btn_basket").toggleClass("upArrow");
                    }
                });
                $().updateMainBasket();
                $().updateCheckoutBasket();
            }
        });

        return false;
    });


    $(document).ready(function() {
        $("[id*=ddlSizes],[id*=ddlQuantities]", $("#cart")[0]).live("change", function() {
            var product_id = $(this).closest(".item").children("a.remove").attr("prel");
            var original_size = $(this).closest(".item").children("a.remove").attr("srel");
            var new_size = $(this).closest(".item").find("[id*=ddlSizes]").val();
            var quantity = $(this).closest(".item").find("[id*=ddlQuantities]").val();

            $().updateBasketItem(product_id, original_size, new_size, quantity,
                    function() {
                        $().updateMainBasket();
                        $().updateCheckoutBasket();
                        $().updateRightBasket(null);
                    },
                    function() {
                        $().updateMainBasket();
                        $().updateCheckoutBasket();
                    }
                );

        });
    });

    $.fn.updateBasketItem = function(product_id, original_size, new_size, quantity, onSuccess, onCancelUpdate) {

        if (original_size == undefined || original_size == "nothing" || original_size == "")
            original_size = null;
        if (new_size == undefined || new_size == "nothing" || new_size == "")
            new_size = null;
        var cancel_update = false;

        $.ajax({
            type: "POST",
            url: "ajax/ajax-door.aspx/CheckIfSameSizeExists",
            contentType: "application/json; charset=utf-8",
            data: "{product_id:" + product_id + ",original_size:" + original_size + ",new_size:" + new_size + "}",
            dataType: "json",
            success: function(msg) {

                if (msg.d == true) {
                    var answer = confirm("This size is already in your Basket. Do you want to change the quantity of this size? ( new quantity is " + quantity + ")");
                    if (answer == false) {
                        cancel_update = true;
                    }
                }
                else {
                    cancel_update = false;
                }

                if (cancel_update == false) {
                    $.ajax({
                        type: "POST",
                        url: "ajax/ajax-door.aspx/UpdateBasketItem",
                        contentType: "application/json; charset=utf-8",
                        data: "{product_id:" + product_id + ",original_size:" + original_size + ",new_size:" + new_size + ",quantity:" + quantity + "}",
                        dataType: "json",
                        success: function(msg) {
                            onSuccess();
                        }
                    });
                }
                else {
                    onCancelUpdate();
                }
            }
        });
    }

    // .custSelect
    $.fn.customSelect = function(options) {

        var defaults = {
            defaultText: "Please Select"
        };
        options = $.extend(defaults, options);
        $(this).each(function() {

            $select = $(this); // "this" is the exactly select element
            $options = $(this).children("option");
            $selected_option = $(this).children("option:selected").first();
            if ($selected_option == 'undefined')
                $selected_option = $options.first();
            var sList = "";
            $options.each(function() {
                sList += "<li rel=\"" + $(this).attr("value") + "\"><a>" + $(this).text() + "</a></li>";
            });

            $select.after("<ul class=\"jq_custSelect\"><li><a class=\"s_tbox\" type=\"text\" name=\""
                          + $(this).attr("name") + "_text\""
                          + " value=\"" + $selected_option.val() + "\">"
                          + $selected_option.text() + "</a><ul class=\"jq_custSelect_sub\">" + sList + "</ul></li></ul>");
            // will change this because will match all .s_tbox elements
            //
            $select.next().find(".s_tbox").bind("click", function() {
                $(this).next("ul").slideDown("fast");
            });

            $select.next().find(".jq_custSelect_sub").children("li").each(function() {
                $(this).bind("click", function() {
                    var $custSelect = $(this).closest(".jq_custSelect").prev();
                    var $custSelectOptions = $custSelect.children("option");
                    $(this).parent("ul").prev(".s_tbox").text($(this).text());
                    $(this).parent("ul").prev(".s_tbox").attr("value", $(this).attr("rel"));



                    $(this).parent("ul").slideUp("fast");
                    if (options["success"]) options["success"];
                    // -- fire the change event of the select element
                    var val = $(this).attr("rel");

                    if ($custSelect.val() != val) {
                        $custSelectOptions.each(function(index) {
                            $(this).removeAttr("selected");
                            if ($(this).attr("value") == val) {

                                $(this).attr("selected", "selected");
                            }
                        });
                        $custSelect.attr("value", val);
                        $custSelect.change();
                    }


                });
            });
            $(this).css("display", "none");
        });
    }

    $.fn.customCheckbox = function() {
        $(this).each(function() {
            var sClass = $(this).attr("class");
            var $myInput = $(this);
            $(this).after("<span class=\"" + sClass + "\"></span>");
            if ($(this).attr("checked")) $(this).next("span").addClass("active");
            else $(this).next("span").addClass("inactive")
            $(this).next("span").bind("mousedown", function() {
                $(this).addClass("down");

            });
            $(this).next("span").bind("mouseup", function() {
                $(this).removeClass("down").toggleClass("inactive").toggleClass("active");
                ////alert($myInput.attr("checked"));
                $(this).prev().attr("checked", !$myInput.attr("checked"));
                $(this).prev().change();
            });
            $(this).css("display", "none");
        });
    }

    $("input.custCheck").customCheckbox();

    $(".custSelect").customSelect();

});

function gotoSlideGall(sPanelID, iSlideRate) {
    $(function() {
        $(".slidePanelIndex").removeClass("onShowIndex");
        $(sPanelID).addClass("onShowIndex");
        $("#slideStripIndex").animate({ marginLeft: $(sPanelID).attr("rel") }, iSlideRate);
        if ($(".slidePanelIndex.onShowIndex").attr("id") == $(".slidePanelIndex:last").attr("id")) $(".digit-r").fadeOut("slow");
        else $(".digit-r").fadeIn("slow");
        var iIndex = $(".slidePanelIndex").index($(".onShowIndex"));
        if (iIndex != 0) {
            var sPage = "0" + parseInt(iIndex);
            $(".larr a span").text(sPage.substr(-2));
            $(".larr a").fadeIn("slow");
            $("#gallery a.left").fadeIn("slow");
        }
        else {
            $(".larr a").fadeOut("slow");
            $("#gallery a.left").fadeOut("slow");
        }
        if (iIndex != $(".slidePanelIndex").length - 5) {
            var sPage = "0" + parseInt(iIndex + 2);
            $(".rarr a span").text(sPage.substr(-2));
            $(".rarr a").fadeIn("slow");
            $("#gallery a.right").fadeIn("slow");
        }
        else {
            $(".rarr a").fadeOut("slow");
            $("#gallery a.right").fadeOut("slow");
        }
    });
}

function gotoSlide(sPanelID, iSlideRate) {
    $(function() {
        $(".slidePanel").removeClass("onShow");
        $(sPanelID).addClass("onShow");
        $("#slideStrip").animate({ marginLeft: $(sPanelID).attr("rel") }, iSlideRate);
        if ($(".slidePanel.onShow").attr("id") == $(".slidePanel:first").attr("id")) $(".digit-l").fadeOut("slow");
        else $(".digit-l").fadeIn("slow");
        if ($(".slidePanel.onShow").attr("id") == $(".slidePanel:last").attr("id")) $(".digit-r").fadeOut("slow");
        else $(".digit-r").fadeIn("slow");
        var iIndex = $(".slidePanel").index($(".onShow"));
        var sLeftPage = "0" + parseInt(iIndex);
        var sRightPage = "0" + parseInt(iIndex + 2);
        if (iIndex != 0) $(".digit-l span").text(sLeftPage.substr(-2));
        if (iIndex != $(".slidePanel").length - 1) $(".digit-r span").text(sRightPage.substr(-2));
    });
}

$(function() {
    $.fn.cycleSlide = function(options) {
        $(this).stop().click(function() {
            var iSlideRate = options["slideRate"];
            var sDirection = options["slideDir"];
            if (sDirection == "prevSlide" && $(".slidePanel.onShow").prev(".slidePanel").length) {
                gotoSlide("#" + $(".slidePanel.onShow").prev(".slidePanel").attr("id"), iSlideRate);

            }
            else if (sDirection == "nextSlide" && $(".slidePanel.onShow").next(".slidePanel").length) {
                gotoSlide("#" + $(".slidePanel.onShow").next(".slidePanel").attr("id"), iSlideRate);
            }
            return false;
        });
    }

    $.fn.SlideStrip = function(options) {
        var defaults = {
            cycleSlides: false,
            handle: "div",
            navBar: true,
            slideRate: 500,
            defaultSlide: 0,
            autoSlide: false,
            autoTimer: 5000,
            extTimer: 1
        };
        options = $.extend(defaults, options); //adds default values to the options array where they haven't been specified

        var iPlayWidth = options["playWidth"];
        var iPlayHeight = options["playHeight"];
        var iSlideCount = $(this).children(options["handle"]).length;
        var iDefaultSlide = options["defaultSlide"];

        $(this).css("width", iPlayWidth).css("overflow", "hidden");

        $(this).children(options["handle"]).addClass("slidePanel");

        $(".slidePanel").each(function(i) {
            $(this).attr("rel", -iPlayWidth * i);
        });

        $(".slidePanel").wrapAll("<div id=\"slideStrip\"></div>");

        $("#slideStrip").css("width", iPlayWidth * iSlideCount);
        $("#slideStrip").css("height", iPlayHeight);

        $("#cycleSlide").css("width", iPlayWidth);
        $("#cycleSlide").css("marginTop", -iPlayHeight);
        $(".cycleSlide").cycleSlide({
            cycleSlides: options["cycleSlides"],
            slideRate: options["slideRate"],
            autoSlide: options["autoSlide"],
            autoTimer: options["autoTimer"]
        });
        $(".slideLink:eq(" + iDefaultSlide + ")").addClass("active");
        $(".slidePanel:eq(" + iDefaultSlide + ")").addClass("onShow");
        $("#slideStrip").css("marginLeft", parseFloat($(".onShow").attr("rel")));

    }
});

// currency selector

$(function() {
    $("#currency select option").each(function() {
        $("#currency-options ul").append("<li><a class=\"currency-option\" rel=\"" + $(this).attr("value") + "\" href=\"#\">" + $(this).text() + "</a></li>");
    });

    $("body").click(function() {
        $("#currency-options").css("display", "none");
    });

    $("#currency-select").click(function() {
        var iCurHei = $("#currency-options").height();
        $("#currency-options").css("height", "0px").css("marginTop", "0").css("display", "block").animate({ height: iCurHei, marginTop: -(iCurHei - 10) }, 500);
        return false;
    });
    $("#currency select").change(function() {
        //$('#aspnetForm').submit();
    });


    $("#currency-options").css("left", $("#currency-select").position().left + "px");

    $("#ddMenu").ddMenu();

    $("#btn_search, #btn_basket").live("click", function() {
        $(this).next("div").slideToggle();
        $(this).toggleClass("upArrow");
        return false;
    });

    $(".no_special").live("click", function() {
        $("#btn_search").click();
        return false;
    });

    $(".btn_close").live("click", function() {
        $(this).parent("div").slideUp();
        $(this).parent("div").prev("a").toggleClass("upArrow");
        return false;
    });

    $.fn.myAccordion = function() {
        $(this).children(".closed").find(".accordion-content").slideUp(700);
        $(this).children("div.past-order").find("a.btn,a.toggle").each(function() {

            $(this).click(function() {
                $(this).parent("p.past").parent("div.past-order").toggleClass("open").toggleClass("closed").children(".accordion-content").slideToggle();
                if ($(this).parent("p.past").parent("div.past-order").hasClass("open")) $(this).parent("p.past").children(".btn").text("Close");
                else $(this).parent("p.past").children(".btn").text("View");
            });

        });
    }

    $("#account #cart").myAccordion({ collapsible: true });

    $("#boutiques #book-gallery, #heritage #book-gallery").SlideStrip({
        navBar: false,
        playWidth: 803,
        playHeight: 388
    });
    $("#boutiques .digit-l, #heritage .digit-l").cycleSlide({
        cycleSlides: false,
        slideRate: 500,
        autoSlide: false,
        autoTimer: 5000,
        slideDir: "prevSlide"
    });
    $("#boutiques .digit-r, #heritage .digit-r").cycleSlide({
        cycleSlides: false,
        slideRate: 500,
        autoSlide: false,
        autoTimer: 5000,
        slideDir: "nextSlide"
    });

    $.fn.customSelectFAQ = function(options) {
        var defaults = {
            defaultText: "Please Select"
        };
        options = $.extend(defaults, options);
        $(this).each(function() {
            $select = $(this);
            $options = $(this).children("option");
            var sList = "";
            $options.each(function() {
                sList += "<li rel=\"" + $(this).attr("value") + "\"><a>" + $(this).text() + "</a></li>";
            });

            $(this).after("<ul class=\"jq_custSelect\"><li><a class=\"s_tbox\" type=\"text\" name=\"" + $(this).attr("name") + "_text\">" + $options.first().text() + "</a><ul class=\"jq_custSelect_sub\">" + sList + "</ul></li></ul>");

            $(".s_tbox").bind("click", function() {
                $(this).next("ul").slideDown("fast");
            });
            $(".jq_custSelect_sub").children("li").each(function() {
                $(this).bind("click", function() {
                    $(this).parent("ul").prev(".s_tbox").text($(this).text());
                    $select.attr("value", $(this).attr("rel"));
                    $(this).parent("ul").slideUp("fast");
                    var sLink = $(this).attr("rel");
                    $.ajax({
                        url: sLink,
                        cache: false,
                        success: function(html) {
                            $("#active-content").html(html);
                            $(".faq-link").live("click", function() {
                                $this = $(this);
                                var sLink = $(this).attr("rel");
                                return false;
                            });
                        }
                    });
                    return false;
                });
            });
            $(this).css("display", "none");

        });

    }

    $("#account .faq-link").live("click", function() {
        var question_key = $(this).attr("rel");
        var question_el = $(this);
        //alert("{question_key:'" + question_key + "'}");
        if (question_key != 'faq_cat_2_q_3') {
            $.ajax({
                type: "POST",
                url: "ajax/ajax-door.aspx/GetAnswer",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: "{question_key:'" + question_key + "'}",
                success: function(html) {
                    $("#topic-detail p").html(html.d);
                    $(".faq-link").removeClass("active");
                    question_el.addClass("active");
                }
            });
        }
        else {
            $.ajax({
                url: "ajax/product-tab01.aspx",
                cache: false,
                success: function(html) {
                    $("#topic-detail p").html(html);
                    $(".faq-link").removeClass("active");
                    question_el.addClass("active");
                },
                failure: function() {
                    alert("failed");
                }
            });
        }
        return false;
    });

    $("#account .custSelectFAQ").customSelectFAQ();


    $("#store #info .tabber,#store #sub-nav .tabber, .slim a.tabber").bind("click", function() {

        var sTarget = $(this).attr("href");

        $.ajax({
            url: "ajax/" + sTarget,
            cache: false,
            success: function(html) {

                //                if ( $("div.send-friend", html).length > 0 )
                //                    html = $("div.send-friend", html).wrap("<div class='send-friend'>");

                $(".windowbox").html(html);
                $("#sub-nav li").removeClass("active");
                $("#sub-nav a:[href='" + sTarget + "']").parent().addClass("active");
                $("#title-block h2").text($("#sub-nav a:[href='" + sTarget + "']").parent().text());
                $(".rollblind").slideDown();
                $("#emailForm").bind("keypress", function(event) {
                    if (event.keyCode == 13) {
                        var src = event.srcElement || event.target;
                        if (!src || (src.tagName.toLowerCase() != "textarea")) {
                            var defaultButton = $("#btSend");
                            if (defaultButton && typeof (defaultButton.click) != "undefined") {
                                defaultButton.click();
                                event.cancelBubble = true;
                                if (event.stopPropagation) event.stopPropagation();
                                return false;
                            }
                        }
                    }
                    return true;

                });
                $("#btSend").bind("click", function() {
                    if (Page_ClientValidate("email")) {
                        var yourEmail = $("#pd02_tbCustomerEmail_tbTextBox").val();
                        var yourFriendsEmail = $("#pd02_tbYourFriendsEmail_tbTextBox").val();
                        var yourMessage = $("#pd02_tbYourMessage_tbTextBox").val();
                        var friend_name = $("#pd02_tbYourFriendsName_tbTextBox").val();
                        var product_id = $("#pd02_hfProductId").val();



                        //send email
                        $.ajax({
                            type: "POST",
                            url: "ajax/ajax-door.aspx/EmailFriend",
                            contentType: "application/json; charset=utf-8",
                            data: "{yourEmail:'" + yourEmail + "'"
                                  + ",yourFriendsEmail:'" + yourFriendsEmail + "'"
                                  + ",message:'" + yourMessage + "'"
                                  + ",yourFriendsName:'" + friend_name + "'"
                                  + ",product_id:" + product_id
                                  + "}",
                            dataType: "json",
                            success: function(msg) {
                            }
                        });
                        $(".rollblind").slideUp();
                        return false;

                    }
                });
                $("#btEmailCancel").bind("click", function() {
                    $(".rollblind").slideUp();
                    return false;
                });
            },
            failure: function() {
                alert("failed");
            }
        });
        return false;
    });

    $("#store .tabclose").bind("click", function() {
        $(".rollblind").slideUp();
        return false;
    });

    $("#store .slideReveal").bind("click", function() {
        $(this).parent().next("div").slideToggle();
        return false;
    });
    $("#store #btn_thumbs, #store #btn_thumbsX").bind("click", function() {
        $("[id*=lvMoreImages_thumbs]").fadeIn();
        $("#thumbs").fadeIn();
        return false;
    });
    $("#store #btn_thumbsX, #store .zoomo").bind("click", function() {
        //        $("#thumbs").fadeOut();
        return false;
    });

    $("#store #btn_thumbsX").bind("click", function() {
        $("[id*=lvMoreImages_thumbs]").fadeOut();
        $("#thumbs").fadeOut();
        return false;
    });

    $(".tipMe").tooltip({
        fixPNG: true,
        showURL: false,
        track: true,
        bodyHandler: function() {
            var sTip = $(this).attr("rel");
            return $(sTip).html();
        }
    });

    $.fn.cycleSlideGall = function(options) {
        $(this).stop().click(function() {
            var iSlideRate = options["slideRate"];
            var sDirection = options["slideDir"];
            if (sDirection == "prevSlide" && $(".slidePanel.onShow").prev(".slidePanel").length) {
                gotoSlide("#" + $(".slidePanel.onShow").prev(".slidePanel").attr("id"), iSlideRate);
                gotoSlideGall("#" + $(".slidePanelIndex.onShowIndex").prev(".slidePanelIndex").attr("id"), iSlideRate);
            }
            else if (sDirection == "nextSlide" && $(".slidePanel.onShow").next(".slidePanel").length) {
                gotoSlide("#" + $(".slidePanel.onShow").next(".slidePanel").attr("id"), iSlideRate);
                gotoSlideGall("#" + $(".slidePanelIndex.onShowIndex").next(".slidePanelIndex").attr("id"), iSlideRate);
            }
            return false;
        });
    }

    $.fn.SlideStripIndex = function(options) {
        var defaults = {
            cycleSlides: false,
            navBar: true,
            slideRate: 500,
            defaultSlide: 0,
            autoSlide: true,
            autoTimer: 5000,
            extTimer: 1
        };
        options = $.extend(defaults, options); //adds default values to the options array where they haven't been specified

        var iPlayWidth = options["playWidth"];
        var iPlayHeight = options["playHeight"];
        var iSlideCount = $(this).children("div").length;
        var iDefaultSlide = options["defaultSlide"];

        $(this).css("width", 5 * iPlayWidth).css("overflow", "hidden");

        $(this).children("div").addClass("slidePanelIndex");

        $(".slidePanelIndex").each(function(i) {
            $(this).attr("rel", -iPlayWidth * i);
        });

        $(".slidePanelIndex").wrapAll("<div id=\"slideStripIndex\"></div>");

        $("#slideStripIndex").css("width", iPlayWidth * iSlideCount);
        $("#slideStripIndex").css("height", iPlayHeight);
        $(".slidePanelIndex:eq(" + iDefaultSlide + ")").addClass("onShowIndex");
        $("#slideStripIndex").css("marginLeft", parseInt($(".onShowIndex").attr("rel")));
    }

    $("#home .thumb-live a").live("click", function() {
        var iIndex = $(".thumb-live").index($(this).parent(".thumb-live"));
        gotoSlide("#" + $(".index-slide").eq(iIndex).attr("id"), 750);
        gotoSlideGall("#" + $(".thumb-slide").eq(iIndex).attr("id"), 750);
        return false;
    });


});

window.onresize = function() {

    $(function() {
        $("#currency-options").css("display", "none");
        $("#currency-options").css("left", $("#currency-select").position().left + "px");
    });

}


$(function() {
    $('a.new-win').click(function() {
        window.open(this.href);
        return false;
    });
});
var heelHeightsCategories = ["1", "2", "3"];
$(document).ready(function() {
    $(".category input.go").click(function() {
        var ukSize = "0";
        var ukSizeElement = $(this).closest("fieldset").find(".s_tbox");
        if ($(ukSizeElement).attr("value") != undefined)
            ukSize = $(ukSizeElement).attr("value");
        var category_id = $(this).closest("fieldset").find("input[id*=hCategoryId]:first").val();
        var redirect = "special-offers.aspx?cid=" + category_id;

        if (ukSize != "0" && ukSize != "undefined") {
            redirect += "&uk=" + ukSize;
        }

        window.location = redirect;
    });
    // init the search behaviour
    searchBehaviour();
    $("#ctl00_ctrlSearch_ddlCategories").change(function() {
        getSubcategories();
        searchBehaviour();
    });
    $("[id*=cbSpecialOffers]").change(function() {
        searchBehaviour();
    });

    $("#btSearch").click(function() {
        var $container = $(this).closest("#search");
        var category_id = $container.find("a[name*=ddlCategories]").attr("value");
        var type_id = $container.find("a[name*=ddlTypes]").attr("value");
        var colour_id = $container.find("a[name*=ddlColors]").attr("value");
        var heel_height_id = $container.find("a[name*=ddlHeelHeights]").attr("value");

        
        if ( type_id != "0" && type_id != "" && type_id != null)
               category_id = type_id;
        



        var name = $container.find("input[id*=tbName]").val();
        var special_offers = $container.find("input[id*=cbSpecialOffers]").attr("checked") == true;
        var uk_size = $container.find("a[name*=ddlUKSizes]").attr("value");

        if ($.inArray(category_id, heelHeightsCategories) == -1) {
            heel_height_id = "0";
            //special_offers = false;
            uk_size = "0";
        }
        else {
            if (special_offers == false) {
                uk_size = "0";
            }
        }

        var redirect = "";
        redirect += category_id != "0" ? "&cid=" + category_id : "";
        redirect += colour_id != "0" ? "&clid=" + colour_id : "";
        redirect += heel_height_id != "0" ? "&hid=" + heel_height_id : "";
        redirect += uk_size != "0" ? "&uk=" + uk_size : "";
        redirect += name != "" ? "&name=" + name : "";
        redirect += special_offers == true ? "&s=true" : "";
        if (redirect != "") {
            redirect = "store.aspx?mode=search" + redirect;
            window.location = redirect;
        }
    });
    $("#ctl00_content_ddlPressYears").change(function() {

        var year = $(this).val();

        window.location = window.location.pathname + "?year=" + year;
    });

    $("[id*=ddlFaqs]").change(function() {
        var cat = $(this).val();
        var cat_name = $(this).children("option:selected").text();
        $.ajax({
            type: "POST",
            url: "ajax/ajax-door.aspx/GetQuestions",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: "{category_key:'" + cat + "'}",
            success: function(msg) {
                var question_key = msg.d[0].key_tag;
                var html = "<li><a class=\"faq-link active\" rel=\"" + msg.d[0].key_tag + "\" href=\"#\">" + msg.d[0].text + "</a></li>";
                for (var i = 1; i < msg.d.length; i++) {
                    html += "<li><a class=\"faq-link\" rel=\"" + msg.d[i].key_tag + "\" href=\"#\">" + msg.d[i].text + "</a></li>";
                }
                $(".link-list").html(html);
                $(".category-title").text(cat_name);
                $.ajax({
                    type: "POST",
                    url: "ajax/ajax-door.aspx/GetAnswer",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data: "{question_key:'" + question_key + "'}",
                    success: function(html) {
                        $("#topic-detail p").html(html.d);
                    }
                });

            }
        });
        return false;
    });

    $(".currency-option").click(function() {
        //
        var sValue = $(this).attr("rel");
        var iCurHei = $("#currency-options").height();
        var cValue = $("#currency select").val();
        $("#currency select option:[value='" + $(this).attr("rel") + "']").attr("selected", "selected");

        $("#currency-select span").text("Currency - " + $(this).text());
        $("#currency-options").css("display", "none");

        if (sValue != cValue) {
            $.ajax({
                type: "POST",
                url: "ajax/ajax-door.aspx/SetSelectedCurrency",
                contentType: "application/json; charset=utf-8",
                data: "{three_letters_symbol:'" + sValue + "'}",
                dataType: "json",
                cache: false,
                success: function(msg) {
                    location.reload(true);
                }
            });
            //$("#currency select").change();
        }
        return false;
    });
});

function getSubcategories() {

    var category_id = $("[id*=ctrlSearch_ddlCategories]").val();
    var ddlTypes = $("[id*=ctrlSearch_ddlTypes]");
    if (category_id != "0") {
        $.ajax({
            type: "POST",
            url: "ajax/ajax-door.aspx/GetSubcategories",
            contentType: "application/json; charset=utf-8",
            data: "{category_id:" + category_id + "}",
            dataType: "json",
            cache: false,
            success: function(msg) {
                if (msg.d != null && msg.d.length > 0) {
                    if (!$(ddlTypes).hasClass("bye"))
                        $(ddlTypes).parent().addClass("bye");
                    $(ddlTypes).find("option:gt(0)").remove();
                    $.each(msg.d, function(i, category) {
                        $("<option/>").val(category.category_id).text(category.name).appendTo($(ddlTypes));
                    });
                    $(ddlTypes).next().remove();
                    $(ddlTypes).parent().removeClass("bye");
                    $(ddlTypes).customSelect();
                }
                else {
                    $(ddlTypes).find("option:gt(0)").remove();
                    $(ddlTypes).next().remove();
                    if (!$(ddlTypes).parent().hasClass("bye"))
                        $(ddlTypes).parent().addClass("bye");
                }
            }
        });
    }
    else {
        $(ddlTypes).find("option:gt(0)").remove();
        $(ddlTypes).next().remove();
        if (!$(ddlTypes).parent().hasClass("bye"))
            $(ddlTypes).parent().addClass("bye");
    }
}

function searchBehaviour() {

    var category_id = $("[id*=ddlCategories]").val();

    if ($.inArray(category_id, heelHeightsCategories) == -1) {
        $("[id*=ddlHeelHeights]").parent().hide();
        $("[id*=ddlUKSizes]").parent().hide();
    }
    else {
        $("[id*=ddlHeelHeights]").parent().show();
        if ($("[id*=cbSpecialOffers]").length != undefined && $("[id*=cbSpecialOffers]").length == 1) {
            $("[id*=cbSpecialOffers]").parent().show();
            if ($("[id*=cbSpecialOffers]").attr("checked") == true) {
                $("[id*=ddlUKSizes]").parent().show();
            }
            else {
                $("[id*=ddlUKSizes]").parent().hide();
            }
        }
    }

}
function queryString(param) {
    var hu = window.location.search.substring(1);
    var gy = hu.split("&");
    for (var i = 0; i < gy.length; i++) {
        var ft = gy[i].split("=");
        if (ft[0] == param) {
            return ft[1];
        }
    }
    return null;
}
function pagePath() {
    var hu = window.location;
    return hu;
}
function resetZIndex() {
    $("#nav").css("z-index", "500");
    return true;
}
