/*--------------------------------------------------------------------------*
 * 
 * Category Zoom (Whitney)
 * 
 * Version 2.0.5
 * 
 * Copyright (C) 2008 Brand Labs LLC
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
 * 02110-1301  USA
 * 
 *--------------------------------------------------------------------------*/
var Whitney={load:function(){if(location.pathname.toLowerCase()=='/searchresults.asp'||location.pathname.toLowerCase().indexOf('-s/')!=-1||location.pathname.toLowerCase().indexOf('_s/')!=-1){if(WhitneyCategoryZoomSettings.ENABLED){WhitneyCategoryZoomStartup.load();}}}};Event.observe(window,'load',Whitney.load);var WhitneyZoom=Class.create({initialize:function(){this.productCode=null;this.photosPath=null;this.mainPhotoElement=null;this.mainPhotoAnchorElement=null;this.noPhotoFileName=null;this.overlayOpacity=null;this.allowClickOnViewPort=null;this.displayZoomOnRight=null;this.displayZoomOnTop=null;this.getPhotosURLTemplate=null;this.body=null;this.mainPhotoWidth=null;this.mainPhotoHeight=null;this.mainPhotoLeft=null;this.mainPhotoTop=null;this.mainPhotoBorderLeft=null;this.mainPhotoBorderTop=null;this.mainPhotoBorderRight=null;this.mainPhotoBorderBottom=null;this.overlayElement=null;this.viewPortElement=null;this.viewPortElementImage=null;this.zoomedPhotoElement=null;this.zoomedPhotoElementImage=null;this.moveEventListener=null;this.imageData=null;this.photoData=null;this.zoomRatio=null;this.currentX=null;this.currentY=null;},load:function(){var aa;try{this.body=$$('body').first();}
catch(e){return;}
if(this.mainPhotoElement==null||this.body==null){return;}
aa=this.mainPhotoElement.src;if(aa==null||aa.indexOf(this.noPhotoFileName)!=-1){return;}
Event.observe(this.mainPhotoElement,'mouseover',this.entered.bindAsEventListener(this));},move:function(ba){this.currentX=Event.pointerX(ba);this.currentY=Event.pointerY(ba);this.moveItems();},moveItems:function(){var x=this.currentX;var y=this.currentY;if(this.mainPhotoElement==null){return;}
if(x<(this.mainPhotoLeft-this.mainPhotoBorderLeft)){this.exited();return;}
if(x>(this.mainPhotoLeft+this.mainPhotoWidth+this.mainPhotoBorderRight)){this.exited();return;}
if(y<(this.mainPhotoTop-this.mainPhotoBorderTop)){this.exited();return;}
if(y>(this.mainPhotoTop+this.mainPhotoHeight+this.mainPhotoBorderBottom)){this.exited();return;}
this.moveViewPort();this.moveZoomedPhoto();},moveViewPort:function(){var ca=this.viewPortElement;var da=this.viewPortElementImage;var ea;var fa;var ga;var ha;var ia;var ja;var x=this.currentX;var y=this.currentY;if(ca==null||da==null){return;}
ea=ca.getWidth();fa=ca.getHeight();ga=ea/2;ha=fa/2;ia=x;ja=y;if(this.mainPhotoLeft>(x-ga)){ia=this.mainPhotoLeft+ga;}
if((this.mainPhotoLeft+this.mainPhotoWidth)<(x+ga)){ia=this.mainPhotoLeft+this.mainPhotoWidth-ga;}
if(this.mainPhotoTop>(y-ha)){ja=this.mainPhotoTop+ha;}
if((this.mainPhotoTop+this.mainPhotoHeight)<(y+ha)){ja=this.mainPhotoTop+this.mainPhotoHeight-ha;}
ca.setStyle({left:ia-ga+'px',top:ja-ha+'px'});da.setStyle({marginLeft:-(ia-this.mainPhotoLeft)+(ga-1)+'px',marginTop:-(ja-this.mainPhotoTop)+(ha-1)+'px'});},moveZoomedPhoto:function(){var ka=this.zoomedPhotoElement;var la=this.zoomedPhotoElementImage;var ma;var na;var oa;var pa;var qa;var ra;var x=this.currentX;var y=this.currentY;if(ka==null||la==null){return;}
ma=ka.getWidth();na=ka.getHeight();qa=ma/2;ra=na/2;oa=this.mainPhotoWidth*this.zoomRatio;pa=this.mainPhotoHeight*this.zoomRatio;var sa=-((x-this.mainPhotoLeft)*this.zoomRatio)+qa;var ta=-((y-this.mainPhotoTop)*this.zoomRatio)+ra;if(sa>0){sa=0;}
else if(sa<(ma-oa)){sa=ma-oa;}
if(ta>0){ta=0;}
else if(ta<(na-pa)){ta=na-pa;}
la.setStyle({marginLeft:sa+'px',marginTop:ta+'px'});},entered:function(ua){var va=this;var wa=null;var x=Event.pointerX(ua);var y=Event.pointerY(ua);var xa=null;this.currentX=x;this.currentY=y;if(this.mainPhotoElement==null){return;}
if(this.moveEventListener!=null){return;}
xa=this.mainPhotoElement.positionedOffset();this.mainPhotoLeft=xa.left;this.mainPhotoTop=xa.top;this.mainPhotoWidth=this.mainPhotoElement.getWidth();this.mainPhotoHeight=this.mainPhotoElement.getHeight();this.mainPhotoBorderLeft=this.parseWidth(this.mainPhotoElement.getStyle('borderLeftWidth'));this.mainPhotoBorderTop=this.parseWidth(this.mainPhotoElement.getStyle('borderTopWidth'));this.mainPhotoBorderRight=this.parseWidth(this.mainPhotoElement.getStyle('borderRightWidth'));this.mainPhotoBorderBottom=this.parseWidth(this.mainPhotoElement.getStyle('borderBottomWidth'));this.mainPhotoWidth=this.mainPhotoWidth-this.mainPhotoBorderLeft-this.mainPhotoBorderRight;this.mainPhotoHeight=this.mainPhotoHeight-this.mainPhotoBorderTop-this.mainPhotoBorderBottom;this.mainPhotoLeft=this.mainPhotoLeft+this.mainPhotoBorderLeft;this.mainPhotoTop=this.mainPhotoTop+this.mainPhotoBorderTop;this.moveEventListener=this.move.bindAsEventListener(this);Event.observe(this.body,'mousemove',this.moveEventListener);if(this.imageData!=null){this.enteredCallback();return;}
wa=this.getPhotosURLTemplate.evaluate({productCode:escape(this.productCode)});new Ajax.Request(wa,{method:'get',evalJSON:true,sanitizeJSON:true,onCreate:function(){va.startShowingWait();},onSuccess:function(ya){var za=ya.responseJSON;va.stopShowingWait();if(za==null||za.size()<=0){return;}
va.imageData=za;va.enteredCallback();},onFailure:function(){va.stopShowingWait();va.exited();}});},enteredCallback:function(){var x=this.currentX;var y=this.currentY;this.photoData=this.getLargePhotoData();if(this.photoData==null){return;}
if(this.mainPhotoWidth>=this.photoData.width&&this.mainPhotoHeight>=this.photoData.height){this.exited();return;}
this.zoomRatio=this.photoData.width/this.mainPhotoWidth;this.createOverlay();this.createViewPort();this.createZoomedPhoto();if(this.allowClickOnViewPort){Event.observe(this.viewPortElement,'click',this.viewPortClicked.bindAsEventListener(this));}
this.moveItems();},parseWidth:function(Aa){var Ba;if(Aa==null){return 0;}
Ba=Aa.indexOf('px');if(Ba==-1){return 0;}
return Number(Aa.substring(0,Ba));},viewPortClicked:function(){var Ca=this.mainPhotoAnchorElement;if(Ca==null){return;}
window.location.href=Ca.href;},exited:function(){this.removeZoomedPhoto();this.removeViewPort();this.removeOverlay();if(this.moveEventListener!=null){Event.stopObserving(this.body,'mousemove',this.moveEventListener);this.moveEventListener=null;}},createOverlay:function(){var Da=null;if(this.overlayElement!=null){return;}
Da=new Element('div',{style:'display: none;'});Da.addClassName('whitney_overlay_class');this.overlayElement=Da;Da.setStyle({position:'absolute',width:this.mainPhotoWidth+'px',height:this.mainPhotoHeight+'px',left:this.mainPhotoLeft+'px',top:this.mainPhotoTop+'px',overflow:'hidden',zIndex:100,opacity:this.overlayOpacity});this.body.insert(Da);Da.show();},removeOverlay:function(){if(this.overlayElement==null){return;}
this.overlayElement.hide();this.overlayElement.remove();this.overlayElement=null;},createViewPort:function(){var Ea=null;var Fa=null;var Ga;var Ha;var x=this.currentX;var y=this.currentY;if(this.viewPortElement!=null){return;}
Ga=this.mainPhotoWidth/this.zoomRatio;Ha=this.mainPhotoHeight/this.zoomRatio;Ea=new Element('div',{style:'display: none;'});this.viewPortElement=Ea;Fa=new Element('img',{src:this.mainPhotoElement.src,alt:this.mainPhotoElement.alt,title:this.mainPhotoElement.title,width:this.mainPhotoWidth+'px',height:this.mainPhotoHeight+'px'});Fa.setStyle({width:this.mainPhotoWidth+'px',height:this.mainPhotoHeight+'px'});this.viewPortElementImage=Fa;Ea.addClassName('whitney_view_port_class');Ea.setStyle({position:'absolute',width:Ga+'px',height:Ha+'px',overflow:'hidden',zIndex:101,backgroundColor:'transparent'});Fa.addClassName('whitney_view_port_image_class');Ea.update(Fa);this.body.insert(Ea);this.moveViewPort();Ea.show();},removeViewPort:function(){if(this.viewPortElement==null){return;}
this.viewPortElement.hide();this.viewPortElement.remove();this.viewPortElement=null;this.viewPortElementImage=null;},createZoomedPhoto:function(){var Ia=null;var Ja=null;var Ka=null;var La;var Ma;var x=this.currentX;var y=this.currentY;if(this.zoomedPhotoElement!=null){return;}
if(this.displayZoomOnRight){La=this.mainPhotoLeft+this.mainPhotoWidth;}
else{La=this.mainPhotoLeft-this.mainPhotoWidth;}
if(this.displayZoomOnTop){Ma=this.mainPhotoTop -1;}
else{Ma=this.mainPhotoTop+this.mainPhotoHeight;}
Ia=new Element('div',{style:'display: none;'});this.zoomedPhotoElement=Ia;Ia.addClassName('whitney_zoomed_photo_class');Ja=new Element('img',{src:this.photoData.fileName,alt:this.mainPhotoElement.alt,title:this.mainPhotoElement.title,width:this.photoData.width+'px',height:this.photoData.height+'px',border:'0'});Ja.addClassName('whitney_zoomed_photo_image_class');Ja.setStyle({width:this.photoData.width+'px',height:this.photoData.height+'px'});this.zoomedPhotoElementImage=Ja;Ia.setStyle({position:'absolute',width:this.mainPhotoWidth+'px',height:this.mainPhotoHeight+'px',top:Ma+'px',left:La+'px',overflow:'hidden',zIndex:102});Ia.update(Ja);this.body.insert(Ia);this.moveZoomedPhoto();Ia.show();},removeZoomedPhoto:function(){if(this.zoomedPhotoElement==null){return;}
this.zoomedPhotoElement.hide();this.zoomedPhotoElement.remove();this.zoomedPhotoElement=null;this.zoomedPhotoElementImage=null;},getLargePhotoData:function(){var Na=null;var Oa=null;if(this.imageData==null){return null;}
Na=this.productCode+'-'+this.getCurrentFileNumber();Na=Na.toLowerCase();Oa=this.imageData.select(function(Pa){if(Pa==null||Pa.fileName==null){return false;}
if(Pa.fileName.toLowerCase().indexOf(Na)!=-1){return true;}});if(Oa.size()!=1){return null;}
Oa=Oa.first();return{fileName:this.photosPath+'/'+Oa.fileName,width:Oa.width,height:Oa.height};},getCurrentFileNumber:function(){},startShowingWait:function(){if(this.mainPhotoElement!=null){this.mainPhotoElement.setStyle({cursor:'wait'});}
if(this.mainPhotoAnchorElement!=null){this.mainPhotoAnchorElement.setStyle({cursor:'wait'});}},stopShowingWait:function(){if(this.mainPhotoElement!=null){this.mainPhotoElement.setStyle({cursor:'auto'});}
if(this.mainPhotoAnchorElement!=null){this.mainPhotoAnchorElement.setStyle({cursor:'auto'});}}});var WhitneyCategoryZoomSettings={ENABLED:false,VIEW_PORT_WIDTH:140,VIEW_PORT_HEIGHT:140,NO_PHOTO_FILE_NAME:'nophoto.gif',OVERLAY_OPACITY:0.5,ALLOW_CLICK_ON_VIEW_PORT:true,DISPLAY_ZOOM_ON_RIGHT:true,DISPLAY_ZOOM_ON_TOP:true,GET_PHOTOS_URL_TEMPLATE:new Template('/v/whitney_get_photos.asp?productcode=#{productCode}&type=3'),PHOTOS_PATH:'/v/vspfiles/photos',MORE_INFO_FILE_NAME:'Bullet_MoreInfo.gif',CONTENT_AREA_ID:'content_area'};var WhitneyCategoryZoom=Class.create(WhitneyZoom,{initialize:function($super){$super();},getCurrentFileNumber:function(){return 2;}});var WhitneyCategoryZoomStartup={load:function(){var Ra=null;var Sa=null;try{Ra=$(WhitneyCategoryZoomSettings.CONTENT_AREA_ID);if(Ra==null){return;}
Sa=Ra.select('a');if(Sa==null||Sa.size<1){return null;}
Sa.each(function(Ta){var Ua=null;var Va=null;var Wa=null;var Xa=null;Wa=WhitneyCategoryZoomStartup.getProductCodeFromURL(Ta.href);if(Wa==null){return;}
Ua=Ta.select('img');if(Ua==null||Ua.size()!=1){return;}
if(Ua.first().src.indexOf(WhitneyCategoryZoomSettings.MORE_INFO_FILE_NAME)!=-1){return;}
Xa=new WhitneyCategoryZoom();Xa.noPhotoFileName=WhitneyCategoryZoomSettings.NO_PHOTO_FILE_NAME;Xa.overlayOpacity=WhitneyCategoryZoomSettings.OVERLAY_OPACITY;Xa.allowClickOnViewPort=WhitneyCategoryZoomSettings.ALLOW_CLICK_ON_VIEW_PORT;Xa.displayZoomOnRight=WhitneyCategoryZoomSettings.DISPLAY_ZOOM_ON_RIGHT;Xa.displayZoomOnTop=WhitneyCategoryZoomSettings.DISPLAY_ZOOM_ON_TOP;Xa.getPhotosURLTemplate=WhitneyCategoryZoomSettings.GET_PHOTOS_URL_TEMPLATE;Xa.productCode=Wa;Xa.photosPath=WhitneyCategoryZoomSettings.PHOTOS_PATH;Xa.mainPhotoElement=Ua.first();Xa.mainPhotoAnchorElement=Ta;Xa.load();});}
catch(e){return;}},getProductCodeFromURL:function(Ya){var Za=null;if(Ya==null){return null;}
Za=Ya.match(/\/productdetails\.asp\?(?:[\&]?.*\=.*)*productcode=([^\&\#]+)/i);if(Za!=null&&Za.length>=2){return unescape(Za[1]);}
Za=Ya.match(/(?:_p|-p)\/(.+)\.htm/i);if(Za!=null&&Za.length>=2){return unescape(Za[1]);}
return null;}};
