var Envy = {

	Scroller : {
		moving : true,
		currentScroll : 0,
		increment : 1,		
		speed : 50,
		direction : "left",
		scroll: function() {
			if( this.moving == 1 ) {
				var beforeScroll = this.scroller.scrollLeft;
				if (this.direction == "right"){
					this.scroller.scrollLeft -= this.increment;
					var afterScroll = this.scroller.scrollLeft;
					newvalue = this.scroller.scrollLeft/(this.scroller.scrollWidth-this.scroller.clientWidth);
					if (this.currentScroll != newvalue) {
						this.currentScroll = newvalue;
					}
					if(this.scroller.scrollLeft == 0 ) {
						this.direction="left";
					}
				}
				else {
					var beforeScroll = this.scroller.scrollLeft;
					this.scroller.scrollLeft += this.increment;
					var afterScroll = this.scroller.scrollLeft;
					newvalue = this.scroller.scrollLeft/(this.scroller.scrollWidth-this.scroller.clientWidth);
					if (this.currentScroll!= newvalue) {
						this.currentScroll = newvalue;
					}
					if( beforeScroll == afterScroll ) {
						this.direction="right";
					}
				}
			}
		},

		start : function() {
			this.moving = 1;
		},

		stop : function() {
			this.moving = 0;
		},

		init : function(scrollerId) {
			this.scroller = document.getElementById(scrollerId);	
			if ((this.scroller == undefined)) {
				return false;
			}
			else {return true}
		}
	},

}

window.onload = function() { 
	if (Envy.Scroller.init('scroller_container')) {
		setInterval("Envy.Scroller.scroll();", Envy.Scroller.speed);
	}
}



