// gives up and down scroll buttons to images, spans, ... named left_name, right_name, respectively.
// will keep the default scroll_box's style overflow if it encounters errors (so make overflow: auto;)

// usage: put this after the scrollbox div:  var div_scroll1 = new TextScroll('div_scroll1', 'scroll_box');
function TextScroll(scrollname, div_name, left_name, right_name) {
    this.div_name = div_name;
    this.name = scrollname;
    this.scrollCursor = 0;
    this.speed = 5;
    this.timeoutID = null;
    this.div_obj = null;
    this.left_name = left_name;
    this.dn_name = right_name;

	this.stopScroll = function() {
			var obj = this.scroller;
			if(obj.timeoutID) {
        		clearTimeout(obj.timeoutID);
				obj.timeoutID = null;
			}
    	}

	this.scrollLeft = function() {
			var obj = this.scroller;
			if (obj.div_obj) {
				obj.scrollCursor = (obj.scrollCursor - obj.speed) < 0 ? 0 : obj.scrollCursor - obj.speed;
				obj.div_obj.scrollLeft = obj.scrollCursor;
				obj.timeoutID = setTimeout("document.getElementById('"+this.id+"').onmouseover()", 60);
			}
    	}

	this.scrollRight = function() {
			var obj = this.scroller;
			if (obj.div_obj) {
				obj.scrollCursor += obj.speed;
				obj.div_obj.scrollLeft = obj.scrollCursor;
				obj.timeoutID = setTimeout("document.getElementById('"+this.id+"').onmouseover()", 60);
			}
	    }

	this.scrollUp = function() {
			if (this.div_obj) {
				this.scrollCursor = (this.scrollCursor - this.speed) < 0 ? 0 : this.scrollCursor - this.speed;
				this.div_obj.scrollTop = this.scrollCursor;
				this.timeoutID = setTimeout(this.name + ".scrollUp()", 60);
			}
		}

	this.scrollDown = function() {
			if (this.div_obj) {
				this.scrollCursor += this.speed;
				this.div_obj.scrollTop = this.scrollCursor;
				this.timeoutID = setTimeout(this.name + ".scrollDown()", 60);
			}
		}

	this.resetScroll = function() {
			if (this.div_obj) {
				this.div_obj.scrollTop = 0;
				this.scrollCursor = 0;
			}
		}

	if (document.getElementById) {

		div_obj = document.getElementById(this.div_name);
		if (div_obj) {
			this.div_obj = div_obj;
			this.div_obj.style.overflow = 'hidden';
		}
		div_up_obj = document.getElementById(this.left_name);
		div_dn_obj = document.getElementById(this.dn_name);
		if (div_up_obj && div_dn_obj) {

			div_up_obj.onmouseover = this.scrollLeft;
			div_up_obj.onmouseout = this.stopScroll;
			div_up_obj.scroller = this;

			div_dn_obj.onmouseover = this.scrollRight;
			div_dn_obj.onmouseout = this.stopScroll;
			div_dn_obj.scroller = this;

		}
	}
}

function ChangeImage(ImageId2Change,ImageId){
	var IdImageToChange = ImageId2Change;
	var NewImage = ImageId;

	document.getElementById(IdImageToChange).src = NewImage;
}
