 function rotatable(arr) {
	this.data = arr;
	this.length = arr.length;
	this.current = 0;

	this.next = function() {
		if (this.length == 0) { return false; }

		++this.current;
		if (this.current >= this.length) {
			this.current = 0;
		}
		return this.data[this.current];
	}

	this.prev = function() {
		if (this.length == 0) { return false; }
		--this.current;
		if (this.current < 0) {
			this.current = this.length-1;
		}
		return this.data[this.current];
	}
}

function createImageCollection(arr) {
	var length = arr.length;
	var preCached = new Array();
	for (var i=0; i< length; i++) {
		preCached.push(getImage(arr[i]));
	}
	return new rotatable(preCached);
}


function getImage(url) {
	var im = new Image();
	im.src = url;
	return im;
}




function runSlideShow1(){
var SlideShowSpeed = 4000;
var tss;
var node = $('navigation');
//var imgs = node.getElementsByTagName('img');


var newim = imgCollection.next();
//alert(newim.src);
node.style.backgroundImage="url("+newim.src+")"; 

//fadeout(imgs[0], 20, 50, true);
//fadein(newim, 20, 50);
//node.appendChild(newim);
tss = setTimeout('runSlideShow1()', SlideShowSpeed);
}

function run(){
runSlideShow1();
}

/**faders**/
function fadein(node, speed, delay) {
	node.opacity = 0;
	node.style.opacity = node.opacity;
	node.style.filter = 'alpha(opacity=0)';

	for (var i=0; i<40; i++) {
		window.setTimeout(function(){ if (node) { fadeStep(node,1);}}, delay + i*speed);
	}
}
function fadeout(node, speed, delay, remove) {
	node.opacity = 1;
	node.style.opacity = '100';
	node.style.filter = 'alpha(opacity=100)';
	for (var i=0; i<40; i++) {
		window.setTimeout(function(){ if (node) { fadeStep(node,-1);}}, delay + i*speed);
	}
	if (remove) {
		window.setTimeout(function(){ if (node && node.parentNode) { node.parentNode.removeChild(node)}}, delay + i*speed);
	}
}
function fadeStep(node, direction) {
	if (node.opacity <= 1) {
		node.opacity += direction * 1/40;
		node.style.opacity = ''+ node.opacity;
		var filterOpacity = Math.round(100*node.opacity);
		node.style.filter = 'alpha(opacity='+filterOpacity+')';
	} 
}
