function Slideshow(tag, image_urls, timeout, fadetime, start_immediately) {
	if (typeof(timeout) == 'undefined') { timeout = 5000; }
	if (typeof(fadetime) == 'undefined') { fadetime = 1000; }
	if (typeof(start_immediately) == 'undefined') { start_immediately = true; }

	this.timeout = timeout;
	this.fadetime = fadetime;

	//We have to wrap the tag in a div
	
	tag.wrap($('<div/>').height(tag.height()).width(tag.width()).css('position', 'relative'));
	tag.css('position', 'absolute');

	this.current_tag = 0;	
	this.tags = [tag]; //List of our image tags
	for (i = 0; i < image_urls.length; i += 2) {
		new_img = $('<img src="' + image_urls[i] + '" alt="' + image_urls[i + 1] + '" />');
		new_img.hide();
		new_img.css('position', 'absolute');
		this.tags.push(new_img);
		tag.after(new_img);
	}
}

Slideshow.prototype._change_image = function(obj) {
	if (obj.stopped) { return; }
	obj.tags[obj.current_tag].fadeOut(obj.fadetime * 2);
	obj.current_tag++;
	if (obj.current_tag == obj.tags.length) { obj.current_tag = 0; }
	obj.tags[obj.current_tag].fadeIn(obj.fadetime);
}

function i(image_name) {
	return '../images/photo/index/' + image_name + '.jpg';
}

$(window).load(function() {
	var ss = new Slideshow($('#slideshow'),
		[i('living_room'), 'The Bunkhouse Living Room',
		 i('cow'), 'A Cow',
		 i('snow'), 'The Bunkhouse in the Snow',
		 i('kitchen'), 'The Bunkhouse Kitchen',
		 i('stream'), 'A Welsh Stream'] 
	);
	document.ss = ss

	setInterval('document.ss._change_image(document.ss)', ss.timeout);
});


