// JavaScript Document

// slideshow
var images = new Array;
var imageIndex = 0;
var layerSwitcher = 1;
var imageCount;
var showcase;
var showcaseLayer;

// init function
function initSlideShow() {
	// define slidwshow container
	showcase = $('div.header_header');
	showcase.append('<div id="slideshow_layer" style="height:100%; width:100%; overflow:hidden;"></div>');
	showcaseLayer = $('div#slideshow_layer');
	// collect the images found in the container and add it's source to the images array
	showcase.children('.slide').each(function(i){
		images.push(this.src);
		// remove the image from the container
		$(this).remove();
	}); 
	// how many images did we find?
	imageCount = images.length;
	// ad an image to the slideshow_layer
	showcaseLayer.append('<img id="slideshow_layer_image" style="height:100%; width:100%;" src="'+images[0]+'"/>');
	slideShow();
}

function slideShow() {
	setTimeout('slideShow()' , 4000);
	if(imageIndex>(images.length-1)) {
		imageIndex = 0;
	}
	var background = 'url(\''+images[imageIndex]+'\')';
	if(layerSwitcher==1) {
		showcase.css("background",background);
		showcaseLayer.fadeOut(1000);
	} else {
		showcaseLayer.children('img#slideshow_layer_image').get(0).src = images[imageIndex];
		showcaseLayer.fadeIn(1000);
	}
	layerSwitcher *= -1;
	imageIndex++;
}