$(function() {
	IntroSlideshow.init();
});

$(window).load(function() {
	setInterval('IntroSlideshow.next()', 2000);
});

IntroSlideshow = {
	
	init: function() {
		this.cont = $('#intro .slideshow');
		this.images = [];
		var imgs = this.cont.find('img');
		for (var i = 0; i < imgs.length; i++) {
			this.images.push(imgs[i].src);
			$(imgs[i]).css('opacity', 0);
			if (imgs[i].complete)
				$(imgs[i]).remove();
			else
				$(imgs[i]).load(function() { $(this).remove(); });
		}
		this.cont.css('backgroundImage', 'url(' + imgs[0].src + ')');
		this.imgIdx = 0;
	},
	
	next: function() {
		this.imgIdx = (this.imgIdx + 1) % this.images.length;
		var img = $('<img>')
			.attr('src', this.images[this.imgIdx])
			.css({ opacity: 0 })
			.appendTo(this.cont)
			.animate({ opacity: 1 }, 1000, function() {
				$(this).parent().css('backgroundImage', 'url(' + this.src + ')');
				$(this).remove();
			});
	}
	
}
