/*Browser = {
	IE: !!(window.attachEvent && !window.opera),
	Opera: !!window.opera,
	WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
	Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
	MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
};
*/
var Scroller = function(){
	this.step=2;
	//this.is_accelerating=true;
	this.timeout=1;
	//this.framesToBrake=10;
}
Scroller.prototype.scroll = function(){
	if (typeof this.width=="undefined")
		this.width= (typeof this.obj.offsetWidth!="undefined"? this.obj.offsetWidth : (typeof this.obj.style.width!="undefined"? typeof this.obj.style.width:0));
	if(typeof this.where=="undefined"){
		return;
	}
	this.end=0;
	if(this.where=="right"){
		if(this.obj.scrollWidth>this.width)
			this.end=this.obj.scrollWidth-this.width;
	}
	if(this.where=="right" || this.where=="left"){
		this.framesToEnd=Math.abs(this.obj.scrollLeft-this.end)/this.step;
	}
	if(this.where=="right" || this.where=="left"){
		this.current=this.obj.scrollLeft;
		//this.scrolled=this.obj.scrollLeft+this.width;
		this.scroller_width=this.obj.scrollWidth;
	}
	//if(this.where=="right" || this.where=="left"){
		//this.current=this.obj.scrollLeft;
		/*
		if(this.is_accelerating){
			if (typeof this.start=="undefined")
				this.start=this.obj.scrollLeft;
		}*/
		//this.framesToEnd=Math.abs(this.obj.scrollLeft-this.end)/this.step;
		/*
		if(this.is_accelerating){
			this.framesFromStart=Math.abs(this.obj.scrollLeft-this.start)/this.step;
			if(!this.framesFromStart)
				this.framesFromStart=1;
		}*/
	//}
	/*
	if(this.framesToEnd<this.framesToBrake)
		this.is_braking=true;
	if(this.is_braking){
		this.current_step=this.step*this.framesToEnd/this.framesToBrake/10;
	}else if(this.is_accelerating){
		this.current_step=this.step*this.framesFromStart/this.framesToBrake;
		if (this.current_step>=this.step){
			this.current_step=this.step;
			this.is_accelerating=false;
		}
	*/
	/*
		this.current_step=(typeof this.current_step=="undefined"?0:this.current_step)+this.step/50;
		if (this.current_step>=this.step){
			this.current_step=this.step;
			this.is_accelerating=false;
		}
	*/
	//}else{
		this.current_step=this.step;
	//}
	
	switch(this.where){
	case "right":
		this.obj.scrollLeft=this.obj.scrollLeft+Math.ceil(this.step);
		break;
	case "left":
		this.obj.scrollLeft=this.obj.scrollLeft-this.step;
		break;
	}
	if(typeof this.indicator !="undefined"){
		if(typeof this.indicator_width=="undefined")
			this.indicator_width=this.width;
		//this.indicator.style.width=this.indicator_width*this.scrolled/this.scroller_width;
		if (this.scroller_width-this.width!=0)
			this.indicator.style.width=(this.current*100/(this.scroller_width-this.width)*this.indicator_width/100)+"px";
		else
			this.indicator.style.width=this.indicator_width+"px";
	}
	clearTimeout(this.timerID);
	
	this.is_scrolling=true;
		
	var _this = this;
	if (this.framesToEnd>0)
		this.timerID=setTimeout(function(){_this.scroll();},this.timeout); 	
};
Scroller.prototype.stop = function() {
	this.is_scrolling=false;
	//this.is_accelerating=true;
	//this.is_braking=false;
	//this.start=undefined;
	//this.current_step=0;
	clearTimeout(this.timerID);
	
}

