/*--------------------------------------------------------------------------*
 * 
 * Category Zoom (Whitney)
 * 
 * Version 3.0.0
 * 
 * Copyright (C) 2009 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(){try{if(location.pathname.toLowerCase()=='/searchresults.asp'||location.pathname.toLowerCase().indexOf('-s/')!=-1||location.pathname.toLowerCase().indexOf('_s/')!=-1){if(WhitneyCategoryZoomSettings.ENABLED){WhitneyCategoryZoomStartup.load();}}}
catch(e){}}};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.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;var ya=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.photoData!=null){this.enteredCallback();return;}
wa=this.photosPath+'/'+this.productCode+'-'+this.getCurrentFileNumber()+this.mainPhotoElement.src.substring(this.mainPhotoElement.src.lastIndexOf('.'));ya=new Element('img',{});this.startShowingWait();Event.observe(ya,'load',function(){Event.stopObserving(ya);va.stopShowingWait();if(ya.width==null||ya.height==null){return;}
if(ya.width<=0||ya.height<=0){return;}
va.photoData={fileName:ya.src,width:ya.width,height:ya.height};va.enteredCallback();});Event.observe(ya,'error',function(){Event.stopObserving(ya);va.stopShowingWait();va.exited();});ya.src=wa;},enteredCallback:function(){var x=this.currentX;var y=this.currentY;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(za){var Aa;if(za==null){return 0;}
Aa=za.indexOf('px');if(Aa==-1){return 0;}
return Number(za.substring(0,Aa));},viewPortClicked:function(){var Ba=this.mainPhotoAnchorElement;if(Ba==null){return;}
window.location.href=Ba.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 Ca=null;if(this.overlayElement!=null){return;}
Ca=new Element('div',{style:'display: none;'});Ca.addClassName('whitney_overlay_class');this.overlayElement=Ca;Ca.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(Ca);Ca.show();},removeOverlay:function(){if(this.overlayElement==null){return;}
this.overlayElement.hide();this.overlayElement.remove();this.overlayElement=null;},createViewPort:function(){var Da=null;var Ea=null;var Fa;var Ga;var x=this.currentX;var y=this.currentY;if(this.viewPortElement!=null){return;}
Fa=this.mainPhotoWidth/this.zoomRatio;Ga=this.mainPhotoHeight/this.zoomRatio;Da=new Element('div',{style:'display: none;'});this.viewPortElement=Da;Ea=new Element('img',{src:this.mainPhotoElement.src,alt:this.mainPhotoElement.alt,title:this.mainPhotoElement.title,width:this.mainPhotoWidth+'px',height:this.mainPhotoHeight+'px'});Ea.setStyle({width:this.mainPhotoWidth+'px',height:this.mainPhotoHeight+'px'});this.viewPortElementImage=Ea;Da.addClassName('whitney_view_port_class');Da.setStyle({position:'absolute',width:Fa+'px',height:Ga+'px',overflow:'hidden',zIndex:101,backgroundColor:'transparent'});Ea.addClassName('whitney_view_port_image_class');Da.update(Ea);this.body.insert(Da);this.moveViewPort();Da.show();},removeViewPort:function(){if(this.viewPortElement==null){return;}
this.viewPortElement.hide();this.viewPortElement.remove();this.viewPortElement=null;this.viewPortElementImage=null;},createZoomedPhoto:function(){var Ha=null;var Ia=null;var Ja=null;var Ka;var La;var x=this.currentX;var y=this.currentY;if(this.zoomedPhotoElement!=null){return;}
if(this.displayZoomOnRight){Ka=this.mainPhotoLeft+this.mainPhotoWidth;}
else{Ka=this.mainPhotoLeft-this.mainPhotoWidth;}
if(this.displayZoomOnTop){La=this.mainPhotoTop -1;}
else{La=this.mainPhotoTop+this.mainPhotoHeight;}
Ha=new Element('div',{style:'display: none;'});this.zoomedPhotoElement=Ha;Ha.addClassName('whitney_zoomed_photo_class');Ia=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'});Ia.addClassName('whitney_zoomed_photo_image_class');Ia.setStyle({width:this.photoData.width+'px',height:this.photoData.height+'px'});this.zoomedPhotoElementImage=Ia;Ha.setStyle({position:'absolute',width:this.mainPhotoWidth+'px',height:this.mainPhotoHeight+'px',top:La+'px',left:Ka+'px',overflow:'hidden',zIndex:102});Ha.update(Ia);this.body.insert(Ha);this.moveZoomedPhoto();Ha.show();},removeZoomedPhoto:function(){if(this.zoomedPhotoElement==null){return;}
this.zoomedPhotoElement.hide();this.zoomedPhotoElement.remove();this.zoomedPhotoElement=null;this.zoomedPhotoElementImage=null;},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,PHOTOS_PATH:'/v/vspfiles/photos',MORE_INFO_FILE_NAME:'Bullet_MoreInfo.gif',ADD_TO_CART_FILE_NAME:'btn_addtocart_small.gif',NO_PHOTO_FILE_NAME:'nophoto.gif',CONTENT_AREA_ID:'content_area'};var WhitneyCategoryZoom=Class.create(WhitneyZoom,{initialize:function($super){$super();},getCurrentFileNumber:function(){return 2;}});var WhitneyCategoryZoomStartup={load:function(){var Na=null;var Oa=null;try{Na=$(WhitneyCategoryZoomSettings.CONTENT_AREA_ID);if(Na==null){return;}
Oa=Na.select('a');if(Oa==null||Oa.size<1){return null;}
Oa.each(function(Pa){var Qa=null;var Ra=null;var Sa=null;var Ta=null;Sa=WhitneyCategoryZoomStartup.getProductCodeFromURL(Pa.href);if(Sa==null){return;}
Qa=Pa.select('img');if(Qa==null||Qa.size()!=1){return;}
Ra=Qa.first();if(Ra.src.toLowerCase().indexOf(WhitneyCategoryZoomSettings.MORE_INFO_FILE_NAME.toLowerCase())!=-1){return;}
if(Ra.src.toLowerCase().indexOf(WhitneyCategoryZoomSettings.ADD_TO_CART_FILE_NAME.toLowerCase())!=-1){return;}
if(Ra.src.toLowerCase().indexOf(WhitneyCategoryZoomSettings.NO_PHOTO_FILE_NAME.toLowerCase())!=-1){return;}
Ta=new WhitneyCategoryZoom();Ta.noPhotoFileName=WhitneyCategoryZoomSettings.NO_PHOTO_FILE_NAME;Ta.overlayOpacity=WhitneyCategoryZoomSettings.OVERLAY_OPACITY;Ta.allowClickOnViewPort=WhitneyCategoryZoomSettings.ALLOW_CLICK_ON_VIEW_PORT;Ta.displayZoomOnRight=WhitneyCategoryZoomSettings.DISPLAY_ZOOM_ON_RIGHT;Ta.displayZoomOnTop=WhitneyCategoryZoomSettings.DISPLAY_ZOOM_ON_TOP;Ta.getPhotosURLTemplate=WhitneyCategoryZoomSettings.GET_PHOTOS_URL_TEMPLATE;Ta.productCode=Sa;Ta.photosPath=WhitneyCategoryZoomSettings.PHOTOS_PATH;Ta.mainPhotoElement=Ra;Ta.mainPhotoAnchorElement=Pa;Ta.load();});}
catch(e){return;}},getProductCodeFromURL:function(Ua){var Va=null;if(Ua==null){return null;}
Va=Ua.match(/\/productdetails\.asp\?(?:[\&]?.*\=.*)*productcode=([^\&\#]+)/i);if(Va!=null&&Va.length>=2){return unescape(Va[1]);}
Va=Ua.match(/(?:_p|-p)\/(.+)\.htm/i);if(Va!=null&&Va.length>=2){return unescape(Va[1]);}
return null;}};