﻿var ReMooz=new Class({Implements:[Events,Options,Chain],options:{link:null,type:'image',container:null,className:null,centered:false,dragging:true,closeOnClick:true,shadow:(Browser.Engine.trident)?'onOpenEnd':'onOpen',resize:true,margin:20,resizeFactor:0.95,resizeLimit:false,fixedSize:false,cutOut:true,addClick:true,opacityLoad:0.6,opacityResize:1,opacityTitle:0.9,resizeOptions:{},fxOptions:{},closer:true,parse:false,parseSecure:false,temporary:false,onBuild:$empty,onLoad:$empty,onOpen:$empty,onOpenEnd:$empty,onClose:$empty,onCloseEnd:$empty,generateTitle:function(el){var text=el.get('title');if(!text)return false;var title=text.split(' :: ');var head=new Element('h6',{'html':title[0]});return(title[1])?[head,new Element('p',{'html':title[1]})]:head}},initialize:function(element,options){this.element=$(element);this.setOptions(options);if(this.options.parse){var obj=this.element.getProperty(this.options.parse);if(obj&&(obj=JSON.decode(obj,this.options.parseSecure)))this.setOptions(obj)}var origin=this.options.origin;this.origin=((origin)?$(origin)||this.element.getElement(origin):null)||this.element;this.link=this.options.link||this.element.get('href')||this.element.get('src');this.container=$(this.options.container)||this.element.getDocument();this.bound={'click':function(e){this.open.delay(1,this);return false}.bind(this),'close':this.close.bind(this),'dragClose':function(e){if(e.rightClick)return;this.close()}.bind(this)};if(this.options.addClick)this.bindToElement()},destroy:function(){if(this.box)this.box.destroy();this.box=this.tweens=this.body=this.content=null},bindToElement:function(element){($(element)||this.element).addClass('remooz-element').addEvent('click',this.bound.click);return this},getOriginCoordinates:function(){var coords=this.origin.getCoordinates();delete coords.right;delete coords.bottom;return coords},open:function(e){if(this.opened)return(e)?this.close():this;this.opened=this.loading=true;if(!this.box)this.build();this.coords=this.getOriginCoordinates();this.coords.opacity=this.options.opacityLoad;this.coords.display='';this.tweens.box.set(this.coords);this.box.addClass('remooz-loading');ReMooz.open(this.fireEvent('onLoad'));this['open'+this.options.type.capitalize()]();return this},finishOpen:function(){this.tweens.fade.start(0,1);this.drag.attach();this.fireEvent('onOpenEnd').callChain()},close:function(){if(!this.opened)return this;this.opened=false;ReMooz.close(this.fireEvent('onClose'));if(this.loading){this.box.setStyle('display','none');return this}this.drag.detach();this.tweens.fade.cancel().set(0).fireEvent('onComplete');if(this.tweens.box.timer)this.tweens.box.clearChain();var vars=this.getOriginCoordinates();if(this.options.opacityResize!=1)vars.opacity=this.options.opacityResize;this.tweens.box.start(vars).chain(this.closeEnd.bind(this));return this},closeEnd:function(){if(this.options.cutOut)this.element.setStyle('visibility','visible');this.box.setStyle('display','none');this.fireEvent('onCloseEnd').callChain();if(this.options.temporary)this.destroy()},openImage:function(){var tmp=new Image();tmp.onload=tmp.onabort=tmp.onerror=function(fast){this.loading=tmp.onload=tmp.onabort=tmp.onerror=null;if(!tmp.width||!this.opened){this.fireEvent('onError').close();return}var to={x:tmp.width,y:tmp.height};if(!this.content)this.content=$(tmp).inject(this.body);else tmp=null;this[(this.options.resize)?'zoomRelativeTo':'zoomTo'].create({'delay':(tmp&&fast!==true)?1:null,'arguments':[to],'bind':this})()}.bind(this);tmp.src=this.link;if(tmp&&tmp.complete&&tmp.onload)tmp.onload(true)},openElement:function(){this.content=this.content||$(this.link)||$E(this.link);if(!this.content){this.fireEvent('onError').close();return}this.content.inject(this.body);this.zoomTo({x:this.content.scrollWidth,y:this.content.scrollHeight})},zoomRelativeTo:function(to){var scale=this.options.resizeLimit;if(!scale){scale=this.container.getSize();scale.x*=this.options.resizeFactor;scale.y*=this.options.resizeFactor}for(var i=2;i--;){if(to.x>scale.x){to.y*=scale.x/to.x;to.x=scale.x}else if(to.y>scale.y){to.x*=scale.y/to.y;to.y=scale.y}}return this.zoomTo({x:to.x.toInt(),y:to.y.toInt()})},zoomTo:function(to){to=this.options.fixedSize||to;var box=this.container.getSize(),scroll=this.container.getScroll();var pos=(!this.options.centered)?{x:(this.coords.left+(this.coords.width/2)-to.x/2).toInt().limit(scroll.x+this.options.margin,scroll.x+box.x-this.options.margin-to.x),y:(this.coords.top+(this.coords.height/2)-to.y/2).toInt().limit(scroll.y+this.options.margin,scroll.y+box.y-this.options.margin-to.y)}:{x:scroll.x+((box.x-to.x)/2).toInt(),y:scroll.y+((box.y-to.y)/2).toInt()};if(this.options.cutOut)this.element.setStyle('visibility','hidden');this.box.removeClass('remooz-loading');var vars={left:pos.x,top:pos.y,width:to.x,height:to.y};if(this.options.opacityResize!=1)vars.opacity=[this.options.opacityResize,1];else this.box.set('opacity',1);this.tweens.box.start(vars).chain(this.finishOpen.bind(this));this.fireEvent('onOpen')},build:function(){this.addEvent('onBlur',function(){this.focused=false;this.box.removeClass('remooz-box-focus').setStyle('z-index',ReMooz.options.zIndex)},true);this.addEvent('onFocus',function(){this.focused=true;this.box.addClass('remooz-box-focus').setStyle('z-index',ReMooz.options.zIndexFocus)},true);var classes=['remooz-box','remooz-type-'+this.options.type,'remooz-engine-'+Browser.Engine.name+Browser.Engine.version];if(this.options.className)classes.push(this.options.className);this.box=new Element('div',{'class':classes.join(' '),'styles':{'display':'none','top':0,'left':0,'zIndex':ReMooz.options.zIndex}});this.tweens={'box':new Fx.Morph(this.box,$merge({'duration':400,'unit':'px','transition':Fx.Transitions.Quart.easeOut,'chain':'cancel'},this.options.resizeOptions)),'fade':new Fx.Tween(null,$merge({'property':'opacity','duration':(Browser.Engine.trident)?0:300,'chain':'cancel'},this.options.fxOptions)).addEvents({'onComplete':function(){if(!this.element.get('opacity'))this.element.setStyle('display','none')},'onStart':function(){if(!this.element.get('opacity'))this.element.setStyle('display','')}})};this.tweens.fade.element=$$();if(this.options.shadow){if(Browser.Engine.webkit420){this.box.setStyle('-webkit-box-shadow','0 0 10px rgba(0, 0, 0, 0.7)')}else if(!Browser.Engine.trident4){var shadow=new Element('div',{'class':'remooz-bg-wrap'}).inject(this.box);['n','ne','e','se','s','sw','w','nw'].each(function(dir){new Element('div',{'class':'remooz-bg remooz-bg-'+dir}).inject(shadow)});this.tweens.bg=new Fx.Tween(shadow,{'property':'opacity','chain':'cancel'}).set(0);this.addEvent(this.options.shadow,this.tweens.bg.set.bind(this.tweens.bg,1),true);this.addEvent('onClose',this.tweens.bg.set.bind(this.tweens.bg,0),true)}}if(this.options.closer){var closer=new Element('a',{'class':'remooz-btn-close','events':{'click':this.bound.close}}).inject(this.box);this.tweens.fade.element.push(closer)}this.body=new Element('div',{'class':'remooz-body'}).inject(this.box);var title=this.options.title||this.options.generateTitle.call(this,this.element);if(title){var title=new Element('div',{'class':'remooz-title'}).adopt(new Element('div',{'class':'remooz-title-bg','opacity':this.options.opacityTitle}),new Element('div',{'class':'remooz-title-content'}).adopt(title)).inject(this.box);this.tweens.fade.element.push(title)}this.tweens.fade.set(0).fireEvent('onComplete');this.drag=new Drag.Move(this.box,{'snap':15,'preventDefault':true,'onBeforeStart':function(){if(!this.focused&&!this.loading)ReMooz.focus(this);else if(this.loading||this.options.closeOnClick)this.box.addEvent('mouseup',this.bound.dragClose)}.bind(this),'onSnap':function(){this.box.removeEvent('mouseup',this.bound.dragClose);if(!this.options.dragging)this.drag.stop();else this.box.addClass('remooz-box-dragging')}.bind(this),'onComplete':function(){this.box.removeClass('remooz-box-dragging')}.bind(this)});this.drag.detach();this.fireEvent('onBuild',this.box,this.element);this.box.inject(this.element.getDocument().body)}});ReMooz.factory=function(extended){return $extend(this,extended)};ReMooz.factory(new Options).factory({options:{zIndex:41,zIndexFocus:42,query:'a.remooz',modal:false},assign:function(elements,options){return $$(elements).map(function(element){return new ReMooz(element,options)},this)},stack:[],open:function(obj){var last=this.stack.getLast();this.focus(obj);if(last&&this.options.modal)last.close()},close:function(obj){var length=this.stack.length-1;if(length>1&&this.stack[length]==obj)this.focus(this.stack[length-1]);this.stack.erase(obj)},focus:function(obj){var last=this.stack.getLast();obj.fireEvent('onFocus',[obj]);if(last==obj)return;if(last)last.fireEvent('onBlur',[last]);this.stack.erase(obj).push(obj)}});
Banners=new Class({Implements:[Chain,Events,Options],options:{center:true,classes:[],delay:2000,duration:750,fast:false,height:false,href:'',hu:'',linked:false,loop:true,match:/\?slide=(\d+)$/,overlap:true,paused:false,random:false,replace:[/(\.[^\.]+)$/,'t$1'],resize:'width',slide:0,transition:function(p){return-(Math.cos(Math.PI*p)-1)/2},width:false},initialize:function(el,data,options){this.setOptions(options);this.slideshow=$(el);if(!this.slideshow)return;this.slideshow.set('styles',{'display':'block','position':'relative','z-index':0});var match=window.location.href.match(this.options.match);this.slide=(this.options.match&&match)?match[1].toInt():this.options.slide;this.counter=this.delay=this.transition=0;this.direction='left';this.paused=false;if(!this.options.overlap)this.options.duration*=2;var anchor=this.slideshow.getElement('a')||new Element('a');if(!this.options.href)this.options.href=anchor.get('href')||'';if(this.options.hu.length&&!this.options.hu.test(/\/$/))this.options.hu+='/';var keys=['slideshow','first','prev','play','pause','next','last','images','captions','controller','thumbnails','hidden','visible','inactive','active','loader'];var values=keys.map(function(key,i){return this.options.classes[i]||key},this);this.classes=values.associate(keys);this.classes.get=function(){var str='.'+this.slideshow;for(var i=0,l=arguments.length;i<l;i++)str+=('-'+this[arguments[i]]);return str}.bind(this.classes);if(!data){this.options.hu='';data={};var thumbnails=this.slideshow.getElements(this.classes.get('thumbnails')+' img');this.slideshow.getElements(this.classes.get('images')+' img').each(function(img,i){var src=img.get('src');var caption=img.get('alt')||img.get('title')||'';var href=img.getParent().get('href')||'';var thumbnail=thumbnails[i].get('src')||'';data[src]={'caption':caption,'href':href,'thumbnail':thumbnail}})}var loaded=this.load(data);if(!loaded)return;this.events=$H({'keydown':[],'keyup':[],'mousemove':[]});var keyup=function(e){switch(e.key){case'left':this.prev(e.shift);break;case'right':this.next(e.shift);break;case'p':this.pause();break}}.bind(this);this.events.keyup.push(keyup);document.addEvent('keyup',keyup);var el=this.slideshow.getElement(this.classes.get('images'));var images=(el)?el.empty():new Element('div',{'class':this.classes.get('images').substr(1)}).inject(this.slideshow);var div=images.getSize();this.height=this.options.height||div.y;this.width=this.options.width||div.x;images.set({'styles':{'display':'block','height':this.height,'overflow':'hidden','position':'relative','width':this.width}});this.slideshow.store('images',images);this.a=this.image=this.slideshow.getElement('img')||new Element('img');this.a.set('styles',{'display':'none','position':'absolute','zIndex':1});this.b=this.a.clone();[this.a,this.b].each(function(img){anchor.clone().grab(img).inject(images)});this._preload()},go:function(n,direction){if((this.slide-1+this.data.images.length)%this.data.images.length==n||$time()<this.transition)return;$clear(this.timer);this.delay=0;this.direction=(direction)?direction:((n<this.slide)?'right':'left');this.slide=n;if(this.preloader)this.preloader=this.preloader.destroy();this._preload(this.options.fast||this.paused)},first:function(){this.prev(true)},prev:function(first){var n=0;if(!first){if(this.options.random){if(this.showed.i<2)return;this.showed.i-=2;n=this.showed.array[this.showed.i]}else n=(this.slide-2+this.data.images.length)%this.data.images.length}this.go(n,'right')},pause:function(p){if($chk(p))this.paused=(p)?false:true;if(this.paused){this.paused=false;this.delay=this.transition=0;this.timer=this._preload.delay(100,this);[this.a,this.b].each(function(img){['morph','tween'].each(function(p){if(this.retrieve(p))this.get(p).resume()},img)})}else{this.paused=true;this.delay=Number.MAX_VALUE;this.transition=0;$clear(this.timer);[this.a,this.b].each(function(img){['morph','tween'].each(function(p){if(this.retrieve(p))this.get(p).pause()},img)})}},next:function(last){var n=(last)?this.data.images.length-1:this.slide;this.go(n,'left')},last:function(){this.next(true)},load:function(data){this.firstrun=true;this.showed={'array':[],'i':0};if($type(data)=='array'){this.options.captions=false;data=new Array(data.length).associate(data.map(function(image,i){return image+'?'+i}))}this.data={'images':[],'captions':[],'hrefs':[],'thumbnails':[]};for(image in data){var obj=data[image]||{};var caption=(obj.caption)?obj.caption.trim():'';var href=(obj.href)?obj.href.trim():((this.options.linked)?this.options.hu+image:this.options.href);var thumbnail=(obj.thumbnail)?obj.thumbnail.trim():image.replace(this.options.replace[0],this.options.replace[1]);this.data.images.push(image);this.data.captions.push(caption);this.data.hrefs.push(href);this.data.thumbnails.push(thumbnail)}if(this.options.thumbnails&&this.slideshow.retrieve('thumbnails'))this._thumbnails();if(this.slideshow.retrieve('images')){[this.a,this.b].each(function(img){['morph','tween'].each(function(p){if(this.retrieve(p))this.get(p).cancel()},img)});this.slide=this.transition=0;this.go(0)}return this.data.images.length},destroy:function(p){this.events.each(function(array,e){array.each(function(fn){document.removeEvent(e,fn)})});this.pause(1);if(this.options.loader)$clear(this.slideshow.retrieve('loader').retrieve('timer'));if(this.options.thumbnails)$clear(this.slideshow.retrieve('thumbnails').retrieve('timer'));this.slideshow.uid=Native.UID++;if(p)this.slideshow[p]()},_preload:function(fast){if(!this.preloader)this.preloader=new Asset.image(this.options.hu+this.data.images[this.slide],{'onload':function(){this.store('loaded',true)}});if(this.preloader.retrieve('loaded')&&$time()>this.delay&&$time()>this.transition){if(this.stopped){this.pause(1);if(this.end)this.fireEvent('end');this.stopped=this.end=false;return}this.image=(this.counter%2)?this.b:this.a;this.image.set('styles',{'display':'block','height':'auto','visibility':'hidden','width':'auto','zIndex':this.counter});['src','height','width'].each(function(prop){this.image.set(prop,this.preloader.get(prop))},this);this._resize(this.image);this._center(this.image);var anchor=this.image.getParent();if(this.data.hrefs[this.slide])anchor.set('href',this.data.hrefs[this.slide]);else anchor.erase('href');anchor.erase('title');if(this.options.loader)this.slideshow.retrieve('loader').fireEvent('hide');if(this.options.thumbnails)this.slideshow.retrieve('thumbnails').fireEvent('update',fast);this._show(fast);this._loaded()}else{if($time()>this.delay&&this.options.loader)this.slideshow.retrieve('loader').fireEvent('show');this.timer=(this.paused&&this.preloader.retrieve('loaded'))?null:this._preload.delay(100,this,fast)}},_show:function(fast){if(!this.image.retrieve('morph')){var options=(this.options.overlap)?{'duration':this.options.duration,'link':'cancel'}:{'duration':this.options.duration/2,'link':'chain'};$$(this.a,this.b).set('morph',$merge(options,{'onStart':this._start.bind(this),'onComplete':this._complete.bind(this),'transition':this.options.transition}))}var hidden=this.classes.get('images',((this.direction=='left')?'next':'prev'));var visible=this.classes.get('images','visible');var img=(this.counter%2)?this.a:this.b;if(fast){img.get('morph').cancel().set(hidden);this.image.get('morph').cancel().set(visible)}else{if(this.options.overlap){img.get('morph').set(visible);this.image.get('morph').set(hidden).start(visible)}else{var fn=function(hidden,visible){this.image.get('morph').set(hidden).start(visible)}.pass([hidden,visible],this);hidden=this.classes.get('images',((this.direction=='left')?'prev':'next'));img.get('morph').set(visible).start(hidden).chain(fn)}}},_loaded:function(){this.counter++;this.delay=(this.paused)?Number.MAX_VALUE:$time()+this.options.duration+this.options.delay;this.direction='left';this.transition=(this.paused||this.options.fast)?0:$time()+this.options.duration;if(this.slide+1==this.data.images.length&&!this.options.loop&&!this.options.random)this.stopped=this.end=true;if(this.options.random){this.showed.i++;if(this.showed.i>=this.showed.array.length){var n=this.slide;if(this.showed.array.getLast()!=n)this.showed.array.push(n);while(this.slide==n)this.slide=$random(0,this.data.images.length-1)}else this.slide=this.showed.array[this.showed.i]}else this.slide=(this.slide+1)%this.data.images.length;if(this.preloader)this.preloader=this.preloader.destroy();this._preload()},_center:function(img){if(this.options.center){var size=img.getSize();img.set('styles',{'left':(size.x-this.width)/-2,'top':(size.y-this.height)/-2})}},_resize:function(img){if(this.options.resize){var h=this.preloader.get('height'),w=this.preloader.get('width');var dh=this.height/h,dw=this.width/w,d;if(this.options.resize=='length')d=(dh>dw)?dw:dh;else d=(dh>dw)?dh:dw;img.set('styles',{height:Math.ceil(h*d),width:Math.ceil(w*d)})}},_start:function(){this.fireEvent('start')},_complete:function(){if(this.firstrun&&this.options.paused){this.firstrun=false;this.pause(1)}this.fireEvent('complete')}});
var SlideItMoo=new Class({Implements:[Options],options:{overallContainer:null,elementScrolled:null,thumbsContainer:null,itemsVisible:5,itemsSelector:null,itemWidth:null,showControls:1,transition:Fx.Transitions.linear,duration:800,direction:1,autoSlide:false,mouseWheelNav:false},initialize:function(options){this.setOptions(options);this.elements=$(this.options.thumbsContainer).getElements(this.options.itemsSelector);this.totalElements=this.elements.length;if(this.totalElements<=this.options.itemsVisible)return;this.elementWidth=this.options.itemWidth||this.elements[0].getSize().x;this.currentElement=0;this.direction=this.options.direction;this.autoSlideTotal=this.options.autoSlide+this.options.duration;this.begin()},begin:function(){this.setContainersSize();this.myFx=new Fx.Morph(this.options.thumbsContainer,{wait:true,transition:this.options.transition,duration:this.options.duration});this.addControls();if(this.options.mouseWheelNav&&!this.options.autoSlide){$(this.options.thumbsContainer).addEvent('mousewheel',function(ev){new Event(ev).stop();this.slide(-ev.wheel)}.bind(this))}if(this.options.autoSlide)this.startAutoSlide()},setContainersSize:function(){$(this.options.overallContainer).set({styles:{'width':this.options.itemsVisible*this.elementWidth+50*this.options.showControls}});$(this.options.elementScrolled).set({styles:{'width':this.options.itemsVisible*this.elementWidth}});$(this.options.thumbsContainer).set({styles:{'width':this.totalElements*(this.elementWidth+10)}})},addControls:function(){if(!this.options.showControls)return;this.fwd=new Element('div',{'class':'SlideItMoo_forward'});this.bkwd=new Element('div',{'class':'SlideItMoo_back'});$(this.options.overallContainer).adopt(this.fwd,this.bkwd);this.fwd.addEvent('click',this.slide.bind(this).pass(1));this.bkwd.addEvent('click',this.slide.bind(this).pass(-1))},slide:function(direction){if(this.started)return;this.direction=direction;var currentIndex=this.currentIndex();if(this.direction==-1){this.rearange();$(this.options.thumbsContainer).setStyle('margin-left',-this.elementWidth)}this.started=true;this.myFx.start({'margin-left':this.direction==1?-this.elementWidth:0}).chain(this.rearange.bind(this).pass(true))},rearange:function(rerun){if(rerun)this.started=false;if(rerun&&this.direction==-1){return}this.currentElement=this.currentIndex(this.direction);$(this.options.thumbsContainer).setStyle('margin-left',0);if(this.currentElement==1&&this.direction==1){this.elements[0].injectAfter(this.elements[this.totalElements-1]);return}if((this.currentElement==0&&this.direction==1)||(this.direction==-1&&this.currentElement==this.totalElements-1)){this.rearrangeElement(this.elements.getLast(),this.direction==1?this.elements[this.totalElements-2]:this.elements[0]);return}if(this.direction==1){this.rearrangeElement(this.elements[this.currentElement-1],this.elements[this.currentElement-2])}else{this.rearrangeElement(this.elements[this.currentElement],this.elements[this.currentElement+1])}},rearrangeElement:function(element,indicator){this.direction==1?element.injectAfter(indicator):element.injectBefore(indicator)},currentIndex:function(){var elemIndex=null;switch(this.direction){case 1:elemIndex=this.currentElement>=this.totalElements-1?0:this.currentElement+this.direction;break;case-1:elemIndex=this.currentElement==0?this.totalElements-1:this.currentElement+this.direction;break}return elemIndex},startAutoSlide:function(){this.startIt=this.slide.bind(this).pass(this.direction||1);this.autoSlide=this.startIt.periodical(this.autoSlideTotal,this);this.elements.addEvents({'mouseover':function(){$clear(this.autoSlide)}.bind(this),'mouseout':function(){this.autoSlide=this.startIt.periodical(this.autoSlideTotal,this)}.bind(this)})}})
