//	dkFadeShow; Friday 19th September 2008, 11.05am
//	An image slideshow with fade effect; uses CSS background image of specified container
//	Usage: 
//		var slideshow1 = new dkFadeShow("container id", background position x, background position y, images array, image delay, fade speed);

// REAL FUNCTION IS BELOW; This one is a wrapper so I can do neat stuff with topgardencentres home page slideshow
function dkFadeShow(container, offsetX, offsetY, images, urls, names, locations, delay, speed) {
	this.delayTimer = null;
	this.fadeTimer = null;

	this.currentImage = 0;
	this.currentAlpha = 10;
	this.fadeDir = 0;
	this.offsetX = offsetX;
	this.offsetY = offsetY;
	this.delay = delay;
	this.speed = speed;
	this.images = images;
	this.urls = urls;
	this.names = names;
	this.locations = locations;
	this.container = document.getElementById(container);

	dkFadeShow.prototype.dkFadeShow_Fade = dkFadeShow_Fade;

	this.container.style.background = "url(" + this.images[this.currentImage] + ") " + this.offsetX + "px " + this.offsetY + "px no-repeat";
	this.container.innerHTML = "<span><a href=\"" + this.urls[this.currentImage] + ".html\">" + this.names[this.currentImage] + "</a>" + this.locations[this.currentImage] + "</span>";
	var thisObj = this;
	this.delayTimer = setTimeout(function() { thisObj.dkFadeShow_Fade(); }, this.delay);

	function dkFadeShow_Fade() {
		clearTimeout(this.delayTimer);
		var thisObj = this;
		this.fadeTimer = setInterval(function() {
			if(thisObj.fadeDir == 0) { thisObj.currentAlpha--; } else { thisObj.currentAlpha++; }
			thisObj.container.style.opacity = thisObj.currentAlpha / 10;
			thisObj.container.style.filter = 'alpha(opacity=' + thisObj.currentAlpha * 10 + ')';

			if((thisObj.fadeDir == 0) && (thisObj.currentAlpha == 0)) {
				thisObj.fadeDir = 1;
				thisObj.currentImage++;
				if(thisObj.currentImage == thisObj.images.length) thisObj.currentImage = 0;
				thisObj.container.style.background = "url(" + thisObj.images[thisObj.currentImage] + ") " + thisObj.offsetX + "px " + thisObj.offsetY + "px no-repeat";
				thisObj.container.innerHTML = "<span><a href=\"" + thisObj.urls[thisObj.currentImage] + ".html\">" + thisObj.names[thisObj.currentImage] + "</a>" + thisObj.locations[thisObj.currentImage] + "</span>";
			}

			if((thisObj.fadeDir == 1) && (thisObj.currentAlpha == 10)) {
				thisObj.fadeDir = 0;
				clearInterval(thisObj.fadeTimer);
				thisObj.delayTimer = setTimeout(function() { thisObj.dkFadeShow_Fade(); }, thisObj.delay);
			}
		}, this.speed, this);
	}
}

function dkAdShow(urls, delay, speed) {
	this.delayTimer = null;
	this.fadeTimer = null;

	this.currentAd = 0;
	this.adHeight = 155;
	this.currentAlpha = 10;
	this.fadeDir = 0;
	this.delay = delay;
	this.speed = speed;
	this.urls = urls;
	this.container = document.getElementById("homeAd");

	dkAdShow.prototype.dkAdShow_Fade = dkAdShow_Fade;
	var bgPos = this.currentAd * this.adHeight;
	this.container.style.backgroundPosition = "0 -" + bgPos + "px";
	this.container.innerHTML = "<a href=\"" + this.urls[this.currentAd] + "\"></a>";
	var thisObj = this;
	this.delayTimer = setTimeout(function() { thisObj.dkAdShow_Fade(); }, this.delay);

	function dkAdShow_Fade() {
		clearTimeout(this.delayTimer);
		var thisObj = this;
		this.fadeTimer = setInterval(function() {
			if(thisObj.fadeDir == 0) { thisObj.currentAlpha--; } else { thisObj.currentAlpha++; }
			thisObj.container.style.opacity = thisObj.currentAlpha / 10;
			thisObj.container.style.filter = 'alpha(opacity=' + thisObj.currentAlpha * 10 + ')';

			if((thisObj.fadeDir == 0) && (thisObj.currentAlpha == 0)) {
				thisObj.fadeDir = 1;
				thisObj.currentAd++;
				if(thisObj.currentAd == thisObj.urls.length) { thisObj.currentAd = 0; }

				var bgPos = thisObj.currentAd * thisObj.adHeight;
				thisObj.container.style.backgroundPosition = "0 -" + bgPos + "px";
				thisObj.container.innerHTML = "<a href=\"" + thisObj.urls[thisObj.currentAd] + "\"></a>";
			}

			if((thisObj.fadeDir == 1) && (thisObj.currentAlpha == 10)) {
				thisObj.fadeDir = 0;
				clearInterval(thisObj.fadeTimer);
				thisObj.delayTimer = setTimeout(function() { thisObj.dkAdShow_Fade(); }, thisObj.delay);
			}
		}, this.speed, this);
	}
}

/* VANILLA VERSION ....
// No preloaded included; add images into HTML and hide with CSS.
function dkFadeShow(container, offsetX, offsetY, images, delay, speed) {
	this.delayTimer = null;
	this.fadeTimer = null;

	this.currentImage = 0;
	this.currentAlpha = 10;
	this.fadeDir = 0;
	this.offsetX = offsetX;
	this.offsetY = offsetY;
	this.delay = delay;
	this.speed = speed;
	this.images = images;
	this.container = document.getElementById(container);

	dkFadeShow.prototype.dkFadeShow_Fade = dkFadeShow_Fade;
	this.container.style.background = "url(" + this.images[this.currentImage] + ") " + this.offsetX + "px " + this.offsetY + "px no-repeat";
	thisObj = this;
	this.delayTimer = setTimeout(function() { thisObj.dkFadeShow_Fade(); }, this.delay);

	function dkFadeShow_Fade() {
		clearTimeout(this.delayTimer);
		thisObj = this;
		this.fadeTimer = setInterval(function(thisObj) {
			if(thisObj.fadeDir == 0) { thisObj.currentAlpha--; } else { thisObj.currentAlpha++; }
			thisObj.container.style.opacity = thisObj.currentAlpha / 10;
			thisObj.container.style.filter = 'alpha(opacity=' + thisObj.currentAlpha * 10 + ')';

			if((thisObj.fadeDir == 0) && (thisObj.currentAlpha == 0)) {
				thisObj.fadeDir = 1;
				thisObj.currentImage++;
				if(thisObj.currentImage == thisObj.images.length) thisObj.currentImage = 0;
				thisObj.container.style.background = "url(" + thisObj.images[thisObj.currentImage] + ") " + thisObj.offsetX + "px " + thisObj.offsetY + "px no-repeat";
			}

			if((thisObj.fadeDir == 1) && (thisObj.currentAlpha == 10)) {
				thisObj.fadeDir = 0;
				clearInterval(thisObj.fadeTimer);
				thisObj.delayTimer = setTimeout(function() { thisObj.dkFadeShow_Fade(); }, thisObj.delay);
			}
		}, this.speed, this);
	}
}*/

