var AlbumZoom=new Class({Implements:[Events,Options],options:{wrap:".product-album-preview",preview:".album-preview-container",zooms:".album-zooms-container",handle:".album-zooms-handle",bigImages:".album-big-image",midImages:".album-mid-image",thumbs:".product-album-thumb",thumbEvent:"mouseover",zoomable:!0,zoomsSize:{x:400,y:300}},initialize:function(a,b){this.container=$(a);this.setOptions(b);this.album_big_img=$$(this.options.bigImages);this.album_mid_img=$$(this.options.midImages);this.recalculating=
!1;this.wrap=this.container.getElement(this.options.wrap);this.preview=this.container.getElement(this.options.preview);this.previewImg=this.preview.getElement("img");this.zoomsImg=(this.zooms=$(this.options.zooms)||$$(this.options.zooms)[0])?this.zooms.getElement("img"):null;this.thumbs=this.container.getElement(this.options.thumbs);this.previewImgY=this.previewImgX=this.zoomsImgY=this.zoomsImgX=0;this.handleY=this.handleX=20;this.positionY=this.positionX=0;var c="",e="",e=this.container.getElement("img.loading");
""!=e.alt&&(c=e.alt);e=e.src;this.loadingCont=(new Element("div.loading",{html:'<img alt="loading..." src="'+e+'" /> '+c,styles:{visibility:"hidden"}})).inject(this.wrap);this.baseuri="";this.safariOnLoadStarted=!1;this.checkcoords_ref=this.checkcoords.bind(this);this.findZooms()},findSelectors:function(){var a=this.thumbs.getElements("li");if(a.length){var b=this.thumbs.getElement("ul"),c=this.thumbs.getElement(".prev"),e=this.thumbs.getElement(".next"),f=a[0].getSize().x+a[0].getPatch("margin").x,
g=f*a.length;b.setStyle("width",g);var h=this.thumbs.getSize().x;g>h&&e.removeClass("over");$$(c,e).addEvent("mousedown",function(a){var d=parseInt(b.getStyle("margin-left"))||0;this.hasClass("over")||(new Fx.Tween(b,{duration:100,onComplete:function(){d=parseInt(b.getStyle("margin-left"));0>d?c.removeClass("over"):0<=d&&c.addClass("over");d<=h-g?e.addClass("over"):d>h-g&&e.removeClass("over")}})).start("margin-left",d,d+(this.hasClass("backward")?-1:1)*f)});var d=this;this.thumbs.getElements("a[rev]").each(function(a,
b){a.addEvent("click",function(a){a.stop()});a.addEvent(d.options.thumbEvent,function(b){this.getParent("li").addClass("active").getSiblings(".active").removeClass("active");d.replaceZoom(a)});d.options.zoomable&&(d.album_big_img[b]=d.album_big_img[b]||(new Element("img"+d.options.bigImages,{src:a.href})).inject(d.container));d.album_mid_img[b]=d.album_mid_img[b]||(new Element("img"+d.options.midImages,{src:a.rev})).inject(d.container)})}},findZooms:function(){var a=this.preview;this.previewImg&&
(a.addEvent("click",function(a){a.stop()}),Browser.ie&&a.setStyle("z-index",0),this.options.zoomable&&(this.zooms=this.zooms||(new Element("div"+this.options.zooms,{styles:{width:this.options.zoomsSize.x,height:this.options.zoomsSize.y}})).inject(this.container),this.zoomsImg=this.zoomsImg||(new Element("img",{src:a.href})).inject(this.zooms),this.initZoom()),this.findSelectors())},initHandle:function(){this.handle=new Element("div"+this.options.handle);this.recalculateHandleDimensions();this.handle.inject(this.preview);
this.preview.unselectable="on";this.preview.onselectstart=Function.from(!1)},initZoomsContainer:function(){var a=this.zoomsImg.src;this.zooms.innerHTML="";this.zoomsImg=(new Element("img",{src:a})).inject(this.zooms)},initZoom:function(){null==this.loadingCont||this.zoomsImg.complete||0==this.previewImg.width||0==this.previewImg.height||this.loadingCont.setStyles({left:(this.wrap.getSize().x-this.loadingCont.getSize().x)/2,top:(this.wrap.getSize().x-this.loadingCont.getSize().y)/2,visibility:"visible"});
if(Browser.safari){if(!this.safariOnLoadStarted){this.zoomsImg.addEvent("load",this.initZoom.bind(this));this.safariOnLoadStarted=!0;return}}else if(!this.zoomsImg.complete||!this.previewImg.complete){this.initZoom.delay(100,this);return}this.zoomsImgX=this.zoomsImg.width;this.zoomsImgY=this.zoomsImg.height;this.previewImgX=this.previewImg.width;this.previewImgY=this.previewImg.height;0==this.zoomsImgX||0==this.zoomsImgY||0==this.previewImgX||0==this.previewImgY?this.initZoom.delay(100,this):(null!=
this.loadingCont&&this.loadingCont.setStyle("visibility","hidden"),this.zoomsX=this.wrap.getPosition().x+this.wrap.getSize().x+10,this.zooms.setStyles({left:this.zoomsX,top:this.wrap.getPosition().y}),this.handle?this.recalculateHandleDimensions():(this.initZoomsContainer(),this.initHandle(),document.addEvent("mousemove",this.checkcoords_ref),this.preview.addEvent("mousemove",this.mousemove.bind(this))))},replaceZoom:function(a){a.rev!=this.previewImg.src&&(this.previewImg.src=a.rev,this.options.zoomable&&
(a=new Element("img",{src:a.href}),a.replaces(this.zoomsImg),this.zoomsImg=a,this.safariOnLoadStarted=!1,this.initZoom()))},stopZoom:function(){document.removeEvent("mousemove",this.checkcoords_ref)},checkcoords:function(a){var b=a.page;a=b.x;var b=b.y,c=this.previewImg.getPosition(),e=c.x,c=c.y;if(a>e+this.previewImgX||a<e||b>c+this.previewImgY||b<c)return this.hiderect(),!1;Browser.ie&&this.preview.setStyle("z-index",1);return!0},mousemove:function(a){a.stop();if(!this.recalculating&&this.checkcoords(a)){this.recalculating=
!0;var b=a.page;a=b.x;var b=b.y,c=this.previewImg.getPosition(),e=c.y;this.positionX=a-c.x;this.positionY=b-e;this.positionX+this.handleX/2>=this.previewImgX&&(this.positionX=this.previewImgX-this.handleX/2);this.positionY+this.handleY/2>=this.previewImgY&&(this.positionY=this.previewImgY-this.handleY/2);0>=this.positionX-this.handleX/2&&(this.positionX=this.handleX/2);0>=this.positionY-this.handleY/2&&(this.positionY=this.handleY/2);setTimeout(this.showrect.bind(this),16)}},showrect:function(){var a=
parseInt(this.positionX-this.handleX/2),b=parseInt(this.positionY-this.handleY/2);this.handle.setStyles({left:a,top:b,visibility:"visible"});perX=this.zoomsImgX/this.previewImgX*a;perY=this.zoomsImgY/this.previewImgY*b;this.zoomsImg.setStyles({left:-perX,top:-perY,visibility:"visible"});this.zooms.setStyles({left:this.zoomsX,visibility:"visible"});this.recalculating=!1},hiderect:function(){this.handle&&this.handle.setStyle("visibility","hidden");this.zooms.setStyles({left:-1E4,visibility:"hidden"});
Browser.ie&&this.preview.setStyle("z-index",0)},recalculateHandleDimensions:function(){this.handleX=(this.zooms.getSize().x-3)/(this.zoomsImgX/this.previewImgX);this.handleY=(this.zooms.getSize().y-3)/(this.zoomsImgY/this.previewImgY);this.handleX>this.previewImgX&&(this.handleX=this.previewImgX);this.handleY>this.previewImgY&&(this.handleY=this.previewImgY);this.handle.setStyles({width:this.handleX,height:this.handleY})}}),LayoutRequest=new Class({Implements:[Events,Options],options:{threshold:50,
loadCls:"loading",errorCls:"error",completeCls:"",onRequest:function(a){var b,c=this.options.loadCls;(b=a.update)&&b.addClass(c);(b=a.append)&&(new Element("div",{"data-load":a.name,"class":c})).inject(b)},onFailure:function(a){var b,c=this.options.loadCls;if(b=a.append)b=b.getElement("div[data-load="+a.name+"]");a.update&&(b=a.update);b.removeClass(c)},onComplete:function(a){var b,c=this.options.loadCls,e=this.options.errorCls;if(b=a.append)b=b.getElement("div[data-load="+a.name+"]");b&&b.destroy();
(b=a.update)&&b.removeClass(c).removeClass(e)},onSuccess:function(){}},initialize:function(a,b){a.length&&(this.sync_queue=a,this.setOptions(b).fireEvent("load"),this.initEvent())},initEvent:function(){function a(){b||(b=function(){c.progress.call(c,c.sync_queue);c.sync_queue.length||win.removeEvent("scroll",a).removeEvent("resize",a);b=null}.delay(200))}var b,c=this;this.cur_sync={};win=window;win.addEvent("domready",function(){c.progress.call(c,c.sync_queue)});this.sync_queue.length&&win.addEvents({scroll:a,
resize:a})},progress:function(a){if(!a.length)return this;var b=[],c=[];a.each(function(a){if(!a.require)return b.push(a);c.push(a)});b.length&&b.each(this.filterSync,this);c.length&&this.require(c,a)},filterItems:function(a){var b=(a.update||a.append).getOffsets().y,c=window,e=c.getScroll(),c=c.getSize().y;if(a=a.append)b+=a.getSize().y;if(a=this.options.threshold)b-=a;return b<=e.y+c?!0:!1},filterSync:function(a){if(!a.update&&!a.append)return this.sync_queue.erase(a);this.filterItems(a)&&this.request(a)},
require:function(a,b){a.each(function(a){var b=this.cur_sync[a.require];if(b&&b.running)return b.ajaxCb=function(){return this.filterSync(a)};"complete"==b&&this.filterSync(a)},this)},request:function(a){if(a){var b=a.onSuccess||function(){},c=a.onFailure||function(){},e=a.onRequest||function(){},f=this,g=2,h=f.cur_sync[a.name],d=$(a.name);d&&(a.update?a.update=d:a.append=d);return!d&&this.detail?this.sync_queue.erase(a):h&&h.running?this:this.cur_sync[a.name]=(new Request.HTML(Object.append(a,{timeout:3E4,
data:"invalid_post_data=1"+(a.view?"&view="+a.view:""),onTimeout:function(b){this.cancel();if(!g)return f.fireEvent("failure",a).complete(a);g-=1;this.send()},onRequest:function(){f.fireEvent("request",a);e.apply(f,arguments)},onFailure:function(){f.fireEvent("failure",a);c.apply(f,arguments);f.failure.call(f,a)},onSuccess:function(c){f.fireEvent("complete",a);b.apply(f,arguments);f.complete.call(f,a);this.ajaxCb&&this.ajaxCb.call(f)}}))).send()}},complete:function(a){this.cur_sync[a.name]="complete";
this.sync_queue.erase(a);this.sync_queue.length||this.success()},failure:function(a){this.cur_sync[a.name]="failure";this.sync_queue.erase(a).each(function(b){b.require==a.name&&(delete b.require,this.filterSync(b))},this)},success:function(){this.fireEvent("success")}});