jQuery.dy = {

    init: function() {
        // initializing code for all pages

        // 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;
        });

        // search box
        //        $("#topNav .searchBox").focus(function() {
        //            $(this).val("");
        //        }).blur(function() {
        //            if ($(this).val() == "") {
        //                $(this).val("SEARCH");
        //            }
        //        });


        /* Subscribe Cheetahmail Layer (Footer)
        * change to ajax like call only when link is clicked.
        */
        $('#footerLeft .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();
        });

        $('.imageButton').each(function() {
            $(this).hover(
                function() { $(this).animate({ opacity: 0.99 }, 1) },
                function() { $(this).animate({ opacity: 0.6 }, 1) }
            );
        });

        $('.imageButton2').each(function() {
            $(this).hover(
                function() { $(this).animate({ opacity: 0.7 }, 1) },
                function() { $(this).animate({ opacity: 1 }, 1) }
            );
        });


        $.shoppingBag();

    },  // end init
    categoryPage: function() {

        $(window).load(function() {
            $.dy.promoGrid();
        });

        $(window).load(function() {
            // equal columns to maintain background
            $("#leftNavContainer, #rightContentContainer").equalColumns();

        });

    }, // end category page
    promoGrid: function() {

        var promos = $(".promo-grid li");

        promos.each(function(i) {
            $(this).fadeIn(i * i * 50);
        });
    }, // animation for promogrid
    subCategoryPage: function() {


        // collection of li that are not parents of nested lists. 
        // Does not apply on view all pages
        var productList = $(".productGrid:not(.viewall) li:not(:has('ul'))");




        $(productList).each(function(i) {
            //** fade out all other products on hover **/
            var liItem = $(this);

            liItem.hover(function() {
                $(this).stop().siblings().addClass("over");
            }, function() {
                $(this).stop().siblings().removeClass("over");
            });
        });



        $(productList).find("a.productImg").each(function(i) {
            //** setup tooltip on product hover **/
            var productImg = $(this);

            productImg.attr("title", "");
            productImg.find("img").attr("title", "");

            productImg.tooltip({
                track: true,
                delay: 0,
                showURL: false,
                extraClass: "p-tooltip",
                bodyHandler: function() {
                    //$this.siblings(":not($(this))").find("a>img").fadeTo("slow","0.5");
                    return productImg.next().find("a").text();
                }
            });


        });

        $(window).load(function() {
            // equal columns to maintain background
            $("#leftNavContainer, #rightContentContainer").equalColumns();

        });

    }, // end subcategory page
    subCategory2Page: function() {

        function showMoonPhases() {
            var xPos = 200;
            var yPos = 200;
            var width = 650;
            var height = 450;

            var features = "location=no,menubar=no,scrollbars=no,status=no,titlebar=no,toolbar=no,resizable=no,directories=no,";
            features += "height=" + height + ",width=" + width + ",screenX=" + xPos + ",screenY=" + yPos;

            window.open("/html/moonphases.html", "MOONPHASES", features);
        }

        //Fix moon phases popup link
        $('#Top').find("a:contains('MOON PHASES')").attr("href", "javascript:showMoonPhases()");

        var productList = $(".productGrid:not(.viewall) .largeThumb, .productGrid:not(.viewall) .smallThumbset li");  // collection of li that are not parents of nested lists



        //** setup tooltip on product hover **/
        productList.each(function(i) {


            //** fade out all other products on hover **/
            var liItem = $(this);

            liItem.append('<div class="bgBlocker"></div>');
            liItem.hover(
		                function() {
		                    productList.not(this).addClass("over");
		                },
		                function() {
		                    productList.removeClass("over");
		                }
		            );
        });

        $(productList).find("a.productImg").each(function(i) {
            var productImg = $(this);

            productImg.attr("title", "");
            productImg.find("img").attr("title", "");

            productImg.tooltip({
                track: true,
                delay: 0,
                showURL: false,
                extraClass: "p-tooltip",
                bodyHandler: function() {
                    //$this.siblings(":not($(this))").find("a>img").fadeTo("slow","0.5");
                //console.log(productImg.next().find("a").html());

                return productImg.next().find("a").text();
                }
            });

        });

        $(window).load(function() {
            // equal columns to maintain background
            $("#leftNavContainer, #rightContentContainer").equalColumns();

        });
    }, // end subcategory2 page

    suites: function() {
        $('.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");

            // equal columns to maintain background
            //            $("#leftNavContainer").equalColumns({
            //                maxH: $("#products").innerHeight()
            //            });
        },
        function() {
            $(this).parents("dl").toggleClass("productDesc-tab-collapse").toggleClass("productDesc-tab-expand");
            $(this).text("Hide Details");

            // equal columns to maintain background
            //            $("#leftNavContainer").equalColumns({
            //                maxH: $("#products").innerHeight()
            //            });
        }
        );

        $('.suiteGrid a.prod-thumbnail').mouseover(
	                function() { $("select").trigger("blur"); }
	            );
        // start js for personal shopper iframe 

        $("#contactPerShopper").click(function(e) {
            e.preventDefault();
            // show personall shopper iframe
            $("#ifr_contactPerShopper iframe").attr("src", 'ContactPersonalShopper.aspx?itemId=' + $(this).attr("href")).load(function() {
                $("#ifr_contactPerShopper").fadeIn('slow');
            });


        })

        $(".btnClose").click(function() {
            // hide personal shopper iframe when close button is clicked
            $("#ifr_contactPerShopper").fadeOut('slow');
        });

        $("#bgblocker").click(function() {
            // hide personal shopper iframe when use clickes outside iframe area                 
            $("#ifr_contactPerShopper").fadeOut('slow');
        });

        $(".lnkprint").click(function() {
            window.open("productprintpreview.aspx?folderid=" + escape("<%=requestedBreadCrumb %>") + "&itemId=<%=productCollection.ItemId %>", "print", "width=640,height=610,scrollbars=yes,status=no,resizeable=no,toolbar=yes,location=no,directories=no,menubar=yes")

        });
        // hover event for share dropdown
        $(".share-links").hover(
            function() { $(this).addClass("active"); },
            function() { $(this).removeClass("active"); }
        );
        // equal columns to maintain background
        $(window).load(function() {

            $("#leftNavContainer. #products").equalColumns();

        });

    }, // end suites page
    storeLocator: function() {

        $("#storeLocator #flashcontainer").bgiframe();

        $(".store-results-container").each(function() {
            //
            //setup pagenav
            var list = $(".boutiques ul:not('.storeLegend'), .stores ul:not('.storeLegend')");
            var totalPages = Math.ceil(list.length / 3);
            var pageDisplay = $(".pagenav li.page");
            var nextPage = $(".pagenav li.next");
            var prevPage = $(".pagenav li.prev");
            var currentPage = 1;

            $(".store-results-list").css("width", ((list.length + 1) * 250));


            var updatePaging = function() {
                pageDisplay.text(currentPage + " / " + totalPages);

                if (totalPages === 1) {
                    prevPage.hide();
                    nextPage.hide();
                } else if (currentPage === 1) {
                    prevPage.hide();
                    nextPage.show();
                } else if (currentPage === totalPages) {
                    nextPage.hide();
                    prevPage.show();
                } else {
                    nextPage.show();
                    prevPage.show();

                }
            }

            updatePaging();
            prevPage.each(function() {
                $(this).find("a").click(function(e) {
                    e.preventDefault();
                    var offset;

                    if (currentPage === 2) {
                        offset = 0;
                    } else {

                        var _bwidth = 0;
                        var _next = ((currentPage - 2) * 3);

                        if ($(".boutiques").length > 0) {
                            _bwidth = $(".boutiques").width() + 25;
                            _next = _next - $(".boutiques ul").length;
                        }

                        var offset = "-" + (_bwidth + (_next * 250));


                    }
                    $(".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 _bwidth = 0;
                        var _next = (currentPage * 3);

                        if ($(".boutiques").length > 0) {
                            _bwidth = $(".boutiques").width() + 25;
                            _next = _next - $(".boutiques ul").length;
                        }

                        var offset = "-" + (_bwidth + (_next * 250));
                        $(".store-results-list").animate({ "left": offset + "px" }, 1000);

                        currentPage++;
                        updatePaging();

                    }

                });
            });

        });

        $(".storeResults").animate({ "opacity": "1" }, 2000, function() { })


    }, // end store locator
    productDetail: function() {


        $(".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();
        }


        );

        $(".btnClose").click(function() {
            // hide personal shopper iframe when close button is clicked
            $("#ifr_contactPerShopper").fadeOut('slow');
        });

        $("#bgblocker").click(function() {
            // hide personal shopper iframe when use clickes outside iframe area                 
            $("#ifr_contactPerShopper").fadeOut('slow');
        });


        // 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"); }
        );
    } // 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=0');
		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){};
