if(!Array.prototype.indexOf){Array.prototype.indexOf=function(b){var a=this.length;var c=Number(arguments[1])||0;c=(c<0)?Math.ceil(c):Math.floor(c);if(c<0){c+=a}for(;c<a;c++){if(c in this&&this[c]===b){return c}}return -1}}var MoveDirection={Unknown:0,Vertical:1,Horizontal:2};var LSCarousel=Class.create({initialize:function(e,b,d,g,c,f){var a;this._carouselContainer=$(e);if(this._carouselContainer){this._loadCarouselItems(b||"div");if(this._scrollingElementPointers&&this._scrollingElementPointers[0]){this._numberShowing=g||1;if(this._scrollingElementPointers.length>g){this._currentIndex=0;this._trailingSize=(c!=null)?c:10;this._effectDuration=(f!=null)?f:3;this._moveBy=d||this._scrollingElementPointers[0].width||this._scrollingElementPointers[0].style.width||0;this._isMoving=false;this.lastOperation={direction:MoveDirection.Unknown,step:0}}else{a="The number of carousel items must be greater than the number of items shown."}}else{a="One or more carousel items not found or invalid."}}else{a="Carousel container not found or invalid."}if(a){alert(a)}},_loadCarouselItems:function(a){this._scrollingElementPointers=[];for(var b=0;b<this._carouselContainer.childNodes.length;b++){if(this._carouselContainer.childNodes[b].nodeName.toLowerCase()==a.toLowerCase()){this._scrollingElementPointers.push(this._carouselContainer.childNodes[b])}}},_move:function(c){if(this._scrollingElementPointers&&this._moveBy>0&&!this._isMoving){this._regroupItems(c.step);this._isMoving=true;var b=moveY=trailX=trailY=0;switch(c.direction){case MoveDirection.Vertical:moveY=(this._moveBy*c.step)+(this._trailingSize*c.step);trailY=-1*(this._trailingSize*c.step);break;case MoveDirection.Horizontal:b=(this._moveBy*c.step)+(this._trailingSize*c.step);trailX=-1*(this._trailingSize*c.step);break}function a(f,e){function d(i){var h=new Effect.Move(i._carouselContainer,{duration:i._effectDuration,x:b,y:moveY});function g(j){setTimeout(function(){j._isMoving=false},h.options.duration*1000)}g(i)}setTimeout(function(){d(f)},e.options.duration*1000)}a(this,new Effect.Move(this._carouselContainer,{x:trailX,y:trailY,duration:0.25}));this.lastOperation=c}},_regroupItems:function(c){var b=false;if(c<0){if(this._currentIndex==0){this._resetToOriginalSequence()}if(this._currentIndex-c+this._numberShowing>this._scrollingElementPointers.length){this._currentIndex=(this._currentIndex-c>this._scrollingElementPointers.length-1)?0:this._currentIndex-c;b=true;if(this._currentIndex==0&&this.lastOperation.step==c){this._resetToOriginalSequence(true)}else{if(this.lastOperation.step==c){var a=0;while(a>c){this._carouselContainer.appendChild(this._getFirstScrollingElement());this._currentIndex--;a--}switch(this.lastOperation.direction){case MoveDirection.Vertical:this._carouselContainer.setStyle({top:(this._moveBy+parseFloat(this._carouselContainer.getStyle("top")||0)).round()+"px"});break;case MoveDirection.Horizontal:this._carouselContainer.setStyle({left:(this._moveBy+parseFloat(this._carouselContainer.getStyle("left")||0)).round()+"px"});break}}}}}else{if(c>0){this._currentIndex=(this._currentIndex-c<0)?this._scrollingElementPointers.length-1:this._currentIndex-c;b=true;if(this._currentIndex==this._scrollingElementPointers.length-1&&this.lastOperation.step!=0&&this.lastOperation.step!=c){this._resetToOriginalSequence(true,true)}else{if(this.lastOperation.step==c||this.lastOperation.step==0){var a=0;while(a<c){this._carouselContainer.insertBefore(this._getLastScrollingElement(),this._getFirstScrollingElement());this._currentIndex++;a++}switch(this.lastOperation.direction){case MoveDirection.Vertical:this._carouselContainer.setStyle({top:(-1*this._moveBy)+parseFloat(this._carouselContainer.getStyle("top")||0)+"px"});break;case MoveDirection.Horizontal:this._carouselContainer.setStyle({left:(-1*this._moveBy)+parseFloat(this._carouselContainer.getStyle("left")||0)+"px"});break}}}}}if(!b){this._currentIndex-=c}},_getFirstScrollingElement:function(){for(var a=0;a<this._carouselContainer.childNodes.length;a++){if(this._scrollingElementPointers.indexOf(this._carouselContainer.childNodes[a])>=0){return this._carouselContainer.childNodes[a]}}return null},_getLastScrollingElement:function(){for(var a=this._carouselContainer.childNodes.length-1;a>=0;a--){if(this._scrollingElementPointers.indexOf(this._carouselContainer.childNodes[a])>=0){return this._carouselContainer.childNodes[a]}}return null},_resetToOriginalSequence:function(c,b){var d=(c)?this._scrollingElementPointers.length-1:this._scrollingElementPointers.length;for(var a=0;a<d;a++){this._carouselContainer.appendChild(this._scrollingElementPointers[a])}var f=0,e=0;switch(this.lastOperation.direction){case MoveDirection.Vertical:this._carouselContainer.setStyle({top:(b)?(-1*this._moveBy)+"px":"0px"});break;case MoveDirection.Horizontal:this._carouselContainer.setStyle({left:(b)?(-1*this._moveBy)+"px":"0px"});break}},moveLeft:function(a){if(a&&a>3){alert("Moving by more then 3 steps is currently not supported.")}else{this.lastOperation.direction=MoveDirection.Horizontal;this._move({direction:MoveDirection.Horizontal,step:-1*(a||1)})}},moveRight:function(a){if(a&&a>3){alert("Moving by more then 3 steps is currently not supported.")}else{this.lastOperation.direction=MoveDirection.Horizontal;this._move({direction:MoveDirection.Horizontal,step:a||1})}},moveUp:function(a){if(a&&a>3){alert("Moving by more then 3 steps is currently not supported.")}else{this.lastOperation.direction=MoveDirection.Vertical;this._move({direction:MoveDirection.Vertical,step:-1*(a||1)})}},moveDown:function(a){if(a&&a>3){alert("Moving by more then 3 steps is currently not supported.")}else{this.lastOperation.direction=MoveDirection.Vertical;this._move({direction:MoveDirection.Vertical,step:a||1})}}});