

Scrollable = Class.create();
Object.extend(Scrollable.prototype, {
	  initialize: function(element,options) {
		this.element = $(element);
		this.position=0;
		this.rightSlidePE=null;
		this.downSlidePE=null;
		
		
		var orig_style = {	
							overflow:this.element.getStyle("overflow"),
							height:this.element.getStyle("height")
						 };
		this.element.setStyle({overflow:"",height:""});
		
		this.full_height=this.element.getDimensions().height;							
		this.element.setStyle(orig_style);
		
		this.options = Object.extend({
			speed:0.02
			
		}, arguments[1] || {});

	  },
	  startUp: function(porps){
		this.notify("startUp");
		this.stopDown();
		this.rightSlidePE=new PeriodicalExecuter(function(pe) {
			this.element.scrollTop-=4;

			if(this.element.offsetHeight<this.full_height){
				if(this.element.scrollTop>0){
					this.notify("scrollingUp");
					
				}else{
					this.notify("endScrollingUp");
					this.stopUp();
				}
			}
		}.bind(this), this.options.speed);
	  },
	  stopUp: function(){
		this.notify("stopRight");
		if(this.rightSlidePE!=null) this.rightSlidePE.stop();
	  },
	  startDown: function(props){
		 
		
		this.notify("startDown");
		this.stopUp();
		
		this.downSlidePE=new PeriodicalExecuter(function(pe) {
			this.element.scrollTop+=4;
			
			if(this.element.offsetHeight<this.full_height){
				
				if(this.full_height-this.element.offsetHeight>this.element.scrollTop){
					this.notify("scrollingDown");
					
				}else{
					this.notify("endScrollingDown");
					this.stopDown();
				}
				
			}
		}.bind(this), this.options.speed);
	  },
	  stopDown: function(){
		this.notify("stopDown");
		if(this.downSlidePE!=null) this.downSlidePE.stop();
	  },
	  goto: function(props){
		this.element.scrollTop=props;
	  },
	  update: function(){
		this.position=0;
		this.rightSlidePE=null;
		this.downSlidePE=null;
		this.element.scrollTop=0;
		
		var orig_style = {	
							overflow:this.element.getStyle("overflow"),
							height:this.element.getStyle("height")
						 };
		this.element.setStyle({overflow:"",height:""});
		
		this.full_height=this.element.getDimensions().height;							
		this.element.setStyle(orig_style);
		
	  }
  }
 );
//this.notify("afterAdded");
Object.Event.extend(Scrollable);