Proto.UI.InfinityCarousel=Class.create({
        initialize: function() 
        {
                      
        	this.options = Object.extend({
        	
                buttonLeftClassName:'br',
                buttonRightClassName:'bl',
                container:false,
                scollerClassName:false,
                element:false,
                blur:0.8,
                duration:0.3
                 
                }, arguments[0] || { });
                this.action=false;
                this.container = this.options.container;
                if(typeof this.container != "object"){ throw ("Container not found "); }
               this.element = this.options.element;
                if(typeof this.element != "object" ){ throw ("element not found "); }
                
               this.scoller = this.container.select('.'+this.options.scollerClassName+'')[0];
               
                if(typeof this.scoller != "object"){ throw ("scoller not found "); }
                this.bL = this.container.select('.'+this.options.buttonLeftClassName+'')[0]; 
                this.bR = this.container.select('.'+this.options.buttonRightClassName+'')[0];
               if(this.element.childElements().length<3)
                {
				this.bL.hide();
				this.bR.hide();
				return;	                
                }
                if(typeof this.bL != "object"){ throw ("bL not found "); }
                if(typeof this.bR != "object"){ throw ("bR not found "); }
                
               this.bL.observe("mousedown",this.toleft.bind(this)); 
               this.bR.observe("mousedown",this.toright.bind(this)); 
               this.scoller.style.overflow='hidden';
               this.fixScroll();     
                 
               this.stopPe=false;
               this.container.observe("mouseover",function(){  this.stopPe=true; }.bind(this));
               this.scoller.observe("mouseover",function(){  this.stopPe=true; }.bind(this));
               
               this.toright();
               /*
               (function(){
               new PeriodicalExecuter(function(pe) {
                    if (this.stopPe){ pe.stop(); }
                    else{
                    this.toleft(); 
                    }
                    }.bind(this), 2);  
               }.bind(this)).delay(3)
                 */
          },
          fixScroll:function(){
          this.container.style.overflow='hidden';
          this.container.style.position='relative';
          this.scoller.style.overflow='hidden';
          this.scoller.style.position='relative';
          this.scoller.scrollLeft = this.elWidth = this.element.firstDescendant().getWidth();
           	
          },
          blur:function(){
          this.scoller.style.opacity=this.options.blur;
          this.scoller.style.filter='Alpha(opacity='+(this.options.blur*100)+')';
          },
          unblur:function(){
          this.scoller.style.opacity='1';
          this.scoller.style.filter='Alpha(opacity=100)';         
          },
          toleft: function(e){
          try{Event.stop(e);}catch(x){}
          if(this.action){return;}
          this.blur();
          this.action=true;
          var lst=this.element.firstDescendant();
          
          var newEl = new Element(lst.tagName,{'class':lst.className});
          this.element.insert(newEl);
          newEl.update(lst.innerHTML);
          
          new Effect.Morph(this.element.firstDescendant(),{style:'width:0px;padding:0px;',fps:100, duration:this.options.duration,afterFinish :function(){this.element.firstDescendant().remove();this.action=false;this.unblur();}.bind(this)});
          
          
          },
          toright:function(e){
          if(e){Event.stop(e);}
          if(this.action){return;}
          
          this.blur();
          this.fixScroll();
          this.action=true;
          var lst;
          this.element.childElements().each(function(e){
          lst = e;
          }.bind(this));
          var newEl = new Element(lst.tagName,{'class':lst.className,'style':'display:none',id:lst.id,title:lst.title});
          this.element.insertBefore(newEl,this.element.firstDescendant());
          
          newEl.update(lst.innerHTML);
          try{newEl.onclick= lst.onclick;}catch(x){}
          var padL = newEl.getStyle('padding-left');
          var padR = newEl.getStyle('padding-right');
          newEl.style.paddingLeft = newEl.style.paddingRight =  newEl.style.width ="0px";
          newEl.show();
          new Effect.Morph(newEl,{style:'width:'+this.elWidth+'px;padding-left:'+padL+'px;padding-right:'+padR+'px;',fps:100,duration:this.options.duration,afterFinish :function(){
          newEl.style.paddingLeft = newEl.style.paddingRight =  newEl.style.width = "";this.unblur();
          
          lst.remove();
          this.action=false;
          }.bind(this)});
          
          
          
          }
          
          });