var Y={anim:YAHOO.util.Anim,easing:YAHOO.util.Easing,dom:YAHOO.util.Dom,getByClass:YAHOO.util.Dom.getElementsByClassName,event:YAHOO.util.Event},Y3=YUI(),Gallery;Y.event.on(window,"load",function(){Y.dom.batch(document.getElementsByTagName("a"),function(a){if(Y.dom.getAttribute(a,"rel")=="new"){Y.event.on(a,"click",function(b){window.open(this.href,"newwin");Y.event.stopEvent(b)})}});Y.dom.batch(Y.getByClass("gallery","div"),function(a){new Gallery(a)})});Gallery=function(a){this.SHOWN_CLASS="shown";this.COUNT_CLASS="count";this.PREV_CLASS="prev";this.NEXT_CLASS="next";this.COUNT_DELIM="/";this.DURATION=1;this.EASE=Y.easing.easeOut;this.DELAY=3;this.gallery=Y.dom.get(a);if(!this.gallery){return}this.counts=Y.getByClass(this.COUNT_CLASS,"*",this.gallery);this.images=this.gallery.getElementsByTagName("img");this.currIndex=0;for(var b=0;b<this.images.length;b++){if(Y.dom.hasClass(this.images[b],this.SHOWN_CLASS)){this.currIndex=b;break}}this.updateCount();Y.event.on(Y.getByClass(this.PREV_CLASS,"a",this.gallery),"click",this.onClickPrev,this,true);Y.event.on(Y.getByClass(this.NEXT_CLASS,"a",this.gallery),"click",this.onClickNext,this,true);this.startAutoplay()};Gallery.prototype={onClickPrev:function(a){if(!this.isAnimating){this.cancelAutoplay();this.showImage((this.currIndex<=0)?(this.images.length-1):(this.currIndex-1))}Y.event.stopEvent(a)},onClickNext:function(a){if(!this.isAnimating){this.cancelAutoplay();this.showImage((this.currIndex>=(this.images.length-1))?0:(this.currIndex+1))}Y.event.stopEvent(a)},startAutoplay:function(){if(!this.autoplay){this.autoplay=true;this.interval=Y3.later(this.DELAY*1000,this,this.autoplayHandler,null,true)}},cancelAutoplay:function(){if(this.autoplay){this.autoplay=false;this.interval.cancel()}},autoplayHandler:function(){if(this.autoplay){this.showImage(((this.currIndex+1)<this.images.length)?this.currIndex+1:0)}},showImage:function(b){if(b==this.currIndex){return}var a=new Y.anim(null,null,this.DURATION);a.onTween.subscribe(function(c,d){Y.dom.setStyle(this.images[this.currIndex],"opacity",this.EASE(d[0].currentFrame,1,-1,this.DURATION*1000));Y.dom.setStyle(this.images[b],"opacity",this.EASE(d[0].currentFrame,0,1,this.DURATION*1000))},this,true);a.onComplete.subscribe(function(){Y.dom.removeClass(this.images[this.currIndex],this.SHOWN_CLASS);this.currIndex=b;this.updateCount();this.isAnimating=false},this,true);Y.dom.setStyle(this.images[b],"opacity",0);Y.dom.addClass(this.images[b],this.SHOWN_CLASS);this.isAnimating=true;a.animate()},updateCount:function(){Y.dom.batch(this.counts,function(a){a.innerHTML=(this.currIndex+1)+this.COUNT_DELIM+this.images.length},this,true)}};