/************************************************************************************************
*
* DivScroller
*
* Scrolls a div vertically about once its height/horizontally about once its width,
* restarting after that.
* No clipping is done in any way. You can use a scrolling div inside another div with fixed clipping
* to emulate a news scroller.
*
*************************************************************************************************/
function _dsRun() {
	this.running = true;
	//this.step();
	//this.timeout = window.setTimeout(this.name + '.run()', this.refreshTime);
	this.timeout = window.setInterval(this.name + '.step()', this.refreshTime);
}

function _dsStop() {
	this.running = false;
	if (this.timeout) {
		//window.clearTimeout(this.timeout);
		window.clearInterval(this.timeout);
		this.timeout = false;
	}
}

function _dsPause() {
	this.stop();
}

function _dsResume() {
	this.run();
}

function _dsSetHorizontal(horizontal) {
	var running = this.running;
	if (running)
		this.stop();
	this.vertical = !horizontal;
	if (running)
		this.run();
}

function _dsStep() {
	if (this.vertical) {
		if (this.element.offsetTop <= -this.height) {
			this.element.style.top = this.height + "px";
		} else {
			this.element.style.top = (this.element.offsetTop - this.stepSize) + "px";
		}
	} else {
		if (this.element.offsetLeft <= -this.width) {
			this.element.style.left = this.width + "px";
		} else {
			this.element.style.left = (this.element.offsetLeft - this.stepSize) + "px";
		}
	}
}

/**
* DivScroller
*
* Scrolls a div vertically about once its height/horizontally about once its width,
* restarting after that.
* No clipping is done in any way. You can use a scrolling div inside another div with fixed clipping
* to emulate a news scroller.
*
* @param name	name of the variable that will hold the DivScroller instance
* @param id 	id of the div to be scrolled
*/
function DivScroller(name, id) {
	this.name = name;
	this.id = id;
	if (document.getElementById(this.id)) {
		this.element = document.getElementById(this.id);
	}	else throw "Element with id '" + this.id + "' does not exist.";
	
	this.timeout = false;
	this.refreshTime = 50;
	this.vertical = true;
	this.stepSize = 1;
	this.width = this.element.offsetWidth;
	this.height = this.element.offsetHeight;
	this.top = this.element.offsetTop;
	this.left = this.element.offsetLeft;

	this.setHorizontal = _dsSetHorizontal;
	this.step = _dsStep;
	this.run = _dsRun;
	this.pause = _dsPause;
	this.resume = _dsResume;
	this.stop = _dsStop;
	this.run();
}
/***********************************************************************************************/