
jQuery.dy = {

    helper: {},

    init: function () {
        // initializing code for all pages
        jQuery.resize.delay = 500;

        $.dy.setupCredits();
        $.dy.setupSubscribe();
        $.dy.setupGlobalPromo();
        $.dy.setupNav();

        $.dy.setupFlash({
            minW: 990,
            minH: 673,
            container: $(".flashHolder")
        });

        //        $.dy.setupFlashGiftfinder({
        //            minH: "auto",
        //            container: $("#giftfinder div.flashHolder")
        //        });


        $.dy.setupShopAssistFooter({
            minH3: 100 + $('#shop-assistance-content .container').height(),
            container: $("#assist-bg")
        });

        //holiday page

        /*$.dy.setupHolidayFooter({
        minH1: 50 + $('#wrapper #dy-holiday').height(),
        container: $("#dy-holiday")
        });


        */

        //product grid

        $.dy.setupProductGridFooter({
            minH3: $('.productGrid-container').height(),
            container: $(".productGrid-container")
        });

        $.dy.setupFooter({

            //minH2: $(".shopform").height() + 100,
            minH2: $(".shopform").outerHeight(true) + 25,
            container: $("#wrapper .shop-bg"),

            minH4: 565,
            container: $(".regform-bg"),

            minH5: $(".privacypolicy-bg").height(),
            container: $(".privacypolicy-bg")

        });

        $(window).resize(function () {
            $.dy.setupFlash({
                minW: 990,
                minH: 673,
                container: $(".flashHolder")
            });

            $.dy.setupFooter({
                //minH2: $(".shopform").height() + 100,
                minH2: $(".shopform").outerHeight(true),
                container: $(".shop-bg"),

                minH4: 565,
                container: $(".regform-bg")

            });

            //holiday page
            /* $.dy.setupHolidayFooter({
            minH1: $('#wrapper #dy-holiday').height(),
            container: $("#dy-holiday")
            });*/

            //            $.dy.setupFlashGiftfinder({
            //                minH: "auto",
            //                container: $("#giftfinder div.flashHolder")
            //            });

        });


        $('#shop-assistance-content .container').resize(function () {
            $.dy.setupShopAssistFooter({
                minH3: 100 + $('#shop-assistance-content .container').height(),
                container: $("#assist-bg")
            });
        });



        //product grid

        $('.productGrid-container').resize(function () {

            $.dy.setupProductGridFooter({
                minH3: $('.productGrid-container').height(),
                container: $(".productGrid-container")
            });
        });


        //initialize the shopping bag
        //$.shoppingBag();

        // search box
        $(".header .searchBox").focus(function () {
            $(this).val("");
        }).blur(function () {
            if ($(this).val() == "") {
                $(this).val("SEARCH");
            }
        });



        $('.imageButton').each(function () {
            var $this = $(this);
            var imagelink = $this.attr("src");

            $this.hover(function () {

                $this.attr("src", imagelink.replace(".gif", "-on.gif"));

            }, function () {

                $this.attr("src", imagelink);

            });
        });


        //        $('.imageButton2').each(function() {
        //            $(this).hover(function() {
        //                $(this).animate({
        //                    opacity: 0.7
        //                }, 1)
        //            }, function() {
        //                $(this).animate({
        //                    opacity: 1
        //                }, 1)
        //            });
        //        });

        // Checkout Popups 

        $('.pop-link .open').click(function (e) {
            e.preventDefault();
            var formPop = $(this).siblings('.form-pop');
            var popHeight = ($(formPop).height() * -1) - 5;
            if ($(this).parent('.pop-link').is('.pop-link-down')) {
                popHeight = $(this).height() + 10;
            }
            $(formPop)
                    .toggle()
                    .css({ 'top': popHeight })
                    .css({ 'left': (($(formPop).width() / 2) * -1) + (($(this).width() / 2)) })
                ;
        });

        $('.form-pop .close').click(function (e) {
            e.preventDefault();
            $(this).parents('.form-pop').hide();
        });

        /*$('.forgot-password-link').click(function (e) {
        e.preventDefault();
        $('.forgot-password-modal').modal({
        opacity: 60,
        overlayCss: { backgroundColor: "#a6a6a6" },
        overlayClose: true,
        maxHeight: 500,
        maxWidth: 700,
        containerID: 'simplemodal-ajax',
        closeHTML: '<div class="simplemodal-header"><a href="#">Close x</a></div>'
        });
        });*/

        /*  Ajax Modal 
        $('#wrapper').delegate('.ajax-modal', 'click', function (e) {
        e.preventDefault();
        $.dy.preloadBlock();
        var popurl = $(this).attr("href");
        $.ajax({
        url: popurl,
        cache: true,
        context: document.body,
        error: function () {
        $.dy.removeBlock();
        },
        success: function (page) {
        var pageBody = $(page).find('.modal-template');
        $(pageBody).modal({
        opacity: 60,
        overlayCss: { backgroundColor: "#a6a6a6" },
        overlayClose: true,
        maxHeight: 500,
        maxWidth: 700,
        containerID: 'simplemodal-ajax',
        closeHTML: '<div class="simplemodal-header"><a href="#">Close x</a></div>'
        });
        $.dy.removeBlock();
        }
        });
        });*/


    }, // end init

    init_facebook: function () {
        window.fbAsyncInit = function () {
            FB.init({
                appId: '147443875307795',
                xfbml: true
            });

            FB.Event.subscribe('xfbml.render',
                function () {
                    $('.col .facebook-like-container').css({ 'visibility': 'visible' });
                }
            );
        };

        (function () {
            var e = document.createElement('script');
            e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
            e.async = true;
            document.getElementById('fb-root').appendChild(e);
        } ());

    },
    preloadBlock: function (callback) {
        $.blockUI.defaults.css = {};
        $.blockUI({ message: '<h1><img src="/images/preloader.gif" title="Loading..."></h1>' });
    },
    removeBlock: function (callback) {
        $.unblockUI();
        if (typeof callback === 'function') {
            callback.call(this);
        };
    },

    setupNav: function () {


    }, // end setup Nav

    setupFlash: function (opts) {

        var $templates = $(".flash-container").add($(".landing-container"));

        var h = parseInt($(window).height()) - parseInt($(".header").outerHeight()) - parseInt($(".footer").outerHeight());
        h = h > opts["minH"] ? h : opts["minH"];
        $templates.css('height', h);

        if (!($(".flash-container").hasClass("flash-fixed"))) {

            var w = parseInt($(window).width());
            w = w > opts["minW"] ? w : opts["minW"];
            $("#flashHolder").add($templates).css('width', w);
            $("#flashHolder").css('height', h);
        }
    }, // end setupFlash

    setupFlashGiftfinder: function (opts) {
        var h = parseInt($(window).height()) - parseInt($(".header").outerHeight()) - parseInt($(".footer").outerHeight());
        h = h > opts["minH"] ? h : opts["minH"];
        $("#giftfinder .flash-container").css('height', h);

        if (!($("#giftfinder.flash-container").hasClass("flash-fixed"))) {

            var w = parseInt($(window).width());
            w = w > opts["minW"] ? w : opts["minW"];
            $("#giftfinder #flashHolder,#giftfinder .flash-container").css('width', w);
            $("#giftfinder #flashHolder").css('height', h);
        }
    }, // end setupFlash

    setupFooter: function (opts) {
        var h2 = parseInt($(window).height()) - parseInt($(".header").outerHeight()) - parseInt($(".footer").outerHeight());
        h2 = h2 > opts["minH2"] ? h2 : opts["minH2"];
        $(".shop-bg").css('height', h2);

        var h4 = parseInt($(window).height()) - parseInt($(".header").outerHeight()) - parseInt($(".footer").outerHeight());
        h4 = h4 > opts["minH4"] ? h4 : opts["minH4"];
        $(".regform-bg").css('height', h4);

    }, // end setupFooter

    setupShopAssistFooter: function (opts) {

        var h3 = parseInt($(window).height()) - parseInt($(".header").outerHeight()) - parseInt($(".footer").outerHeight());
        h3 = h3 > opts["minH3"] ? h3 : opts["minH3"];
        $("#assist-bg").css('height', h3);

    }, //end setupShopAssistFoooter

    setupHolidayFooter: function (opts) {

        var h1 = parseInt($(window).height()) - parseInt($(".header").outerHeight()) - parseInt($(".footer").outerHeight());
        h1 = h1 > opts["minH1"] ? h1 : opts["minH1"];
        $("#dy-holiday").css('height', h1);

    }, //end setupHolidayFoooter

    setupProductGridFooter: function (opts) {
        //not sure the purpose of this but commenting out to fix footer bug on subcategory2
        /*
        var container = $(".productGrid-container");
        var h3 = parseInt($(window).height()) - parseInt($(".header").outerHeight()) - parseInt($(".footer").outerHeight());
        h3 = h3 > opts["minH3"] ? h3 : opts["minH3"];

        if ($.browser.msie && $.browser.version == "7.0") {
        container.css('min-height', h3 - 125);
        } else {
        container.css('height', h3 - 140);
        }

        */
    }, //end setupHolidayFoooter

    setupCredits: function () {

        // site credit hover event
        $("#siteCredits").hover(function () {
            var copy = $(this).attr("title");
            $(this).text(copy);
        }, function () {
            $(this).text("Credits");
        }).click(function () {
            window.open($(this).attr("href"));
            return false;
        });

    }, // end setupCredits

    setupSubscribe: function () {
        /* Subscribe Cheetahmail Layer (Footer)
        * change to ajax like call only when link is clicked.
        */
        $('.header .subscribeLink').click(function (e) {
            e.preventDefault();
            //get rid of anything else this link wants to do, sorry link.
            $('#subscribeBox').toggle();
        });
        $('#closeSubscribeBox a').click(function (e) {
            e.preventDefault();
            $('#subscribeBox').hide();
        });
    }, // end setupSubscribe

    setupGlobalPromo: function () {
        // event for global promo
        $("#globalpromo").click(function () {
            $(this).find("dd").show();
        });
        $("#globalpromo #globalpromo-close").click(function () {
            $(this).parent("dd").hide();
            return false;
        });

    }, // end setupGlobalPromo

    categoryPage: function () {

        if ($("#flashHolder").find(".flashBackup-hero") && $("#flashHolder").find(".flashBackup-hero").length > 0 && $("#flashHolder").find(".flashBackup-hero").attr("src") > '') {
            // move hero image to background as html backup
            $("#flashHolder.categoryLanding").css({
                'backgroundImage': 'url(' + $("#flashHolder").find(".flashBackup-hero").attr("src") + ')'
            });
        }


        $(".dropdown-holder .subnav .subnav-content").jScrollPane();

        $(".dropdown-holder .fdd .subnav-bg").css('height', $('.fdd .subnav-content ul').height() + 5);

        $(".dropdown-holder .fdd2 .subnav-bg").css('height', $('.fdd2 .subnav-content ul').height() + 5);

        // use system drop down for ipad
        if (navigator.userAgent.match(/iPad/i)) {
            $(".dropdown-holder li").css({ display: 'none' });
            $(".system-ddl").css({ display: 'block' });
            $(".system-ddl select").change(function () {
                location.href = document.getElementById('ctl00_mainContent_fdd_ddlSubcat').value;
            });
        }

        var promos = $(".promo-grid"),
            buttonTrigger = false;

        var navigation = function (promos, button) {

            var selected = promos.find(".item-on");

            //prev
            if (button == "prev") {

                if (selected.index() == 0) {

                    promos.find("li")
                            .removeClass("item-on")
                            .last().addClass("item-on");

                } else {
                    selected.removeClass("item-on")
                            .prev().addClass("item-on");
                }

                //next
            } else {

                if (selected.index() + 1 == promos.find("li").length) {

                    promos.find("li")
                        .removeClass("item-on")
                        .first().addClass("item-on");
                } else {

                    selected.removeClass("item-on")
                        .next().addClass("item-on");
                }

            }

        };

        if ($(".slideshow-item").length > 1) {

            $(".slideshow-items").cycle({
                fx: "scrollHorz",
                next: $(".next-btn"),
                prev: $(".prev-btn"),
                before: function () {
                    setTimeout(function () {
                        navigation(promos, "nextAuto");
                    }, 200);
                }
            });

        }

    }, // categoryPage

    categoryResize: function () {
        if (($('.landing-container').width() / $('.landing-container').height()) > 1.94) {
            $('.slide-hero').css({
                height: 'auto',
                width: '100%'
            });
        } else {
            $('.slide-hero').css({
                height: '100%',
                width: 'auto'
            });
        }

    },

    subCategoryPage: function () {
        $.productGrid();
        $.facets();
        var self = this;
        // Init and change handlers for hash changes.
        $(document).ready(function () {
            self.init_facebook();
            //$.address.tracker(null);
            $.address.init(function (event) {
                var cat = $.facets.impl.GetCategoriesArray();
                $.each(event.parameters, function (i, val) {
                    cat[parseInt(i) - 1] = val;
                });
                $.facets.impl.SetCategoriesArray(cat);
                $.facets.impl.searchParam.maxPrice = $.address.parameter("6");
            }).change(function (event) {
                var cat = $.facets.impl.GetCategoriesArray();
                $.each(event.parameters, function (i, val) {
                    cat[parseInt(i) - 1] = val;
                });

                if ($.address.parameter("page") === undefined || $.address.parameter("page") > 0) {
                    $.facets.impl.searchParam.page = ($.address.parameter("page") === undefined) ? 0 : ($.address.parameter("page") - 1);
                    $.facets.impl.searchParam.rows = -1;
                }
                else {
                    $.facets.impl.searchParam.page = 0;
                    $.facets.impl.searchParam.rows = 500;
                }

                $.facets.impl.SetCategoriesArray(cat);
                $.facets.impl.Search();
            });
            $(".dropdown-holder .subnav .subnav-content").jScrollPane({
                scrollbarMargin: 0
            });

            $(".dropdown-holder .fdd .subnav-bg").css('height', $('.fdd .subnav-content ul').height() + 5);

            $(".dropdown-holder .fdd2 .subnav-bg").css('height', $('.fdd2 .subnav-content ul').height() + 5);

            // use system drop down for ipad
            if (navigator.userAgent.match(/iPad/i)) {
                $(".dropdown-holder li").css({ display: 'none' });
                $(".system-ddl").css({ display: 'block' });
                $(".system-ddl select").change(function () {
                    location.href = document.getElementById('ctl00_mainContent_fdd_ddlSubcat').value;
                });
            }

        });

        var pageloaded = false;
        $(window).load(function () {
            pageloaded = true;

            //$.productGrid.impl.centerGrid();
        });
        // window resize
        $(window).resize(function (event) {
            if (pageloaded) {
                $.productGrid.impl.resizeGrid();

            }
        });


    }, // end subcategory page


    suites: function () {
        this.init_facebook();
        $('.suiteGrid .prod-detail-tip').bgiframe();
        $('.suiteGrid a.prod-thumbnail').tooltip({
            track: true,
            delay: 500,
            showURL: false,
            extraClass: "prodtip-image",
            bodyHandler: function () {

                //$(this).next(".prod-detail-tip").html();
                //$this.siblings(":not($(this))").find("a>img").fadeTo("slow","0.5");
                return $(this).next(".prod-detail-tip").html();
            }
        });

        //        $(".productDesc-tab dt span").toggle(function() {
        //            $(this).parents("dl").toggleClass("productDesc-tab-collapse").toggleClass("productDesc-tab-expand");
        //            $(this).text("View Details");

        //           
        //        }, function() {
        //            $(this).parents("dl").toggleClass("productDesc-tab-collapse").toggleClass("productDesc-tab-expand");
        //            $(this).text("Hide Details");

        //        });

        $('.suiteGrid a.prod-thumbnail').mouseover(function () {
            $("select").trigger("blur");
        });

        // start js for personal shopper iframe
        $("#ifr_contactPerShopper .iframeHolder").hide();
        $(".contactPerShopper").each(function () {
            $(this).click(function (e) {

                // e.preventDefault();

                //            $("#ifr_contactPerShopper").css("top", $(document).scrollTop()).show();
                $("#ifr_contactPerShopper").css({
                    height: $(document).height(),
                    width: $(document).width()
                }).show();

                // show personall shopper iframe
                $("#ifr_contactPerShopper iframe").attr("src", 'ContactPersonalShopper.aspx?itemId=' + $(this).attr("href")).load(function () {
                    $(this).parent(".iframeHolder").css("top", $(document).scrollTop()).fadeIn('slow');
                });

                return false;
            });
        });

        $(".btnClose").click(function () {
            // hide personal shopper iframe when close button is clicked
            $("#ifr_contactPerShopper").fadeOut('slow').find(".iframeHolder").hide();
            return false;
        });

        $("#bgblocker").click(function () {
            // hide personal shopper iframe when use clickes outside iframe area
            $("#ifr_contactPerShopper").fadeOut('slow').find(".iframeHolder").hide();
            return false;
        });


        // hover event for share dropdown
        $(".share-links").hover(function () {
            $(this).addClass("active");
        }, function () {
            $(this).removeClass("active");
        });

        $("#suggestContainer a").each(function (i) {
            var product = $(this);
            var productImgtitle = product.find("img").attr("alt");
            product.find("img").attr("alt", "").attr("title", "");
            product.attr("title", "");

            product.tooltip({
                track: true,
                delay: 0,
                showURL: false,
                extraClass: "p-tooltip",
                bodyHandler: function () {

                    return productImgtitle;
                }
            });

        });

        if ($("#recently-viewed").hasClass("enableCarousel")) {

            $(".recently-viewed-items").jcarousel();
        }

        // equal columns to maintain background
        //        $(window).load(function() {

        //            $("#leftNavContainer. #products").equalColumns();

        //        });

    }, // end suites page
    storeLocator: function () {

        $(".list .store").each(function () {

            var store = $(this);

            store.find(".store-details").click(function () {
                store.find(".store-details-modal").modal();
            });

        });

        $(".store-results-list .list").each(function () {
            var self = $(this);
            if (self.children().size() == 0) {
                self.remove();
            }
        });

        $(".store-results-container").each(function () {
            //
            //setup pagenav
            var list = $(".store-results-list .list");
            var totalPages = list.length;
            var pageDisplay = $(".pagenav li.page");
            var nextPage = $(".pagenav li.next");
            var prevPage = $(".pagenav li.prev");
            var viewAll = $('.pagenav li.view-all');
            var ul_width = 669;
            var currentPage = 1;

            $(".store-results-list").css("width", ((list.length + 1) * ul_width));

            var updatePaging = function () {
                pageDisplay.text(currentPage + " / " + totalPages);

                if (totalPages === 1 || totalPages === 0) {
                    prevPage.hide();
                    nextPage.hide();
                    viewAll.hide();
                } else {
                    if (currentPage === 1) {
                        prevPage.hide();
                        nextPage.show();
                        viewAll.show();
                    } else {
                        if (currentPage === totalPages) {
                            nextPage.hide();
                            prevPage.show();
                        } else {
                            nextPage.show();
                            prevPage.show();
                        }
                    }
                }
            }

            var resizeStoreContainer = function () {
                $('.store-container').removeClass('shop-bg');

                if (($('.store-results-list-container').height() + $('.hd').height() + 70) > $('.store-container').height()) {
                    $('.store-container').css('height', 'auto');
                }
            }

            updatePaging();

            prevPage.each(function () {
                $(this).find("a").click(function (e) {
                    e.preventDefault();
                    var offset;

                    if (currentPage === 2) {
                        offset = 0;
                    }
                    else {

                        var _next = currentPage - 2;

                        var offset = "-" + (_next * ul_width);

                    }

                    $(".store-results-list").animate({
                        "left": offset + "px"
                    }, 1000);

                    currentPage--;
                    updatePaging();
                    return false;
                });
            });

            nextPage.each(function () {
                $(this).find("a").click(function (e) {
                    e.preventDefault();
                    if (currentPage !== totalPages) {
                        var _next = currentPage;

                        var offset = "-" + (_next * ul_width);
                        $(".store-results-list").animate({
                            "left": offset + "px"
                        }, 1000);

                        currentPage++;
                        updatePaging();
                    }

                });
            });

            viewAll.click(function (e) {
                e.preventDefault();
                $(".store-results-list").css({
                    "width": 669,
                    "left": 0
                });
                prevPage.hide();
                nextPage.hide();
                viewAll.hide();
                resizeStoreContainer();
                pageDisplay.text("1/1");
            });


        });

        $(".storeResults").animate({
            "opacity": "1"
        }, 2000, function () {
        });


    }, // end store locator

    setupArchiveNav: function () {
        // used on timelinegrid.aspx and holiday shop

        var ie6 = ($.browser.msie && $.browser.version === "6.0") ? true : false;

        var $parent = $(".nav-archive"),
            $breadcrumb = $parent.find(".nav-archive-breadcrumb span"),
            $links = $parent.find(".nav-archive-item"),
            currentPage = $breadcrumb.text();

        $links.hover(function () {
            if (ie6) {
                DD_belatedPNG.fix('.archive-link, .carrot');
                $(this).find('.archive-thumb').css('display', 'block');
            }
            $breadcrumb.text($(this).find(".archive-thumb img").attr("alt"));
        },
            function () {
                if (ie6) {
                    DD_belatedPNG.fix('.archive-link, .carrot');
                    $(this).find('.archive-thumb').css('display', 'none');
                }
                $breadcrumb.text(currentPage);
            });
    },
    productDetail: function () {

        this.init_facebook();


        //        $(".productDesc-tab dt span").toggle(function() {
        //            $(this).parents("dl").toggleClass("productDesc-tab-collapse").toggleClass("productDesc-tab-expand");
        //            $(this).text("View Details");

        //            // equal columns to maintain background
        //            $("#leftNavContainer, #products").equalColumns();
        //        }, function() {
        //            $(this).parents("dl").toggleClass("productDesc-tab-collapse").toggleClass("productDesc-tab-expand");
        //            $(this).text("Hide Details");

        //            // equal columns to maintain background
        //            $("#leftNavContainer, #products").equalColumns();
        //        });

        // start js for personal shopper iframe
        $("#ifr_contactPerShopper .iframeHolder").hide();
        $(".contactPerShopper").each(function () {
            $(this).click(function (e) {

                // e.preventDefault();

                //            $("#ifr_contactPerShopper").css("top", $(document).scrollTop()).show();
                $("#ifr_contactPerShopper").show();
                // show personall shopper iframe
                $("#ifr_contactPerShopper iframe").attr("src", 'ContactPersonalShopper.aspx?itemId=' + $(this).attr("href")).load(function () {
                    $(this).parent(".iframeHolder").css("top", $(document).scrollTop()).fadeIn('slow');
                });

                return false;
            });
        });

        $(".btnClose").click(function () {
            // hide personal shopper iframe when close button is clicked
            $("#ifr_contactPerShopper").fadeOut('slow').find(".iframeHolder").hide();
            return false;
        });

        $("#bgblocker").click(function () {
            // hide personal shopper iframe when use clickes outside iframe area
            $("#ifr_contactPerShopper").fadeOut('slow').find(".iframeHolder").hide();
            return false;
        });


        // equal columns to maintain background
        //        $(window).load(function() {
        //            $("#leftNavContainer, #products").equalColumns();

        //        });
        // hover event for share dropdown
        $(".share-links").hover(function () {
            $(this).addClass("active");
        }, function () {
            $(this).removeClass("active");
        });

        if ($("#suggestContainer li").length > 3) {

            $("#suggestContainer ul").jcarousel({
                buttonNextHTML: "<div>Next</div>",
                buttonPrevHTML: "<div>Prev</div>"
            });

            $("#suggestContainer").addClass('enableCarousel');
        }

        $("#suggestContainer a").each(function (i) {
            var product = $(this);
            var productImgtitle = product.find("img").attr("alt");
            product.find("img").attr("alt", "").attr("title", "");
            product.attr("title", "");

            product.tooltip({
                track: true,
                delay: 0,
                showURL: false,
                extraClass: "p-tooltip",
                bodyHandler: function () {

                    return productImgtitle;
                }
            });

        });


        if ($("#recently-viewed").hasClass("enableCarousel")) {

            $(".recently-viewed-items").jcarousel();
        }

        //about collection popup

        $("#product-links .collection-link").click(function () {

            var info = $("#collection-info"),
                close = $("#collection-info .collection-close");

            if ($("#collection-info img").attr("class") == "collection-img") {
                info.css({ "width": 775 + "px" });
            }
            else {
                info.css({ "width": 500 + "px" });
            }

            info.modal({
                opacity: 30,
                overlayCss: { backgroundColor: "#000" }
            });

            close.click(function () { $.modal.close(); });

        });

        // stop mouse hover event for quickbuy..
        if ($("body").hasClass("quickbuy")) {
            $("select").focus(function (e) {
                $(this).mouseover(function (e) {
                    $.productGrid.impl.stopEvent(e);
                }).mouseout(function (e) {
                    $.productGrid.impl.stopEvent(e);
                });
            });
        }


    } // end product detail
};

(function(){
    // pass in a set of columns and function will set all to the max height
    $.fn.equalColumns = function(settings){
    
        settings = jQuery.extend({
            maxH: 0
        }, settings);
        var columns = $(this);
        
        columns.each(function(i){
            //find the max height
            
            $(this).height("auto");
            settings["maxH"] = (settings["maxH"] > $(this).innerHeight()) ? settings["maxH"] : $(this).innerHeight();
            
        });
        
        columns.each(function(i){
            //set max height
            $(this).css("height", settings["maxH"] + "px");
        });
        return this;
    }; //Close function
})(jQuery);


$(document).ready(function(){
    $.dy.init();
});


var windowOpenedSuccessfully = "false";
function stopDef(e){
    if (e && e.preventDefault) 
        e.preventDefault();
    else 
        if (window.event && window.event.returnValue) 
            window.eventReturnValue = false;
}

function focusAndCheck(openedWindow, displayError){
    if (!openedWindow || (openedWindow.closed || !openedWindow.focus)) {
        if (displayError) {
            alert("Popup blocking software may be stopping this operation.  Please disable any popup blockers and try again.");
        }
        return false;
    }
    else {
        openedWindow.focus();
        return true;
    }
}

function replaceText(inString, oldText, newText){
    return (inString.split(oldText).join(newText));
}

function openPopup(inputUrl, inputWidth, inputHeight){

    var popupWindow = "";
    var stringArray = inputUrl.split(".aspx");
    
    var pagePath = replaceText(stringArray[0], '/en/shoponline/', '');
    
    if (!popupWindow || popupWindow.closed) {
        windowOpenedSuccessfully = "false";
        popupWindow = window.open(inputUrl, pagePath, 'width=' + inputWidth + ',height=' + inputHeight + ',scrollbars=00');
        windowOpenedSuccessfully = focusAndCheck(popupWindow, true);
    }
}

function openPopupGeneric(inputUrl, inputWidth, inputHeight, scrollbars){

    //	var popupWindow = "";
    
    //	if (!popupWindow || popupWindow.closed)
    //	{
    //		windowOpenedSuccessfully = "false";
    //		popupWindow = window.open(inputUrl, "DavidYurmanPopup", 'width=' + inputWidth + ',height=' + inputHeight + ',scrollbars=' + scrollbars);
    //		windowOpenedSuccessfully = focusAndCheck(popupWindow, true);
    //    }
    
    
    var popupWindow = "";
    
    if ($.browser.msie && (parseInt($.browser.version) === 6.0)) {
    
        var _name = "DavidYurmanPopup" + parseInt(Math.random() * 100);
        popupWindow = window.open(inputUrl, _name, 'width=' + inputWidth + ',height=' + inputHeight + ',scrollbars=' + scrollbars);
        
    }
    else {
    
    
        if (!popupWindow || popupWindow.closed) {
            windowOpenedSuccessfully = "false";
            popupWindow = window.open(inputUrl, "DavidYurmanPopup", 'width=' + inputWidth + ',height=' + inputHeight + ',scrollbars=' + scrollbars);
            windowOpenedSuccessfully = focusAndCheck(popupWindow, true);
        }
        
        
    }
    
}

function openPopupOnlineChat(){
    var confirmWin = null;
    confirmWin = window.open('https://server.iad.liveperson.net/hc/LPneimanmarcus/?cmd=file&file=visitorWantsToChat&site=LPneimanmarcus&SESSIONVAR!skill=Yurman&referrer=' + escape(document.location), 'chatwindow', 'width=485,height=380,scrollbars=yes,status=yes');
}

function checkEnter(e, url){
    var characterCode
    
    if (e && e.which) { //if which property of event object is supported (NN4)
        e = e;
        characterCode = e.which; //character code is contained in NN4's which property
    }
    else {
        e = event;
        characterCode = e.keyCode; //character code is contained in IE's keyCode property
    }
    
    if (characterCode == 13) { //if generated character code is equal to ascii 13 (if enter key)
        submitSearchForm(url);
        return false;
    }
    else {
        return true;
    }
}

function printpage(){
    window.print();
}

function closeWindow(){
    window.close();
}

var selected_id = null;
var dom = document.getElementById;

function swapIt(id, newclass){
    if (dom) {
        if (selected_id != id) {
        
            el = document.getElementById(id);
            el.className = newclass;
            el.style.cursor = "hand";
            el.style.cursor = "pointer";
            
        }
    }
}

function down(id, oldclass, newclass){
    if (dom) {
        if (selected_id != null) {
            document.getElementById(selected_id).className = oldclass;
        }
        el.className = newclass;
        selected_id = id;
    }
}

function setElementContent(id, content){
    document.getElementById(id).value = content;
}

function f_clientWidth(){
    return f_filterResults(window.innerWidth ? window.innerWidth : 0, document.documentElement ? document.documentElement.clientWidth : 0, document.body ? document.body.clientWidth : 0);
}

function f_clientHeight(){
    return f_filterResults(window.innerHeight ? window.innerHeight : 0, document.documentElement ? document.documentElement.clientHeight : 0, document.body ? document.body.clientHeight : 0);
}

function f_scrollLeft(){
    return f_filterResults(window.pageXOffset ? window.pageXOffset : 0, document.documentElement ? document.documentElement.scrollLeft : 0, document.body ? document.body.scrollLeft : 0);
}

function f_scrollTop(){
    return f_filterResults(window.pageYOffset ? window.pageYOffset : 0, document.documentElement ? document.documentElement.scrollTop : 0, document.body ? document.body.scrollTop : 0);
}

function f_filterResults(n_win, n_docel, n_body){
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel))) 
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

var showFilter = function(x){

    stopDef();
    var collArr = ["ByCollection", "ByGemstone", "ByMetal"]
    
    $(collArr).each(function(){
        if (this == x) {
            $('#' + x).slideDown(200, function(){
                $("#leftNavContainer, #products, #rightContentContainer").equalColumns();
                return false;
            });
        }
        else {
        
            $('#' + this).slideUp(200);
        }
        
    });
    
    $("#" + x + ":not(:visible)").slideDown(200);
    
    
    return false;
}

function redirecttoregister(){
    var email = document.aspnetForm.ctl00_footer_emailRegister.value;
    if (email != "") {
        window.location = "/registeremail.aspx?email=" + email;
    }
    else {
        window.location = "/registeremail.aspx";
    }
}

function redirecttosearch(){
    var searchKeyword = document.aspnetForm.ctl00_header_searchInputBox.value
    
    if (searchKeyword != "") {
        window.location = "/shoponline/search.aspx?keyword=" + searchKeyword + "&page=1";
    }
    else {
        window.location = "/shoponline/search.aspx";
    }
}

function entsub(myform){
    if (window.event && window.event.keyCode == 13) 
        myform.submit();
    else 
        return true;
}

function zpad(n){
    if (n < 10) 
        n = "0" + n;
    
    return n;
}

function addInputSubmitEvent(input, id){
    input.onkeydown = function(e){
        e = e || window.event;
        if (e.keyCode == 13) {
            __doPostBack(id, '');
        }
    };
}

/*
var resizeTimer = null;
// vertical center content on homepage 
// added 8/22/2008 by milly kwok
function verticalCenter(){

    // vertical align
    var windowH = $(window).height();
    var docH = $("#wrapper").innerHeight();
    var minH = 660;
    var maxBox = 780;
    
    docH = (docH < minH) ? minH : docH;
    
    //If page is dynamic height, use the imaginary max box
    if (docH > maxBox) {
        var margin = (windowH - maxBox) / 2;
        margin = margin > 0 ? margin : 0;
        $("#container").css("margin-top", margin);
    }
    //Else smaller box, center in window
    else {
        var margin = (windowH - docH) / 2;
        margin = margin > 0 ? margin : 0;
        $("#container").css("margin-top", margin);
    }
    resizeTimer = null;
}
*/

var trackPage = function(pageName){
    s.pageName = pageName;
    s.t();
}

function flashPutHref(newHash){
    location.hash = newHash;
}


/* Fix MSIE6 Image flicker */
var m = document.uniqueID /*IE*/ && document.compatMode /*>=IE6*/ && !window.XMLHttpRequest /*<=IE6*/ && document.execCommand;
try {
    if (!!m) {
        m("BackgroundImageCache", false, true) /* = IE6 only */
    }
} 
catch (oh) {
};

//$(document).bind('bagLoaded', function() {
//    $.shoppingBag.opts = { 
//        prop50: "<%=NMConfiguration.Section.OmnitureProp50%>",
//        imageserver: "<%=ImagePathController.imageServerUrl %>"
//     };
//    
//});

function serialize(mixed_value) {
    // Returns a string representation of variable (which can later be unserialized)  
    // 
    // version: 1004.2314
    // discuss at: http://phpjs.org/functions/serialize
    // +   original by: Arpad Ray (mailto:arpad@php.net)
    // +   improved by: Dino
    // +   bugfixed by: Andrej Pavlovic
    // +   bugfixed by: Garagoth
    // +      input by: DtTvB (http://dt.in.th/2008-09-16.string-length-in-bytes.html)
    // +   bugfixed by: Russell Walker (http://www.nbill.co.uk/)
    // +   bugfixed by: Jamie Beck (http://www.terabit.ca/)
    // +      input by: Martin (http://www.erlenwiese.de/)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: utf8_encode
    // %          note: We feel the main purpose of this function should be to ease the transport of data between php & js
    // %          note: Aiming for PHP-compatibility, we have to translate objects to arrays
    // *     example 1: serialize(['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: 'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}'
    // *     example 2: serialize({firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'});
    // *     returns 2: 'a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}'
    var _getType = function(inp) {
        var type = typeof inp, match;
        var key;
        if (type == 'object' && !inp) {
            return 'null';
        }
        if (type == "object") {
            if (!inp.constructor) {
                return 'object';
            }
            var cons = inp.constructor.toString();
            match = cons.match(/(\w+)\(/);
            if (match) {
                cons = match[1].toLowerCase();
            }
            var types = ["boolean", "number", "string", "array"];
            for (key in types) {
                if (cons == types[key]) {
                    type = types[key];
                    break;
                }
            }
        }
        return type;
    };
    var type = _getType(mixed_value);
    var val, ktype = '';

    switch (type) {
        case "function":
            val = "";
            break;
        case "boolean":
            val = "b:" + (mixed_value ? "1" : "0");
            break;
        case "number":
            val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;
            break;
        case "string":
            mixed_value = this.utf8_encode(mixed_value);
            val = "s:" + encodeURIComponent(mixed_value).replace(/%../g, 'x').length + ":\"" + mixed_value + "\"";
            break;
        case "array":
        case "object":
            val = "a";
            /*
            if (type == "object") {
            var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/);
            if (objname == undefined) {
            return;
            }
            objname[1] = this.serialize(objname[1]);
            val = "O" + objname[1].substring(1, objname[1].length - 1);
            }
            */
            var count = 0;
            var vals = "";
            var okey;
            var key;
            for (key in mixed_value) {
                ktype = _getType(mixed_value[key]);
                if (ktype == "function") {
                    continue;
                }

                okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key);
                vals += this.serialize(okey) +
                        this.serialize(mixed_value[key]);
                count++;
            }
            val += ":" + count + ":{" + vals + "}";
            break;
        case "undefined": // Fall-through
        default: // if the JS object has a property which contains a null value, the string cannot be unserialized by PHP
            val = "N";
            break;
    }
    if (type != "object" && type != "array") {
        val += ";";
    }
    return val;
}

