var slideshow = new function() {
	this.image_delay = 9000;	//time (ms) between each slide change
	this.transition_time = 500; //time (ms) spent animating between slides
	this.base_dir = '/images/slideshow/';
	this.container_selector = "#slideshow";	
	
	this.container_css = 
		{
			position: "relative",
			display: "block",
			width: 985,
			height: 297,
			overflow: "hidden",
			"z-index": 50
		};
	this.slide_css =
		{
			position: "absolute",
			top: 0,
			right: 0,
			display: "none"
		};

	this.slides = []; //array of images
	this.index = 0; //current index
	this.timer = 0; //main timer	
	
	this.container = null; //jquery object
	this.container_slides = []; //array of jquery slides

	this.setup = function(slides) {
		this.slides = slides;
		this.container = jQuery(this.container_selector);

		this.setupHTML();
		this.start();
	};
	
	this.change = function() {	
		var next_id = this.index + 1;
		if (next_id >= this.slides.length)
			next_id = 0;

		var current_slide = this.container_slides[this.index];
		var next_slide = this.container_slides[next_id];
		
		current_slide.css('z-index',10);
		next_slide.css('z-index',9);
		next_slide.show();
		
		current_slide.fadeOut(this.transition_time);
		
		this.index = next_id;
	};
		
	this.start = function() {
		this.timer = setInterval("slideshow.tick()", this.image_delay);
	};
	
	this.setupHTML = function() {
		this.container.css(this.container_css);
		
		for(var i=0; i<this.slides.length; i++) {
			var slide = jQuery('<div />').css(this.slide_css).html('<img src="' + this.base_dir + this.slides[i] + '" />');
			this.container_slides.push(slide);
			this.container.append(slide);
		}		
		this.container_slides[0].show();
	};
	
	this.tick = function() {
		this.change();
	};
};
