//Written by Nathan Faubion: http://n-son.com
//Use this or edit how you want, just give me
//some credit!

function jsScroller (o, w, h) {
	var self = this;
	var list = o.getElementsByTagName("div");
	for (var i = 0; i < list.length; i++) {
		if (list[i].className.indexOf("Container") > -1) {
			o = list[i];
		}
	}
	
	//Private methods
	this._setPos = function (t, u) {
		if (t < this.viewableWidth - this.totalWidth) 
			t = this.viewableWidth - this.totalWidth;
		if (t > 0) t = 0;
		if (u < this.viewableHeight - this.totalHeight) 
			u = this.viewableHeight - this.totalHeight;
		if (u > 0) u = 0;
		this._t = t;
		this._u = u;
		with (o.style) {
			left = this._t +"px";
			top  = this._u +"px";
		}
	};
	
	//Public Methods
	this.reset = function () {
		this.content = o;
		this.totalHeight = o.offsetHeight;
		this.totalWidth	 = o.offsetWidth;
		this._t = 0;
		this._u = 0;
		with (o.style) {
			left = "0px";
			top  = "0px";
		}
	};
	this.scrollBy = function (t, u) {
		this._setPos(this._t + t, this._u + u);
	};
	this.scrollTo = function (t, u) {
		this._setPos(-t, -u);
	};
	this.stopScroll = function () {
		if (this.scrollTimer) window.clearInterval(this.scrollTimer);
	};
	this.startScroll = function (t, u) {
		this.stopScroll();
		this.scrollTimer = window.setInterval(
			function(){ self.scrollBy(t, u); }, 40
		);
	};
	this.swapContent = function (c, w, h) {
		o = c;
		var list = o.getElementsByTagName("div");
		for (var i = 0; i < list.length; i++) {
			if (list[i].className.indexOf("Container") > -1) {
				o = list[i];
			}
		}
		if (w) this.viewableWidth  = w;
		if (h) this.viewableHeight = h;
		this.reset();
	};
	
	//variables
	this.content = o;
	this.viewableWidth  = w;
	this.viewableHeight = h;
	this.totalWidth	 = o.offsetWidth;
	this.totalHeight = o.offsetHeight;
	this.scrollTimer = null;
	this.reset();
};
