
	/*****************************************************************
	 *
	 * JS_BRAMUS - by Bramus! - http://www.bram.us/
	 *
	 * Horizontal Image Scroller (his) 1.1
	 *
	 * v 1.1 - added on/off support
	 * v 1.0 - initial release
	 *
	 * only comment so far (no time yet) is Exodus 20.15 (Google it!)
	 *
	 *****************************************************************/
	 
	if (!JS_BRAMUS) { var JS_BRAMUS = new Object(); }

	JS_BRAMUS.his = {
		container		: null,
		amount			: 1,
		interval		: 50,
		imagesOnArray	: null,
		imageOffArray	: null,
		linksArray		: null,
		imagePath		: null,

		imagesOn		: null,
		imagesOff		: null,
		counter			: 0,
		timer			: null,
		loaded			: false,
		somo			: true,

		init			: function(el, amount, interval, imagePath, imagesOffArray, imagesOnArray, linksArray, somo) {
			// get container
			this.container	= document.getElementById(el);

			// copy some vars
			this.amount			= amount;
			this.interval		= interval;
			this.imagePath		= imagePath;
			this.imagesOnArray	= imagesOnArray;
			this.imagesOffArray	= imagesOffArray;
			this.linksArray		= linksArray;
			this.somo			= somo;

			// init this.images
			this.imagesOn	= new Array();
			this.imagesOff	= new Array();

			// preload all on images
			for (i = 0; i < imagesOnArray.length; i++) {
				this.imagesOn[i]		= new Image();
				this.imagesOn[i].src	= imagePath + imagesOnArray[i];
			}

			// preload all off images
			for (i = 0; i < imagesOffArray.length; i++) {
				this.imagesOff[i]		= new Image();
				this.imagesOff[i].src	= imagePath + imagesOffArray[i];
			}

			// call waitForLoadingComplete
			this.waitForLoadingComplete();
		},

		waitForLoadingComplete	: function() {

			if (this.loaded	== false) {

				for (i = 0; i < this.imagesOn.length; i++) {
					if (!this.imagesOn[i].complete) {
						// an image is not loaded, check again within 100 ms
						that	= this;
						setTimeout( function() { that.waitForLoadingComplete() }, 1000);
						return;
					}
				}

				for (i = 0; i < this.imagesOff.length; i++) {
					if (!this.imagesOff[i].complete) {
						// an image is not loaded, check again within 100 ms
						that	= this;
						setTimeout( function() { that.waitForLoadingComplete() }, 1000);
						return;
					}
				}

				// set loaded to true
				this.loaded	= true;

				// all images are loaded, now populate the container
				this.populate();
			}
		},

		populate		: function() {
			// clear the spinner image
			this.container.innerHTML	= "";
			this.container.scrollLeft	= 0;

			// add all images (with links of course)
			for (i = 0; i < this.imagesOn.length; i++) {
				var toAdd	= "<a href=\"" + this.linksArray[i] + "\" title=\"\" onmouseover=\"javascript:JS_BRAMUS.his.swapMe('on','" + i + "', this)\" onmouseout=\"javascript:JS_BRAMUS.his.swapMe('off','" + i + "', this)\"><img src=\"" + this.imagePath + this.imagesOffArray[i] + "\" alt=\"\" title=\"\" /></a>";
				this.container.innerHTML	+= toAdd;
			}
			// and now finally start, with an interval of course
			that		= this;
			this.timer	= setInterval(function() { that.scrollIt(); }, this.interval);

			// hook the somo if needed
			if (this.somo == true) {
				that	= this;

				this.container.onmouseover	= function() {
					clearInterval(that.timer);
				}

				this.container.onmouseout	= function() {
					that.timer	= setInterval(function() { that.scrollIt(); }, that.interval);
				}
			}

		},

		scrollIt		: function() {
			// scroll it a bit
			this.container.scrollLeft += this.amount;

			// check if first image "get out of sight"
			if(this.container.scrollLeft > (this.container.firstChild.firstChild.width) + 1) {
				this.container.removeChild(this.container.firstChild);			// now delete it
				this.container.scrollLeft	= 0;								// reset scrollLeft to 0
				var toAdd = "<a href=\"" + this.linksArray[this.counter] + "\" title=\"\" onmouseover=\"javascript:JS_BRAMUS.his.swapMe('on','" + this.counter + "', this)\" onmouseout=\"javascript:JS_BRAMUS.his.swapMe('off','" + this.counter + "', this)\"><img src=\"" + this.imagePath + this.imagesOffArray[this.counter] + "\" alt=\"\" title=\"\" /></a>";
				this.container.innerHTML	+= toAdd;							// add the just deleted item to the back of the container
				this.counter++;													// counter++ to keep track of which image we just bummed out
				if(this.counter >= this.imagesOn.length) { this.counter = 0; }	// reset counter to zero if needed
			}
		},

		swapMe			: function(what, id, that) {

			if (what == "on") {
				image	= this.imagesOnArray[id];
			} else {
				image	= this.imagesOffArray[id];
			}

			that.firstChild.src = this.imagePath + image;

		}

	}