
jQuery.fn.swatchPopup=function(parentDivIdentifier){var popUp=function(){};popUp.swatchImageData={},popUp.ajaxDataCache={},popUp.initialize=function(parentDivIdentifier){this.setClueTipDefaults();this.setMouseOverSwatchBinding(parentDivIdentifier);},popUp.setClueTipDefaults=function(){jQuery.fn.cluetip.defaults.ajaxCache=true;jQuery.fn.cluetip.defaults.waitImage=true;jQuery.fn.cluetip.defaults.cluetipClass="rounded";jQuery.fn.cluetip.defaults.dropShadow=false;jQuery.fn.cluetip.defaults.width=158;jQuery.fn.cluetip.defaults.positionBy="fixed";jQuery.fn.cluetip.defaults.sticky=true;jQuery.fn.cluetip.defaults.mouseOutClose=true;jQuery.fn.cluetip.defaults.activation="hover";jQuery.fn.cluetip.defaults.local=true;jQuery.fn.cluetip.defaults.hideLocal=false;jQuery.fn.cluetip.defaults.leftOffset=undefined;jQuery.fn.cluetip.defaults.topOffset=undefined;},popUp.setOffsets=function(element,id){jQuery.fn.cluetip.defaults.leftOffset=-jQuery.fn.cluetip.defaults.width-4;var positionProductImage=element.children("a.productImage").position();var positionColorElement=jQuery(id).position();jQuery.fn.cluetip.defaults.topOffset=-(-positionProductImage.top+positionColorElement.top-3);if(jQuery.browser.msie){jQuery.fn.cluetip.defaults.topOffset=-(-positionProductImage.top+positionColorElement.top-4);}},popUp.displaySorryMsg=function(pAsin){popUp.ajaxDataCache[pAsin]=undefined;jQuery("#loadingImage").remove();var sorryMsgDiv=jQuery("<div/>").attr("class","popOverSorryMsg");sorryMsgDiv.attr("innerHTML","Sorry, We're unable to process your request. Please try later.");sorryMsgDiv.appendTo(jQuery("#cluetip-inner"));},popUp.setPopupOmnitureData=function(asin){var productTitleLink=jQuery("#cluetip-inner .productTitle a:first").attr("href")+"?intid=ref_dp_vPopover_title";jQuery("#cluetip-inner .productTitle a:first").attr("href",productTitleLink);var productImageLink=jQuery("#cluetip-inner .productImage").attr("href")+"?intid=ref_dp_vPopover_img";jQuery("#cluetip-inner .productImage").attr("href",productImageLink);try{if((s.pageName).indexOf("VariationPopover")==-1)
s.pageName="VariationPopover:"+s.pageName;s.products=";"+asin;s.events="event9";var s_code=s.t();if(s_code)
document.write(s_code);}catch(e){}},popUp.setMouseOverSwatchBinding=function(parentDivClass){jQuery(parentDivClass).each(function(){var pAsin=jQuery(this).attr("id").toString().substring(5);var divId="#DivC_"+pAsin;popUp.setOffsets(jQuery(this),divId);jQuery(divId).attr("rel","#pImg_"+pAsin).cluetip({onShow:function(ct,c){if(!popUp.ajaxDataCache[pAsin]){var numColorsOrig=jQuery("#cluetip-inner #pImg_"+pAsin+" .numberOfColorsMessage");if(numColorsOrig){var colorsAvailable=jQuery("<div/>").attr("class","popOverNumberOfColorsMessage");var colorsImg=jQuery("<img/>").attr("class","colorsMessageImg");colorsImg.attr("src","/images/icons/roundedColorsMsg.jpg");colorsImg.appendTo(colorsAvailable);var colorsMsg=jQuery("<div/>").attr("class","numberOfColorsMessageText");;colorsMsg.attr("innerHTML",numColorsOrig.attr("innerHTML"));colorsMsg.appendTo(colorsAvailable);numColorsOrig.hide();colorsAvailable.appendTo(jQuery("#cluetip-inner .floatedProduct"));}
var loadDiv=jQuery("<div/>").attr("id","loadingImage");var loadImage=jQuery("<img/>").attr("class","spinningImage");loadImage.attr("src","http://g-ecx.images-amazon.com/images/G/01/Lacoste/en_US/core/icons/graphic_spinner.gif");loadImage.appendTo(loadDiv);var loadMsg=jQuery("<div/>").attr("class","loadingMsg");loadMsg.attr("innerHTML","Loading Colors");loadMsg.appendTo(loadDiv);loadDiv.appendTo(jQuery("#cluetip-inner"));jQuery.ajax({url:"/variationrequest",type:"GET",ajaxCache:"true",data:"ASIN="+pAsin,dataType:"json",beforeSend:function(){popUp.ajaxDataCache[pAsin]=-1;},error:function(){popUp.displaySorryMsg(pAsin);},success:function(data){if(data==undefined||data.colorData==undefined){popUp.displaySorryMsg(pAsin);return;}
if(pAsin==jQuery("#cluetip-inner .floatedProduct").attr("id").toString().substring(5)&&popUp.ajaxDataCache[pAsin]==-1){var swatchImagesDiv=jQuery("<div/>").attr("class","popOverSwatchImages");var swatchCount=0,swatchRow=0,swatchImagesToDisplay=0,swatchesPerRow=5,noSwatchImages=0;jQuery.each(data.colorData,function(){swatchImagesToDisplay++});if(swatchImagesToDisplay==0){popUp.displaySorryMsg(pAsin);return;}
var numRows=Math.ceil(swatchImagesToDisplay/swatchesPerRow);if(numRows<1)
numRows=1;var swatchRowArray=new Array(numRows);var dpLink=jQuery("#cluetip-inner .productTitle a:first").attr("href");jQuery.each(data.colorData,function(color,colorDetails){if(colorDetails.swatchImages.size()==0){jQuery("#loadingImage").remove();var noSwatchMsgDiv=jQuery("<div/>").attr("class","noSwatchDiv");noSwatchMsgDiv.attr("innerHTML",color);noSwatchMsgDiv.appendTo(jQuery("#cluetip-inner"));popUp.ajaxDataCache[pAsin]=noSwatchMsgDiv
noSwatchImages=1;}
else{if(!(swatchCount%swatchesPerRow)){if(swatchCount!=0)
swatchRowArray[swatchRow-1].appendTo(swatchImagesDiv);swatchRowArray[swatchRow]=jQuery("<div/>").attr("id","swatchRow"+swatchRow);swatchRowArray[swatchRow].attr("class","popOverSwatchRow");swatchRow++;}
var swatchId="#varPSwatch_"+colorDetails.Asin;var swatchImageAnchor=jQuery("<a/>").attr("id","#swatchLnk"+colorDetails.Asin);swatchImageAnchor.attr("class","swatchDPLink");swatchImageAnchor.attr("href",dpLink+"?intid=ref_dp_vPopover_swatch_"+colorDetails.Asin+"&selectedColorAsin="+colorDetails.Asin);var swatchImage=jQuery("<img/>").attr("id",swatchId);swatchImage.attr("src",colorDetails.swatchImages[0].swatchImage.URL);swatchImage.attr("class","varPswatch");swatchImage.attr("alt",color);swatchImage.hover(function(){jQuery("#cluetip-inner img:first").attr("src",popUp.swatchImageData[jQuery(this).attr("id")]);},function(){});popUp.swatchImageData[swatchId]=colorDetails.mainImages[0].mediumImage.URL.replace(".jpg","SH60_.jpg");swatchImage.appendTo(swatchImageAnchor);swatchImageAnchor.appendTo(swatchRowArray[swatchRow-1]);swatchCount++;}});if(!noSwatchImages)
{swatchRow=(swatchRow==0)?swatchRow:swatchRow-1;swatchRowArray[swatchRow].appendTo(swatchImagesDiv);if(data.currentAsinData!=undefined&&data.currentAsinData.moreColorsAvailable){var moreColorsLink=jQuery("<a/>").attr("class","popOverMoreColorLink");moreColorsLink.attr("href",dpLink+"?intid=ref_dp_vPopover_viewMore");moreColorsLink.attr("innerHTML","View More Colors");moreColorsLink.appendTo(swatchImagesDiv);}
popUp.ajaxDataCache[pAsin]=swatchImagesDiv;jQuery("#loadingImage").remove();swatchImagesDiv.appendTo(jQuery("#cluetip-inner"));}
popUp.setPopupOmnitureData(pAsin);}}});}
else if(popUp.ajaxDataCache[pAsin]!=-1)
{popUp.ajaxDataCache[pAsin].appendTo(jQuery("#cluetip-inner"));var numColorsOrig=jQuery("#cluetip-inner #pImg_"+pAsin+" .numberOfColorsMessage");if(numColorsOrig){var colorsAvailable=jQuery("<div/>").attr("class","popOverNumberOfColorsMessage");var colorsImg=jQuery("<img/>").attr("class","colorsMessageImg");colorsImg.attr("src","/images/icons/roundedColorsMsg.jpg");colorsImg.appendTo(colorsAvailable);var colorsMsg=jQuery("<div/>").attr("class","numberOfColorsMessageText");;colorsMsg.attr("innerHTML",numColorsOrig.attr("innerHTML"));colorsMsg.appendTo(colorsAvailable);numColorsOrig.hide();colorsAvailable.appendTo(jQuery("#cluetip-inner .floatedProduct"));}
jQuery(".varPswatch").hover(function(){jQuery("#cluetip-inner img:first").attr("src",popUp.swatchImageData[jQuery(this).attr("id")]);},function(){});popUp.setPopupOmnitureData(pAsin);}},onHide:function(ct,ci){if(popUp.ajaxDataCache[pAsin]){if(popUp.ajaxDataCache[pAsin]!=-1){popUp.ajaxDataCache[pAsin].remove();}
else{popUp.ajaxDataCache[pAsin]=undefined;}}}});});}
popUp.initialize(parentDivIdentifier);};