/**
 * @author Dave Abdul
 */
function slideShow(id,interval,jump,pause) {
	this.id = id;
	this.interval = interval;
	this.jump = jump;
	this.pause = pause * 1000;
	this.ready = false;
	build(this);
	
	function build(obj) {
		document.getElementById(obj.id).style.position = "relative";
		document.getElementById(obj.id).style.zIndex;
		obj.images = document.getElementById(obj.id).getElementsByTagName("img");
		obj.max = obj.images.length;
		obj.track = 0;
		obj.counter = 0;
		for (var i = 0; i < obj.images.length; i++) {
			if (i != 0) {
				obj.images[i].style.opacity = obj.counter / 10;
				obj.images[i].style.filter = 'alpha(opacity=' + obj.counter * 10 + ')';
				//obj.images[i].style.zIndex = "3";	
			}
			else {
				obj.size = new Image();
				obj.size.onload = function() {
					document.getElementById(obj.id).style.height = obj.size.height + "px";
					document.getElementById(obj.id).style.width = obj.size.width + "px";
				};
				obj.size.src = obj.images[i].src;
				//obj.images[i].style.zIndex = "1";	
			}
			
			obj.images[i].style.position = "absolute";
			obj.images[i].style.left = "0px";
			obj.images[i].style.top = "0px";
			
		}
		
		obj.images[obj.track].style.display = "block";
		setTimeout(function () { hide(obj); },obj.pause);
	}
	
	function show(elm){
		bringIn(elm);
	}
	
	function hide(elm) {
		bringOut(elm);
	}
	
	function bringIn(obj) {
		obj.animation = window.setInterval( function() {
			obj.images[obj.track].style.opacity = obj.counter/10;
			obj.images[obj.track].style.filter = 'alpha(opacity=' + obj.counter*10 + ')';
			obj.counter = parseFloat(Number(obj.counter + obj.jump).toPrecision(2));
			if (obj.counter >= 10) {
				clearInterval(obj.animation);
				if (!obj.ready) obj.ready = true;
				obj.images[obj.track].style.opacity = 10/10;
				obj.images[obj.track].style.filter = 'alpha(opacity=' + 10*10 + ')';
				if (obj.track == 0) {
					obj.images[obj.max-1].style.display = "none";
					obj.images[obj.max-1].style.opacity = 0 / 10;
					obj.images[obj.max-1].style.filter = 'alpha(opacity=' + 0 * 10 + ')';
				}
				else {
					obj.images[obj.track-1].style.display = "none";
					obj.images[obj.track-1].style.opacity = 0 / 10;
					obj.images[obj.track-1].style.filter = 'alpha(opacity=' + 0 * 10 + ')';
				}
				obj.animation = false;
				setTimeout(function () { hide(obj); },obj.pause);
			}
		},obj.interval);
	}
	
	function bringOut(obj) {
		obj.images[obj.track].style.zIndex = "2";	
		obj.track++;
		if (obj.track == obj.max) { obj.track = 0; }	
		obj.images[obj.track].style.display = "block";
		obj.images[obj.track].style.zIndex = "3";
		obj.counter = 0;
		show(obj);
	}
	
}
