/*
 *	@TITLE:	Horizontal Image Scroller
 *	@AUTHOR: Richard Conrad II
 *	@DATE: 2008-02-24
 *	@TIME: 18:36
 *	@VERSION: 3.0
 *
 *	Dependencies:
 *
 *		the ImageList array
 *
 */

var IMAGE_SCROLL_CONTAINER_WIDTH = 874;
var IMAGE_SCROLL_CONTAINER_HEIGHT = 75;
var IMAGE_WIDTH = 75;
var IMAGE_HEIGHT= 75;
var IMAGE_SPACING = 0;
var IMAGE_GALLERY_LINK = "photos.php";
var SCROLL_SPEED = 1.0;
var IMAGE_DIRECTORY = "photos/";

var ImageScroll = new Object ();

ImageScroll.timer = null;
ImageScroll.container = null;
ImageScroll.slider = null;
ImageScroll.preload = new Array ();
ImageScroll.slide_x = 0;
ImageScroll.count = 0;
ImageScroll.trigger = 0;

ImageScroll.init = function () {
	this.count = ImageList.length;
/*---DEBUG: set for debugging---*/
//	this.count = 12;
	this.trigger = ((IMAGE_WIDTH + IMAGE_SPACING)*this.count) + this.count;
	this.container = document.getElementById ("ImageScrollContainer");
	this.container.style.width = IMAGE_SCROLL_CONTAINER_WIDTH + "px";
	this.container.style.height = IMAGE_SCROLL_CONTAINER_HEIGHT + "px";
	this.container.style.overflow = "hidden";
	this.slider = document.createElement("div");
	this.slider.setAttribute("id","ImageScrollSlider");
	this.slider.onmouseover = function () { eval ("ImageScroll.pause()");};//this is for bloody ie...
	this.slider.onmouseout = function () { eval ("ImageScroll.resume()");};//this is for bloody ie...
	this.container.appendChild (this.slider);
	this.slider = document.getElementById ("ImageScrollSlider");
	this.slider.style.width = (IMAGE_SCROLL_CONTAINER_WIDTH * 4) + "px";
	this.slider.style.position = "relative";
	this.slider.style.left = "0px";
	this.slider.style.top = "0px";
	var frag = document.createDocumentFragment ();
	var anchor;
	for (var i = 0; i < this.count; i++) {
		var img = document.createElement("img");
		img.width = IMAGE_WIDTH;
		img.height = IMAGE_HEIGHT;
		img.src = IMAGE_DIRECTORY + ImageList[i];
		img.setAttribute("border","0");
		img.style.marginTop = "0px";
		img.style.marginRight = (IMAGE_SPACING + 1) + "px";
		img.style.marginBottom = "0px";
		img.style.marginLeft = "0px";
		img.style.paddingTop = "0px";
		img.style.paddingRight = "0px";
		img.style.paddingBottom = "0px";
		img.style.paddingLeft = "0px";
//		img.style.float = "left";		//----\
//		img.style.cssFloat = "left";	//------Totally screws up Safari 2.0.4
//		img.styleFloat = "left";		//----/
		img.style.display = "inline";

		this.preload[i] = img;

		anchor = document.createElement("a");
		anchor.setAttribute("href",IMAGE_GALLERY_LINK);
		anchor.appendChild(this.preload[i]);
		frag.appendChild(anchor);
	}
	var sub_slider1, sub_slider2;
	sub_slider_1 = document.createElement("div");
	sub_slider_1.appendChild(frag);
	sub_slider_2 = sub_slider_1.cloneNode(true);
	sub_slider_1.setAttribute("id","sub_slider_1");
	sub_slider_1.style.display = "inline";
	sub_slider_2.setAttribute("id","sub_slider_2");
	sub_slider_2.style.display = "inline";
	this.slider.appendChild(sub_slider_1);
	this.slider.appendChild(sub_slider_2);
	this.timer = window.setInterval ('ImageScroll.slide()', (50 / SCROLL_SPEED));
}
ImageScroll.cycle = function () {
//	var debug = document.getElementById("debug");
//	debug.innerHTML += "Left: " + this.slider.style.left +"<br />";
	this.slider = document.getElementById ("ImageScrollSlider");
	var copy = this.slider.firstChild.cloneNode(true);
	this.slider.removeChild(this.slider.firstChild);
	this.slider.style.left = "0px";
	this.slider.appendChild(copy);
	this.timer = window.setInterval('ImageScroll.slide()', (50 / SCROLL_SPEED));
}
ImageScroll.slide = function () {
	if (this.slide_x == this.trigger) {
		this.slide_x = 0;
		window.clearInterval (this.timer);
		ImageScroll.cycle ();
	}
	else {
		this.slide_x++;
		var x_pos = parseInt(this.slider.style.left) - 1;
//		this.slider.style.setProperty("left",x_pos+"px",null);
		this.slider.style.left = x_pos + "px";
		//this.slider.style.left = x_pos + "px";
	}
}
ImageScroll.pause = function () { window.clearInterval (this.timer); }
ImageScroll.resume = function () { this.timer = window.setInterval('ImageScroll.slide()', (50 / SCROLL_SPEED)); }
function speed_inc () { SCROLL_SPEED += 0.15; }
function speed_dec () { SCROLL_SPEED -= 0.15; }
