jQuery.stjohn = {
    init: function() {

        /* 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) { };

        // Site credits
        $('#sitecredits a').hover(
	        function() { $(this).text('CreateThe Group'); },
	        function() { $(this).text('Site Credits'); }
        );
        $('#sitecredits a').click(function(e) {
            e.preventDefault();
        });

        $("#utilitynav #careers a").click(function() {

            var src = $(this).attr("href");
            $(this).attr("href", "");

            window.open(src, "Careers");
            return false;

        });

        //$(".search .frmtext").val("Search Products");

        // search box
        /*
        $(".search .frmtext").focus(function(){
        $(this).val(""); 
        }).blur(function(){
        if($(this).val()==""){
        $(this).val("Search Products");
        }
        });
        */

        

        //initialize the global promo
        $.stjohn.globalPromo();

        //parse out the querystring into an object. for easy access in js
        queryString = jQuery.query = {};
        var params = location.search.replace(/^\?/, '').split('&');
        for (var i = params.length - 1; i >= 0; i--) {
            var p = params[i].split('='), key = p[0];
            if (key) queryString[key] = p[1];
        }


    }, //end init
    termsConditons: function() {

        $(".terms-open").click(function() {
            $("body").append("<div id='tc'></div>");

            initjscrollPane = function() {
                $("#tc").jScrollPane({
                    showArrows: true,
                    scrollbarWidth: 15,
                    scrollbarMargin: 0
                });
            }

            $("#tc").load("/en-us/termsofuse/ .content", "", initjscrollPane).dialog({
                autoOpen: false,
                draggable: false,
                bgiframe: true,
                dialogClass: "tc-dialog",
                show: "fade",
                height: 450,
                width: 570,
                modal: true,
                resizable: false,
                stack: false,
                overlay: {
                    opacity: 0.5,
                    background: "black"
                },
                show: {
                    effect: "slide",
                    options: { direction: "up" },
                    speed: "2000"
                },
                open: function(e, ui) {


                    //$(this).fadeIn();

                },
                close: function(e, ui) { }

            });
            $("#tc").dialog("open")

        });
    }, //end terms and conditions    
    productTooltip: function() {

        //** setup tooltip on product hover **/
        $(".p-grid .p-image").tooltip({
            track: true,
            bgiframe: true,
            delay: 0,
            showURL: false,
            //fade: 250,
            extraClass: "p-tooltip p-content",
            bodyHandler: function() {

                // suppress default tooltip text for proudct images
                $(this).find("img").attr("alt", "");
                $(this).find("img").attr("title", "");

                return $(this).parents("li").find(".p-info").html();
            }
        });

    }, //productTooltip

    initForm: function() {
        var addTabIndex = function() {
            /*
            $(":input, .button").each(function(i){
				
				$(this).attr("tabindex",i);
            });
            */
        }

        $(":input").mouseover(function() {
            $(this).addClass("frmhover");
        }).mouseout(function() {
            $(this).removeClass("frmhover");
        }).focus(function() {
            $(this).addClass("frmfocus");
        }).blur(function() {
            $(this).removeClass("frmfocus frmhover");
        })

        addTabIndex();

    }, //initForm
    productGrid: function() {
        $.stjohn.productTooltip();


        //*************
        // EDIT: Removed fadeout functionality w/ return
        //*************
        //** fade out all other products on hover **/
        $(".p-grid>li:visible").each(function() {
            //return;

            var $this = $(this);

            $this.hover(
					function() {
					    $(this).siblings(":not($(this))").addClass("over");
					},
					function() {
					    $(this).siblings(":not($(this))").removeClass("over");
					}
				);
        });

        //			$(".p-grid").pagination({
        //				childElement:	"li"
        //				//itemsperpage:		32
        //				//viewall:true
        //			});	
        //			
        //			
        //			
        //			$(".preloader").hide();
        $(".p-grid").show();


    }, // end productGrid
    productDetail: function() {

        if (queryString["print"]) {

            return;
        } else {

            $.stjohn.productTooltip();

            $(".sizeguide").dialog({
                autoOpen: false,
                bgiframe: true,
                draggable: false,
                autoResize: false,
                show: "fade",
                height: "232px",
                width: "733px",
                modal: true,
                resizable: false,
                stack: false,
                overlay: {
                    opacity: 0.5,
                    background: "black"
                },
                open: function() {
                    $(this).fadeIn();
                },
                close: function() { }

            });

            $(".lnk-sizeguide").click(function() {
                $(".sizeguide").dialog("open");
                return false;
            });



            $("#btn-emailFriend").click(function() {

                var url = $(this).attr("href");
                $(this).attr("target", "");

                window.open(url, "email", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=670, height=505");
                return false;

            });



            $(".slideshow").slideshow({
                paging: false,
                name: null,
                callback: function() {
                    $(".column-w").trigger("mouseleave").trigger("mouseenter");
                }
            });


            $(".column-w .haszoom").zoom({
                parent: ".column-w"
            });

            $(".btn-print").click(function() {
                var url = $(this).attr("href");
                window.open(url, "print", "toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes, width=640, height=480");
                return false;
            });

            $(".btn-printpage").click(function() {
                window.print();
            });

            // add scrollbars to description
            $(".p-description").jScrollPane({
                showArrows: true,
                scrollbarWidth: 15,
                scrollbarMargin: 0
            });

            $.stjohn.initForm();
        }
    },  // end product detail
    suites: function() {

        if (queryString["print"]) {

            return;
        } else {

            // add scrollbars to description
            $(".suite-description").jScrollPane({
                showArrows: true,
                scrollbarWidth: 15,
                scrollbarMargin: 0
            });

            $.stjohn.productDetail();

            $('<div class="p-image-dialog"></div>').dialog({
                autoOpen: false,
                draggable: false,
                bgiframe: true,
                show: "fade",
                height: 443,
                width: 328,
                modal: true,
                resizable: false,
                stack: false,
                overlay: {
                    opacity: 0.8,
                    background: "black"
                },
                open: function() {
                    $(".ui-dialog-content").find(".haszoom").zoom({
                        parent: ".ui-dialog-content"
                    });
                    $(this).fadeIn();
                    //console.log($(this).parents(".ui-dialog").find(".zoomBox"));
                    //$(this).parents(".ui-dialog").find(".sensor").css("top","30px");

                },
                close: function() { }

            });




            //	    $(".p-list .haszoom").zoom({
            //		    parent: $(".p-image .p-image-detail")
            //	    });

            $(".btn-detail").each(function() {

                var content = $(this).siblings(".p-image-detail").clone().html();


                $(this).click(function(e) {
                    e.preventDefault();
                    $(".p-image-dialog").find(".ui-dialog-content").html(content).end().dialog("open");
                });


            });

        } // end if non-print		
    }, //end suites
    search: function() {
        $(":input").mouseover(function() {
            $(this).addClass("frmhover");
        }).mouseout(function() {
            $(this).removeClass("frmhover");
        }).focus(function() {
            $(this).addClass("frmfocus");
        }).blur(function() {
            $(this).removeClass("frmfocus frmhover");
        });

        //			$.stjohn.productTooltip();

        //			//** fade out all other products on hover **/
        //			$(".p-grid>dt:visible").each(function(){
        //				var $this = $(this);

        //				$this.hover(
        //					function(){
        //						$(this).siblings(":not($(this))").addClass("over");
        //					},
        //					function(){
        //						$(this).siblings(":not($(this))").removeClass("over");
        //					}
        //				);


        //			});
        //			
        //			
        //			
        //			//$(".preloader").hide();
        //			$(".p-grid").show();


    }, // end search	
    helpLink: function() {
        var $this = $("#help");
        $this.find("dt a").click(function() {
            $this.find("dd").fadeIn();

        });

        $this.find(".help-close").click(function() {
            $this.find("dd").fadeOut();
        });



    }, // end help
    globalPromo: function() {
        var $this = $("#globalpromo");

        $this.find("dt a").click(function() {
            $this.find("dd").fadeIn();
            return false;
        });

        $this.find(".btn-close").click(function() {
            $this.find("dd").fadeOut();
        });


    }, // end globalpromo
    registerHelp: function() {
        $(".registerHelp").each(function() {
            var $this = $(this);

            $this.find("dt a").hover(function() {
                $this.find("dd").fadeIn(300);
            },
	        function() {
	            $this.find("dd").fadeOut(300);
	        }).click(function() {
	            return false;
	        });


            /*$this.find("dt a").click(function(){
	           
            return false;
            });
    	    
	        $this.find(".btn-close").click(function(){
            $(this).parents("dd").fadeOut();
            });*/

        });


    }, // end passwordHelp	
    checkout: function() {
        $.stjohn.helpLink();
        $.stjohn.initForm();

        $(".btn-print").click(function() {
            var url = location.pathname + "?print=true";
            window.open(url, "print", "status=0,scrollbars=1,height=480,width=640,resizable=1,directories=0,toolbar=0,location=0,menubar=1");
            return false;
        });

        $(".btn-printpage").click(function() {
            window.print();
        });

    },  // end checkout


    myaccount: function() {

        $.stjohn.helpLink();
        $.stjohn.registerHelp();
        $.stjohn.initForm();
        $.stjohn.termsConditons();


    }, // end myaccount

    assistance: function() {


        $(".helpTabs,.commerceTabs,.securityTabs,.communityTabs").tabs({
            select: function(e, ui) {
                location.href = ui.tab.href;


                if ((ui.tab.hash.indexOf("commerce") > 0) || (ui.tab.rel.indexOf("commerce") > 0)) {
                    $(".commerceTabs").show();
                } else {
                    $(".commerceTabs").hide();


                }


                if ((ui.tab.hash.indexOf("community") > 0) || (ui.tab.rel.indexOf("community") > 0)) {


                    $(".communityTabs").show();
                } else {
                    $(".communityTabs").hide();
                }

            },
            fx: { opacity: 'toggle' },
            show: function(e, ui) {
                $("#nav-container").equalColumns({
                    maxH: $(".content").outerHeight({ margin: true })
                });
            }
        });


        if (location.hash.substring(1) != "") {
            $(".helpTabs,.commerceTabs,.securityTabs,.communitytabs").tabs("select", '#' + location.hash.substring(1));

            if (location.hash.substring(1).indexOf("commerce") >= 0) {
                $(".commerceTabs").show();
                $(".helpTabs").tabs("select", '#commerce');
            } else {
                $(".commerceTabs").hide();
            }

            if (location.hash.substring(1).indexOf("community") >= 0) {
                $(".communityTabs").show();
                $(".helpTabs").tabs("select", '#community');
            } else {
                $(".communityTabs").hide();
            }

            if (location.hash.substring(1).indexOf("security") >= 0) {
                $(".helpTabs").tabs("select", '#security');
                $(".securityTabs").tabs("select", '#' + location.hash.substring(1));

            }

            if (location.hash.substring(1).indexOf("garment") >= 0) {

                $(".helpTabs").tabs("select", '#garment');
            }








        } else {
            $(".helpTabs").tabs("select", '#commerce');

            $(".communityTabs").hide();
        }

        $("#csContact").dialog({
            autoOpen: false,
            bgiframe: true,
            draggable: false,
            autoResize: false,
            show: "fade",
            height: "300px",
            width: "300px",
            modal: true,
            resizable: false,
            stack: false,
            overlay: {
                opacity: 0.5,
                background: "black"
            },
            open: function() {
                $(this).fadeIn();
            },
            close: function() { }

        });

        $(".btn-contact").click(function() {
            $("#csContact").dialog("open");
            return false;

        });
        $("#csContact").hide();
        $.stjohn.initForm();

        $(".btn-print").click(function() {

            var url = location.pathname + "?print=true" + "#" + location.hash.substring(1);
            window.open(url, "print", "status=0,scrollbars=1,height=480,width=640,resizable=1,directories=0,toolbar=0,location=0,menubar=1");
            return false;
        });

        $("#nav-container").equalColumns({
            maxH: $(".content").outerHeight({ margin: true })
        });

    }, // end help
    press: function() {

        $("dd").hide();

        $("#nav-container").equalColumns({
            maxH: $("#content-container").height()
        });

        function resetHeight() {

            $("#nav-container").equalColumns({
                maxH: $(".grid-c").outerHeight({ margin: true })
            })
        }

        $(".column-w dt>a").click(function(e) {
            e.preventDefault();
            $("dt").fadeOut("slow");
            $("h1:not('.title')").fadeOut("slow");
            $(this).parents("dt").next().animate({ opacity: 1.0 }, 1000).fadeIn("slow", resetHeight);

        });


        $(".column-w a.backLink").click(function(e) {
            e.preventDefault();
            $("dd").fadeOut("slow");
            $("dt").animate({ opacity: 1.0 }, 700).fadeIn("slow");
            $("h1:not('.title')").animate({ opacity: 1.0 }, 700).fadeIn("slow", resetHeight);

        });

    } // end press		
}
    
// open popup
$("a.chatPopup").click(function() {
    window.open('https://server.iad.liveperson.net/hc/LPneimanmarcus/?cmd=file&file=visitorWantsToChat&site=LPneimanmarcus&SESSIONVAR!skill=St%20John&referrer=%27+' + escape(document.location) + '+ %27','chat', 'width=470, height=320,status= 1,resizable=0,scrollbars=0');          
    return false;
});




(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);

        $(this).each(function(i) {
            //set max height
            $(this).css("height", settings["maxH"]);
        });
        return this;
    }; //Close function

})(jQuery);
