
var CoutureClass = Class.create();

CoutureClass.prototype = {

  initialize: function() { },

layeredPopup: {
		dragger:null,
		hiddenDropDowns:null,
		effects:null,
		isOpen:false,
		popupId:"",
		
		/**
		 * layeredPopups can have different styles.  Each object within styles contains everything required to display differently.
		 * 
		 * @author Byung Kim
		 * @date 1/8/2008
		 */
		styles : {

			/**
			 * commonTemplates contains templates that are common to all styles
			 * 
			 * @author Byung Kim
			 * @date 1/8/2008
			 */
			commonTemplates : {
				iFrameContentTemplate : new Template('<iframe id="#{id}PopupContent" name="#{id}PopupContent" src="#{src}" class="content" style="width:#{width}px;height:#{height}px;" frameborder="0"></iframe>'),
				markupContentTemplate : new Template('<div id="#{id}PopupContent" class="content" style="width:#{width}px;height:#{height}px;">#{content}</div>'),
				closeAnchorTemplate : new Template('<a href="#" onclick="return coutureLib.layeredPopup.closeLayeredPopup();">#{text}</a>'),
				universalCloseButtonTemplate : new Template('<img src="/assets/common/clear.gif" alt="#{altText}" class="universalButtonSprite universalButtonSpriteCloseWindowOn"/>')
			},
			
			/**
			 * brandedPopup is a style type for layeredPopup display
			 * 
			 * @author Byung Kim
			 * @date 1/8/2008
			 */
			brandedPopup : {
				constants : brandConst,
				templates : {
					mainTemplate : new Template(
						'<div id="popupMain" style="width:#{totalWidth}px;">' +
							'<div class="topBorder clearfix">' +
								'<div class="topLeftCorner"></div>' +
								'<div id="layeredPopup#{topId}FrameTop" class="topMiddle#{topClass}" style="width:#{topWidth}px;">#{title}</div>' +
								'<div class="topCloseButton"><a href="#" onclick="return coutureLib.layeredPopup.closeLayeredPopup();">&#160;</a></div>' +
								'<div class="topRightCorner"></div>' +
							'</div>' +
							'<div class="mainContent clearfix">' +
								'<div class="leftBar" style="height:#{borderHeight}px;"></div>' +
								'#{content}' +
								'<div class="rightBar" style="height:#{borderHeight}px;"></div>' +
							'</div>' +
							'<div class="bottom clearfix ">' +
								'<div class="bottomLeftCorner"></div>' +
								'<div class="bottomMiddle" style="width:#{innerContentWidth}px;">#{bottonCloseButton}</div>' +
								'<div class="bottomRightCorner"></div>' +
							'</div>' +
						'</div>'
					)
				},
				
				/**
				 * getMarkup returns the markup for brandedPopup styled popups
				 * 
				 * @author Byung Kim
				 * @date 1/8/2008
				 */
				getMarkup:function(useIFrame, width, height, title, strContent, id) {
					var constants = this.constants;
					var templates = this.templates;
					var commonTemplates = coutureLib.layeredPopup.styles.commonTemplates;
					var topId = ""
					var topClass = "";
					var content = "";
					var bottomCloseButton = (brandConst.LAYERED_POPUP_CLOSE_COPY != "" ? commonTemplates.closeAnchorTemplate.evaluate({copy:brandConst.LAYERED_POPUP_CLOSE_COPY}) : "");
					var topTitle = brandConst.LAYERED_POPUP_BRAND_NAME + (title && title != "" ? " - " + title : "");
					if (!topTitle || topTitle == "") topTitle = "&#160;";

					var innerContentWidth = width - constants.LAYERED_POPUP_SIDE_IMAGE_WIDTH;
					var borderHeight = height + constants.LAYERED_POPUP_CONTENT_COMBINED_BORDER_HEIGHT;
		
					if (useIFrame) {
						topId = "NoDrag";
						content = commonTemplates.iFrameContentTemplate.evaluate({
							id:id,
							src:gidLib.addCurrentDomain(strContent),
							width:innerContentWidth,
							height:height
						});
					} else {
						topClass = " cursorMove";
						content = commonTemplates.markupContentTemplate.evaluate({
							id:id,
							content:strContent,
							width:innerContentWidth,
							height:height
						});
					}
		
					return templates.mainTemplate.evaluate({
						topId:topId,
						topClass:topClass,
						totalWidth:width+constants.LAYERED_POPUP_COMBINED_BORDER_WIDTH+constants.LAYERED_POPUP_CONTENT_COMBINED_BORDER_WIDTH+constants.LAYERED_POPUP_SHADOW_WIDTH,
						topWidth:width-constants.LAYERED_POPUP_MAIN_WIDTH_OFFSET,
						innerContentWidth:innerContentWidth,
						borderHeight:borderHeight,
						title:topTitle,
						content:content,
						bottomCloseButton:bottomCloseButton
					});
				}
			},
			
			/**
			 * universalPopup is a style type for layeredPopup display
			 * 
			 * @author Byung Kim
			 * @date 1/8/2008
			 */
			universalPopup : {
				constants : {
					LAYERED_POPUP_COMBINED_BORDER_WIDTH: 21, // left and right border combined widths
					LAYERED_POPUP_COMBINED_BORDER_HEIGHT: 59, // top and bottom border combined heights 
					LAYERED_POPUP_MAIN_WIDTH_OFFSET:19 // close window button width
				},
				templates : {
					mainTemplate : new Template(
						'<div id="popupMain" class="universalLayeredPopup" style="width:#{popupWidth}px;">' +
							'<div class="topBorder clearfix">' +
								'<div class="pop-sprites topLeftCorner"></div>' +
								'<div id="layeredPopup#{topId}FrameTop" class=" pop-sprites topMiddle#{topClass}" style="width:#{topWidth}px;">#{title}</div>' +
								'<div class="topCloseButton">#{topCloseButton}</div>' +
								'<div class="pop-sprites topRightCorner"></div>' +
							'</div>' +
							'<div class="mainContent clearfix">' +
								'<div class="leftBar" style="height:#{borderHeight}px;"></div>' +
								'#{content}' +
								'<div class="rightBar" style="height:#{borderHeight}px;"></div>' +
							'</div>' +
							'<div class="bottom clearfix ">' +
								'<div class="pop-sprites bottomLeftCorner"></div>' +
								'<div class="pop-sprites bottomMiddle" style="width:#{innerContentWidth}px;"></div>' +
								'<div class="pop-sprites bottomRightCorner"></div>' +
							'</div>' +
						'</div>'
					)
				},

				/**
				 * getMarkup returns the markup for universalPopup styled popups
				 * 
				 * @author Byung Kim
				 * @date 1/8/2008
				 */
				getMarkup:function(useIFrame, width, height, title, strContent, id) {
					var constants = this.constants;
					var templates = this.templates;
					var commonTemplates = coutureLib.layeredPopup.styles.commonTemplates;
					var topId = ""
					var topClass = "";
					var content = "";
					var topCloseButton = commonTemplates.closeAnchorTemplate.evaluate({text:commonTemplates.universalCloseButtonTemplate.evaluate({path:brandConst.UNIVERSAL_BUTTON_CONTENT_PATH,altText:resourceBundleValues.infoPopupsAltTextClose })});
					var topTitle = title;
					if (!topTitle || topTitle == "") topTitle = "&#160;";
		
					if (useIFrame) {
						topId = "NoDrag";
						content = commonTemplates.iFrameContentTemplate.evaluate({
							id:id,
							src:gidLib.addCurrentDomain(strContent),
							width:width,
							height:height
						});
					} else {
						topClass = " cursorMove";
						content = commonTemplates.markupContentTemplate.evaluate({
							id:id,
							content:strContent,
							width:width,
							height:height
						});
					}
		
					return templates.mainTemplate.evaluate({
						popupWidth:width + constants.LAYERED_POPUP_COMBINED_BORDER_WIDTH,
						topId:topId,
						topClass:topClass,
						topWidth:width-constants.LAYERED_POPUP_MAIN_WIDTH_OFFSET,
						innerContentWidth:width,
						borderHeight:height,
						title:topTitle,
						content:content,
						topCloseButton:topCloseButton
					});
				}
			},
			
			/**
			 * universalPanel is a style type for layeredPopup display
			 * 
			 * @author Byung Kim
			 * @date 1/8/2008
			 */
			universalPanel : {
				constants : {
					PANEL_COMBINED_BORDER_WIDTH: 14, // left and right border combined widths
					PANEL_MAIN_WIDTH_OFFSET:27, // to calculate the main width from the content width
					PANEL_TITLE_WIDTH_OFFSET:50 // to calculate the title width
				},
				templates : {
					mainTemplate : new Template(
						'<div id="popupMain" class="universalPanel" style="width:#{mainWidth}px;">' +
							'<div class="row top clearfix" style="width:#{topBottomWidth}px;">' +
								'<div class="pop-sprites topLeft">&#160;</div>' +
								'<div class="pop-sprites topCenter" style="width:#{topBottomCenterWidth}px;">&#160;</div>' +
								'<div class="pop-sprites topRight">&#160;</div>' +
							'</div>' +
							'<div class="row">' +
								'<div class="leftCenter clearfix" style="width:#{leftCenterWidth}px;">' +
									'#{calloutLeft}' +
									'<div class="rightCenter" style="width:#{rightCenterWidth}px;#{offset}">' +
										'<div class="close" style="width:#{closeWidth}px;">' +
											'#{topBar}' +
											'<div class="panelContent" style="width:#{contentWidth}px;height:#{contentHeight}px;">#{content}</div>' +
										'</div>' +
									'</div>' +
								'</div>' +
							'</div>' +
							'<div class="row bottom clearfix" style="width:#{topBottomWidth}px;">' +
								'<div class="pop-sprites bottomLeft">&#160;</div>' +
								'<div class="pop-sprites bottomCenter" style="width:#{topBottomCenterWidth}px;">&#160;</div>' +
								'<div class="pop-sprites bottomRight">&#160;</div>' +
							'</div>' +
							'#{calloutBottom}' +
						'</div>'
					),
					
					panelCalloutBottomTemplate : new Template('<div class="pop-sprites row callout" style="#{offset}">&#160;</div>'),
					panelCalloutLeftTemplate : new Template('<div id="universalPanelLeftCallout" class="pop-sprites calloutLeft" style="#{offset}">&#160;</div>'),
					panelTitleTemplate : new Template('<div class="panelTitle" style="width:#{width}px;">#{title}</div>'),
					panelCloseButtonTemplate : new Template('<div class="closeButton">#{topCloseButton}</div>'),
					panelTopBarTemplate : new Template('<div class="clearfix">#{titleTemplate}#{buttonTemplate}</div>')
				},

				/**
				 * getMarkup returns the markup for universalPanel styled popups
				 * 
				 * @author Byung Kim
				 * @date 1/8/2008
				 */
				getMarkup:function(useIFrame, width, height, title, strContent, id, style) {
					var constants = this.constants;
					var templates = this.templates;
					var commonTemplates = coutureLib.layeredPopup.styles.commonTemplates;
					var hasCloseButton = true;
					var callout = null;
					var calloutOffset = null;
					var content = "";
					var mainWidth = width+constants.PANEL_MAIN_WIDTH_OFFSET;
					if (style && style.hasCloseButton != undefined) hasCloseButton = style.hasCloseButton;
					if (style && style.callout) callout = style.callout;
					if (style && style.calloutOffset) calloutOffset = style.calloutOffset;
					var topTitle = "";
					var topCloseButton = "";
					var calloutLeft = "";
					var calloutBottom = "";
					var topBar = "";
					
					if (title) {
						topTitle = templates.panelTitleTemplate.evaluate({
							title:title,
							width:mainWidth-constants.PANEL_TITLE_WIDTH_OFFSET
						})
					}

					if (hasCloseButton) {
						topCloseButton = templates.panelCloseButtonTemplate.evaluate({
							topCloseButton:commonTemplates.closeAnchorTemplate.evaluate({
								text:commonTemplates.universalCloseButtonTemplate.evaluate({
									path:brandConst.UNIVERSAL_BUTTON_CONTENT_PATH, altText:resourceBundleValues.infoPopupsAltTextClose
								})
							})
						})
					}
					
					if (title || hasCloseButton) {
						topBar = templates.panelTopBarTemplate.evaluate({
							titleTemplate:topTitle,
							buttonTemplate:topCloseButton
						});
					}
					
					if (callout == "left") {
						calloutOffset = "top:"+calloutOffset+"px;"
						calloutLeft = templates.panelCalloutLeftTemplate.evaluate({offset:calloutOffset});
					} else if (callout == "bottom") {
						calloutOffset = "left:"+calloutOffset+"px;"
						calloutBottom = templates.panelCalloutBottomTemplate.evaluate({offset:calloutOffset});
					}
					
					if (useIFrame) {
						topId = "NoDrag";
						content = commonTemplates.iFrameContentTemplate.evaluate({
							id:id,
							src:gidLib.addCurrentDomain(strContent),
							width:width,
							height:height
						});
					} else {
						topClass = " cursorMove";
						content = commonTemplates.markupContentTemplate.evaluate({

							id:id,
							content:strContent,
							width:width,
							height:height
						});
					}
		
					return templates.mainTemplate.evaluate({
						mainWidth:mainWidth,
						topBottomWidth:mainWidth,
						topBottomCenterWidth:(mainWidth-constants.PANEL_COMBINED_BORDER_WIDTH),
						leftCenterWidth:mainWidth,
						rightCenterWidth:mainWidth,
						closeWidth:width,
						topBar:topBar,
						contentWidth:width,
						contentHeight:height,
						content:content,
						calloutLeft:calloutLeft,
						calloutBottom:calloutBottom
					});
				}
			}
		},

		/**
		 * openLayeredPopup opens a DHTML layer that looks like a popup.
		 * @param {object} argsGraph The JSON object with values for the popup
		 * 		str : The content of the layered Popup.  This can be a string of HTML, a URL to open, or a form to submit 
		 * 		id : The id for the layer parent element
		 * 		width : The width of the popup
		 * 		height : The height of the popup
		 * 		title : The title to display in the fake titlebar
		 * 		left : The x coordinate to position the popup
		 * 		top : The y coordinate to position the popup
		 * 		calleeElement : The calling element for the event
		 *		isDraggable : Whether the popover is draggable by clicking on it 
		 * 		style : A JSON object for the look and feel of the popup.
		 * 			name : which template to use (optional, default is the brandedPopup template)
		 * 			hasCloseButton : whether to display the close button for the universalPanel (optional, default is true)
		 * 			callout : used for displaying a callout for the universalPanel. values are 'left' or 'bottom' (optional, default is no callout)
		 * 			calloutOffset : used to offset the callout on the left or top depending on which is used.
		 *			isDraggable : Whether the poopup is draggagle (defaults to true)
		 * 		interstitial : JSON object -- when it exists, display as an interstitial (rest of the page greys out)
		 * 			color: hex value color of the interstitial (e.g. "#fff")
		 * 			opacity: opacity of the interstitial (e.g. "0.7" is 70%)
		 * 			buzz: whether to buzz the popup if a user clicks on the interstitial (e.g. true or false)
		 * 		effects : JSON object describing how to show and hide the layeredPopup.  Default is CSS visibility visible/hidden
		 * 			show : JSON object for showing the layered popup
		 * 				method : Scriptaculous Effect method
		 * 				args : JSON object of arguments for the method
		 * 			hide : JSON object for hiding the layered popup
		 * 				method : Scriptaculous Effect method
		 * 				args : JSON object of arguments for the method
		 * 			
		 * 
		 * Modified 12/19/2007 Byung Kim - converted method arguments to JSON with legacy API support
		 * Modified 1/1/2008 Byung Kim - reorganized to accept different styles
		 * Modified 1/8/2008 Byung Kim - updated FORM submit implementation
		 * Modified 1/31/2008 Byung Kim - added interstitial option
		 * Modified 7/25/2008 Byung Kim - added effects option for showing / hiding layered popup
		 * Modified 7/31/2008 Byung Kim - added callee element arg for returning focus to the callee once the popup closes
		 * 
		 * TODO: refactor implementation to use only JSON
		 * TODO: implement a dynamic root element for the popups 
		 * 
		 * @author Byung Kim
		 * @date 10/24/2007
		 */
		openLayeredPopup:function(argsGraph) {
			var args = arguments;
			if (args.length > 1) {
				// FOR LEGACY SUPPORT ONLY.  New implementations should use JSON object graph for arguments
				var str = args[0];
				var id = args[1];
				var width = args[2];
				var height = args[3];
				var title = args[4];
				var left = args[5];
				var top = args[6];
			} else {
				var str = argsGraph.str;
				var id = argsGraph.id;
				var width = argsGraph.width;
				var height = argsGraph.height;
				var title = argsGraph.title;
				var left = argsGraph.left;
				var top = argsGraph.top;
				var isDraggable = argsGraph.isDraggable;
				var style = argsGraph.style;
				var interstitial = argsGraph.interstitial;
				this.effects = argsGraph.effects;
				this.calleeElement = argsGraph.calleeElement;
			}
			var popup = $("popupContent");
			
			var layerStyle = this.styles[(style && style.name ? style.name : "brandedPopup")]; 
			var constants = layerStyle.constants;
			var useIFrame = false;
			var isForm = false;
			var strContent = "";
			var strIgnoredFormTypes = "submit,button,image,file,reset";
			this.popupId = id;

			popup.setStyle({visibility:"hidden",display:"block"});

			if (str.match(/^(\/|http|about)/)) {
				useIFrame = true;
				strContent = str;
				var cid = str.substr(str.indexOf('?')+1, str.length);
			} else {
				var targetElement = $(str);
				if (targetElement) {
					if (targetElement.tagName && targetElement.tagName.toLowerCase() == 'form') {
						useIFrame = true;
						isForm = true;
						strContent = "/gid/html/en/blank.html";
						targetElement.target = id + "PopupContent";
					} else {
						// Copy the innerHTML
						strContent = targetElement.innerHTML;
					}
				} else {
					// Copy the string literally
					strContent = str;
				}
			}
			popup.update(layerStyle.getMarkup(useIFrame,width,height,title,strContent,id,style));
			if (!useIFrame && isDraggable) {
				gidLib.setButtonEvents("popupContent");
				this.dragger = new Draggable('popupContent',{handle:'layeredPopupFrameTop'});
			}
			this.hiddenDropDowns = gidLib.hideDropDownsUnderElement(popup);
			if (interstitial) this.openInterstitialDisplay(interstitial);
			this.setPosition(popup,left,top);
			this.launchLayeredPopup(id);
			if (isForm) targetElement.submit();
			return false;
		},
		
		/**
		 * setPosition sets the position of the layeredPopup
		 * 
		 * Modified 7/23/2008 - Byung Kim : removed scrollTop, scrollLeft calculation on x,y coordinates.  values passed to openlayeredpopup should account for the scroll values
		 * 
		 * @author Byung Kim
		 * @date 1/8/2008
		 */
		setPosition : function(popup,x,y) {
			var popupX = parseInt(x);
			var popupY = parseInt(y);
			var dimensions = popup.getDimensions();
			if (isNaN(popupX) || isNaN(popupY)) {
				var clientWidth = (document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth);
				var clientHeight = (document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight);
				var scrollLeft = (document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
				var scrollTop = (document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
				if (clientBrowser.isSafari) {
					/*
					TD 14933: Safari does not seem to properly support the document.documentElement.clientHeight -
					reporting a constant value of 1330.
					*/
					var clientHeight = window.innerHeight;
				}
				popupX = Math.max(0,clientWidth/2 - dimensions.width/2)+scrollLeft;
				popupY = Math.max(0,clientHeight/2 - dimensions.height/2)+scrollTop;
				// alert("clientBrowser.isSafari = " + clientBrowser.isSafari + "\rwindow.innerHeight = " + window.innerHeight + "\rdocument.documentElement.clientHeight = " + document.documentElement.clientHeight + "\r\rclientHeight = " + clientHeight + "\rclientWidth = " + clientWidth + "\r\rpopupX = " + popupX + "\rpopupY = " + popupY);
			}
			gidLib.setObjPosition(popup,popupX,popupY);
		},
		
		/**
		 * launchLayeredPopup reveals the layered popup
		 * 
		 * @author Byung Kim
		 * @date 7/25/2008
		 */
		launchLayeredPopup : function(id) {
			var effects = this.effects;
			var popup = $("popupContent");
			
			var afterFinish = function(id) {
				setTimeout("gidLib.setFocus($('popupContent'))",100);
				this.isOpen = true;
			};
			
			if (effects && effects.show && effects.show.method) {
				popup.setStyle({display:"none",visibility:"visible"});
				var method = effects.show.method;
				var args = effects.show.args;
				var aF = {afterFinish:afterFinish.bind(this,id)};
				if (args) {
					Object.extend(args,aF);
					method(popup,args);
				} else {
					method(popup,aF);
				}
			} else {
				popup.setStyle({visibility:"visible",display:"block"});
				afterFinish(id);
			}
		},

		/**
		 * closeLayeredPopup closes the layered popup
		 * 
		 * Modified 7/25/2008 Byung Kim - added effect
		 * Modified 7/31/2008 Byung Kim - added returning focus to the callee element
		 * 
		 * @author Byung Kim
		 * @date 10/24/2007
		 */
		closeLayeredPopup:function() {
			var popup = $("popupContent");
			this.closeInterstitialDisplay();
			$('popupContent').removeClassName('couturePopup');
			var afterFinish = function() {
				//while(popup.hasChildNodes()) {
					//popup.removeChild(popup.firstChild);
				//}
				gidLib.showDropDowns(this.hiddenDropDowns);
				this.hiddenDropDowns = null;
				if (this.dragger) this.dragger.destroy();
				if (this.calleeElement) {
					gidLib.setFocus(this.calleeElement);
				}
				this.isOpen = false;
				this.popupId = "";
			};

			var effects = this.effects;
			if (effects && effects.hide && effects.hide.method) {
				var method = effects.hide.method;
				var args = effects.hide.args;
				var aF = {afterFinish:afterFinish.bind(this)};
				if (args) {
					Object.extend(args,aF);
					method(popup,args);
				} else {
					method(popup,aF);
				}
			} else {
				popup.setStyle({visibility:"hidden",display:"block"});
				afterFinish();
			}
			return false;
		},
		
		/**
		 * openInterstitialDisplay adds an interstitial layer behind the layeredPopup to grey out the page. 
		 * 
		 * @author Byung Kim
		 * @date 1/30/2008
		 */
		openInterstitialDisplay:function(args) {
			var color = (args.color ? args.color : "#fff");
			var opacity = (args.opacity ? args.opacity : "0.65");
			this.hasBuzz = (args.buzz != undefined ? args.buzz : true);
			var id = "layeredPopupInterstitial";
			var interstitial = $(id);
			if (!interstitial) {
				var interstitial = $(document.createElement("div"));
				interstitial.id = id;
				document.body.appendChild(interstitial);
				Event.observe(interstitial,"click",this.interstitialBuzzEffect.bind(this));
			}
			var clientWidth = (document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth);
			var clientHeight = (document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight);
			var scrollLeft = (document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
			var scrollTop = (document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
			var docW = clientWidth + scrollLeft;
			var docH = (clientBrowser.isIE ? document.body.offsetHeight : (document.documentElement ? document.documentElement.offsetHeight : document.body.offsetHeight)); 
			if (clientHeight > docH) docH = clientHeight;
			interstitial.setStyle({
				position:"absolute",
				top:"0px",
				left:"0px",
				width:docW+"px",
				height:docH+"px",
				display:"block",
				background:color,
				zIndex:"98",
				opacity:opacity,
				filter:"alpha(opacity=" + (opacity*100) + ")" 
			});
		},
		
		/**
		 * closeInterstitialDisplay hides the interstitial layer
		 * 
		 * @author Byung Kim
		 * @date 1/30/2008
		 */
		closeInterstitialDisplay:function() {
			var interstitial = $("layeredPopupInterstitial");
			if (interstitial) {
				interstitial.setStyle({display:"none"});
				Event.stopObserving(interstitial,"click",this.interstitialBuzzEffect.bind(this));
			}
		},
		
		/**
		 * interstitialBuzzEffect does the effect for the popup
		 * 
		 * @author Byung Kim
		 * @date 1/31/2008
		 */
		interstitialBuzzEffect:function(hasBuzz) {
			if (this.hasBuzz) Effect.Shake("popupContent");
		}
  }
}
	  
var coutureLib = new CoutureClass();

// QUICK LOOK OVERRIDES

var quickLook = {
    productFunctionPath: '/gid/js/common/layouts/en/productFunctions.js',
    QuickLookBtnAdj: {'1':0,'2':0,'3':0,'4':0,'10':0,'7':0,'8':0,'9':0,'20':0,'21':0},
    QuickLookLauncherMap : {
	   objQuickLook : 'quickLookWindow',
	   objQuickLookLauncher : "quickLookLauncher"},
	initializeQuickLook : function() {
		gidLib.loadDomObjMap(this, this.QuickLookLauncherMap);
		if (window["objSBS"] && objSBS.isFilterEngaged) this.isFromSBS = true;
        this.isLoaded = true;
        this.launcherHalfWidth = this.objQuickLookLauncher.width / 2;
        this.launcherHalfHeight = this.objQuickLookLauncher.height / 2;
	},
    setUserSizeSelections : function(strSizeCategoryDimension,strSizeSelections) {
		if (!this.objUserSizeSelections) this.objUserSizeSelections = {};
		var objUserSelections = this.objUserSizeSelections;
		if (!objUserSelections.arraySizeCategories) objUserSelections.arraySizeCategories = [];
		with(objUserSelections) {
			var arraySizeSelections = strSizeSelections.split("||");
			var arraySizeValues = arraySizeSelections[0].split("^,^");
			arraySizeCategories[strSizeCategoryDimension] = {strSizeDimensionValueId: arraySizeValues[0], strSizeDimensionAlphaSize: arraySizeValues[1]};
		}
	},
    loadQuickLookCallback: function(obj,periodicalExecuterRef) {
        if(!quickLook.initializeData) return false;
        objGIDPageViewAdapter.initializeGidProducts();
        periodicalExecuterRef.stop();
        quickLook.isLoaded = true;
        if(quickLook.relaunchQuickLook) { quickLook.relaunchQuickLook = false; quickLook.launchQuickLook(); }
        return true;
    },
    isQuickLookOpen : false,
    initializing: false,
    loadQuickLookModule: function(brandCode) {
        if(quickLook.initializing) return;
        quickLook.initializing = true;
        gidLib.loadScript({
            callerObject:this, src:this.productFunctionPath,
            timeout:{
                handler:function() {return true; },
                args:null,
                timeDelay:2
            },
            callback:{
                handler:this.loadQuickLookCallback,
                args:this,
                timeDelay:1
            }
        });
    },
openQuickLookLauncher : function(strProductId,strDefaultStyleColor,strCategoryId,strVariantId,targetImg, isCrossSell, brandCode, customProperties, fromIso) {
		if (this.isLoaded) {
			var blnOpen = false;
			if (this.isQuickLookOpen) {
				if (this.objP.strProductId != strProductId) blnOpen = true;
			} else {
				blnOpen = true;
			}
            brandCode = brandCode||gidBrandSiteConstruct.currentBrandCode;

            var constants = customProperties || brandProperties;

            if (blnOpen) {
				if( fromIso ) {
				  // JS browser check
				  var browserName=navigator.appName; 
					if (browserName=="Netscape") { 
					 var targetFrame = $('coutureLayerPopupContent').contentDocument;
					}
					else { 
					 if (browserName=="Microsoft Internet Explorer") {
					  var targetFrame = window.frames['coutureLayerPopupContent'].document;
					 }
					 else {
					  var targetFrame = $('coutureLayerPopupContent').contentDocument;
					 }
					}
 
					//var targetFrame = $('coutureLayerPopupContent').contentDocument;
					//var targetFrame = window.frames['coutureLayerPopupContent'].document;
					var targetObj = targetFrame.getElementById(targetImg);
				}
				else {
					var targetObj = $(targetImg);
				}
                if(!targetObj) return;
                var cumulativeOffset = Position.cumulativeOffset(targetObj);
                var realOffset =  Position.realOffset(targetObj);
				
				var isoOffsetL = $('popupContent').getStyle('left');
				isoOffsetL = parseInt( isoOffsetL.replace('px','') );
				var isoOffsetT = $('popupContent').getStyle('top');
				isoOffsetT = parseInt( isoOffsetT.replace('px','') );
				
                var scrollTop = (document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
                var scrollLeft = (document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
				if( fromIso ) {
	                var position = [cumulativeOffset[0]-(realOffset[0]-scrollLeft)+isoOffsetL,cumulativeOffset[1]-(realOffset[1]-scrollTop)+isoOffsetT];
				}
				else {
					var position = [cumulativeOffset[0]-(realOffset[0]-scrollLeft),cumulativeOffset[1]-(realOffset[1]-scrollTop)];
				}
                /* targetImgCount is required to test strDefaultStyleColor the imageLoader.categoryProductsMap
                 * is constructed differently based on whether the item is STYLECOLOR or not in the JSP */
                var targetImgCount = targetImg.split("_");
				var isStyleColor = ( targetImgCount.length == 3 );
                var imgLoaderObjRef = strCategoryId + "_" + (isStyleColor ? strProductId : strDefaultStyleColor) + "_" + strDefaultStyleColor;
                if(!isCrossSell  && imageLoader.categoryProductsMap[imgLoaderObjRef]){
	                var selectedStyleID = imageLoader.categoryProductsMap[imgLoaderObjRef].selectedScid;
	                strDefaultStyleColor = selectedStyleID;
                }
                var target = this.objQuickLookTarget = {
					strProductId : strProductId,
					strDefaultStyleColor : strDefaultStyleColor,
					strCategoryId : strCategoryId,
					strVariantId : strVariantId,
					position : position,
					isCrossSell: isCrossSell,
					obj : targetObj,
                    brandCode: brandCode
                };

                var targetWidth = target.obj.width;
                var targetHeight = target.obj.height;
                this.quickLookLauncherBoundBox = {top:target.position[1],left:target.position[0],right:target.position[0] + targetWidth, btm:target.position[1] + targetHeight};
                this.objQuickLookLauncher.setStyle({left: (target.position[0] + (targetWidth * 0.5) - this.launcherHalfWidth) + 'px',
					top: (target.position[1] + (targetHeight * 0.8 - this.launcherHalfHeight)) + 'px', visibility: 'visible'});

                if(!quickLook.initializeData) {
                    this.loadQuickLookModule(brandCode);
                }
            }
		}
	},
    logTeaLeafEvent: function(itemSource, eventType) {
        var tlevt = new TeaLeaf.Event("GUI", eventType);

        var tlAddNameValueArray = ["Name", itemSource.name,
                                     "Id", itemSource.id,
                                     "ElementType", itemSource.type,
                                     "TagName", itemSource.tagName,
                                     "XPath", TeaLeaf.Client.tlGetXPathFromNode(itemSource)];
        tlevt.tlAddData(tlAddNameValueArray);
        tlevt.tlSend();
    },

	closeQuickLookLauncher : function(e) {
		if(e && this.quickLookLauncherBoundBox && !gidLib.isMouseOut(Event.pointerX(e), Event.pointerY(e), this.quickLookLauncherBoundBox)) {
			return;
		}
		if(this.isLoaded && this.objQuickLookTarget) {
			this.objQuickLookLauncher.style.visibility = 'hidden';
			this.objQuickLookLauncher.src = '/gid/assets/common/quicklook/'+brandConst.BRAND_LOCALE+'/button_quicklook_launcher_on.gif';
			this.objQuickLookTarget.strProductId = 0;
		}
	},
	
	
	// FUNCTIONS TO OVERRIDE
	launchQuickLook : function( plStyleID ) {
		// this.objQuickLookTarget = QL target object
		// this.objQuickLookTarget.obj = img of QL target

		var plStyleIDStr = plStyleID.toString();

		// find QL target aka this.objQuickLookTarget.obj
		var objQLTargetImg = $('coutureLayerPopupContent').contentDocument.getElementById('coutureOutfit'+plStyleID);
		var objQLTargetBrand = "4";
	
        this.logTeaLeafEvent(objQLTargetImg,'mouseover');
        this.logTeaLeafEvent(this.objQuickLookLauncher,'click');
        TeaLeaf.Client.tlProcessNode('quickLookWindow');

		var strProductId = plStyleIDStr.substr(0,6);
		var strStyleColorId = plStyleIDStr;
		
        //if (strTarget && strTarget.getDimensions) {
			//this.objQuickLookTarget.position = returnObjPosition(strTarget);
			//this.objQuickLookTarget.obj = $(strTarget);
        //}

		if (!objInlineBag.isOpen) {
			if (!this.isQuickLookOpen || brandConst.QUICKLOOK_ALLOW_MULTIPLE) {
                this.brandCode = objQLTargetBrand;
                this.brandSite = gidBrandSiteConstruct.gidBrandSites[this.brandCode];
                this.resources.BTN_PATH = this.brandSite.unsecureUrl + brandConst.resources.BTN_PATH;
                this.resources.ASSET_PATH = this.brandSite.unsecureUrl + brandConst.resources.ASSET_PATH;
                var product = $('coutureLayerPopupContent').contentDocument.objGIDPageViewAdapter.objGIDProducts.arrayProducts[strProductId];
				if (product) {
					this.closeQuickLookLauncher();
					this.dataLoaderAction = "auto";
					this.isQuickLookOpen = true;
					this.initializeData(strProductId);
                    this.setupQuickLookBoundBox();
					loadQuickLookAnimate();
					if(isCrossSell) { this.goCrossSell(strProductId);}
					if(!(window['reportingService']||{}).isActive) {
						this.initializeOmni();
					}
					else {
						this.setReportingService();
					}
					this.reopenQuickLook = false;
				} else {
					if (!this.isFromSBS) {
						var variantId = this.strDefaultStyleVariant;
						if (this.objQuickLookTarget.strVariantId && this.objQuickLookTarget.strVariantId != "-1") {
							variantId = this.objQuickLookTarget.strVariantId;
						}
						this.loadProductData(strProductId,"auto",variantId,strStyleColorId, this.brandCode);
					} else {
						this.loadProductData(strProductId,"auto",undefined,strStyleColorId, this.brandCode);
					}
				}
			} else {
				this.reopenQuickLook = true;
				this.closeQuickLook();
			}
		} else {
			setTimeout('quickLook.launchQuickLook()', 250);
		}
	}
};


