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
        jQuery('#sitecredits a').hover(
	        function() { jQuery(this).text('CreateThe Group'); },
	        function() { jQuery(this).text('Site Credits'); }
        );
        jQuery('#sitecredits a').click(function(e) {
            e.preventDefault();
        });

        jQuery("#utilitynav #careers a").click(function() {

            var src = jQuery(this).attr("href");
            jQuery(this).attr("href", "");

            window.open(src, "Careers");
            return false;

        });
        //initialize the global promo
       // jQuery.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
    

    productDetail: function() {

        if (queryString["print"]) {

            return;
        } else {

            jQuery("#btn-emailFriend").click(function() {

                var url = jQuery(this).attr("href");
                jQuery(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;

            });

            jQuery(".column-w .haszoom").zoom({
                parent: ".column-w"
            });

            jQuery(".btn-print").click(function() {
                var url = jQuery(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;
            });

            jQuery(".btn-printpage").click(function() {
                window.print();
            });
            // add scrollbars to description

           // jQuery.stjohn.initForm();
        }
    },  // end product detail
    suites: function() {

        if (queryString["print"]) {

            return;
        } else {

            jQuery.stjohn.productDetail();

            jQuery(".btn-detail").each(function() {

                var content = jQuery(this).siblings(".p-image-detail").clone().html();


                jQuery(this).click(function(e) {
                    e.preventDefault();
                    jQuery(".p-image-dialog").find(".ui-dialog-content").html(content).end().dialog("open");
                });

            });

        } // end if non-print		
    }, //end suites


    press: function() {

        jQuery("dd").hide();

        jQuery("#nav-container").equalColumns({
            maxH: jQuery("#content-container").height()
        });

        function resetHeight() {

            jQuery("#nav-container").equalColumns({
                maxH: jQuery(".grid-c").outerHeight({ margin: true })
            })
        }

        jQuery(".column-w dt>a").click(function(e) {
            e.preventDefault();
            jQuery("dt").fadeOut("slow");
            jQuery("h1:not('.title')").fadeOut("slow");
            jQuery(this).parents("dt").next().animate({ opacity: 1.0 }, 1000).fadeIn("slow", resetHeight);

        });


        jQuery(".column-w a.backLink").click(function(e) {
            e.preventDefault();
            jQuery("dd").fadeOut("slow");
            jQuery("dt").animate({ opacity: 1.0 }, 700).fadeIn("slow");
            jQuery("h1:not('.title')").animate({ opacity: 1.0 }, 700).fadeIn("slow", resetHeight);

        });

    } // end press		
}

// open popup
jQuery("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
    jQuery.fn.equalColumns = function(settings) {

        settings = jQuery.extend({
            maxH: 0
        }, settings);

        var columns = jQuery(this);

        jQuery(this).each(function(i) {
            //set max height
            jQuery(this).css("height", settings["maxH"]);
        });
        return this;
    }; //Close function
    
    
        jQuery.fn.zoom = function(settings){
        // VERY IMPORTANT - must pass in the class or element of the parent.  
        // Sensor and zoombox are appended into the parent element
        // positioning also relies on where this parent element is
        // The parent would be the first parent container with positon set to relative
        
        
        
        settings = jQuery.extend({
            triggerOn: "mouseover",
            triggerOff: "mouseout",
            zoomContainer: "zoomBox",
            parent: null
        }, settings);
        
        var imageList = this;

        
		// check if sensor and zoomBox already exists
		if (jQuery(settings["parent"]).find(".sensor").length == 0) {
		    var zoomBox = jQuery('<div class="' + settings["zoomContainer"] + '" style="display:none;background-image:url(http://www.2valor.com/images/load.gif);background-repeat:no-repeat;background-position:center;"><img class="zoomImg" /></div>');
			var sensor = jQuery('<div class="sensor"></div>')
			var preloader = jQuery('<div class="preloader" style="display:none"></div>');
			jQuery(settings["parent"]).append(zoomBox).append(sensor).append(preloader);	
		}
		       
        // get the height and width of zoomBox - includes border		 
        var zoomBoxHeight = jQuery(zoomBox).outerHeight();
        var zoomBoxWidth = jQuery(zoomBox).outerWidth();
        var zoomImg = jQuery(".zoomImg");
       // alert(zoomBoxHeight);

        //preload images        
        var imgArray = [];

        jQuery(window).load(function(){
			var count = 0;
			for (var i = 0; i < jQuery(imageList).length; i++){
				imgArray[i] = new Image();
				jQuery(imgArray[i]).load(function(){
					count++;
					zoomPreloaded = (count==jQuery(imageList).length);

				}).attr('src',jQuery(imageList[i]).attr("zoom"));
			}
		});
		
        jQuery(imageList).each(function(i){
            var jQuerycurrent, zoomImgWidth, zoomImgHeight;
            
        
            jQuery(this).attr("title","");
            jQuery(this).attr("alt","");
            
          	jQuery(this).parents(settings["parent"]).bind("mouseenter",function(e){
		
				// get the current img with the haszoom
				jQuerycurrent = jQuery(this).find(".haszoom:visible");
				zoomBox = jQuery(this).find("."+settings["zoomContainer"]);
				sensor = jQuery(this).find(".sensor");				
				// show preloader
				preloader.show();

                // get the height. width and position of the current element
                var curWidth = jQuerycurrent.attr("width");
                var curHeight = jQuerycurrent.attr("height");                

			    var curPosition = jQuery(settings["parent"]).offset();
                
                // set the min max border for mouse move  events
                var border = {
                    xMin: curPosition["left"] + (zoomBoxWidth / 2),
                    xMax: curPosition["left"] + curWidth - (zoomBoxWidth / 2),
                    yMin: curPosition["top"] + (zoomBoxHeight / 2),
                    yMax: curPosition["top"] + curHeight - (zoomBoxHeight / 2)
                }
                
                // set the height and width of sensor
                // can be commented out and set in css
                sensor.css({
                    "width": curWidth + "px",
                    "height": curHeight + "px"                
                });
                
                //load the larger image
                zoomImg.load(function(){
					
                /*
    zoomImgWidth = jQuery(this).attr("width");
                    zoomImgHeight = jQuery(this).attr("height");

*/
                }).attr("src", jQuerycurrent.attr("zoom"))
				
                  zoomImgWidth = 1020;
                  zoomImgHeight = 1000;
				
				//alert(zoomBoxHeight );
				
 					preloader.fadeOut();
					// show the sensor and zoomBox layer
                    sensor.show();
                    zoomBox.show();
                                
                
	                sensor.bind("mousemove", function(e){
						
						// catch mouse move events on the sensor
	                    var _left = (e.pageX <= border["xMin"]) ? border["xMin"] - curPosition["left"] - (zoomBoxWidth / 2) : (e.pageX >= border["xMax"]) ? border["xMax"] - curPosition["left"] - (zoomBoxWidth / 2) : e.pageX - curPosition["left"] - (zoomBoxWidth / 2);
	                    var _top = (e.pageY <= border["yMin"]) ? border["yMin"] - curPosition["top"] - (zoomBoxHeight / 2) : (e.pageY >= border["yMax"]) ? border["yMax"] - curPosition["top"] - (zoomBoxHeight / 2) : e.pageY - curPosition["top"] - (zoomBoxHeight / 2);
	                    
						// psotion zoomBox
	                    zoomBox.css({
	                        "left": _left,
	                        "top": _top
	                    });
	                    
	                    //position large image inside the zoomBox
						
						//alert(((e.pageX - curPosition["left"]) / curWidth) * -(zoomImgWidth - zoomBoxWidth));
						
						zoomImg.css({
	                        "left":(((e.pageX - curPosition["left"]) / curWidth) * -(zoomImgWidth - zoomBoxWidth)),
	                        "top": ((e.pageY - curPosition["top"]) / curHeight) * -(zoomImgHeight - zoomBoxHeight)
	                    });
	                    
	                });                
							
					//end mouseenter	
				}).bind("mouseleave",function(e){
											
					//  hide everything and unload zoom img
					//  zoomBox.find("img").attr("src", "");
                    zoomBox.hide();
                    sensor.unbind("mousemove").hide();
                 	preloader.hide();
				//end mouseleave
			});
}); 
zoomBox.mouseenter();
zoomImg.css({
    "left": -14,
    "top": -80
});
                
    };

})(jQuery);

