function Slideshow (settings)
{
	var obj = new Object;
	obj.items 			= settings.items == null 		? false : settings.items;
	obj.currentImage 	= settings.currentImage == null ? -1 	: settings.currentImage;
	obj.timeout 		= 0;
	obj.playing 		= settings.playing == null 		? true 	: settings.playing;
	obj.delay 			= settings.delay == null 		? 7000 	: settings.delay;
	obj.fadeduration	= settings.fadeduration == null ? .5 	: settings.fadeduration;
	obj.restartdelay 	= settings.restartdelay == null ? 20000 : settings.restartdelay;
	obj.parent 			= settings.parent == null 		? false : settings.parent;
	obj.smooth 			= settings.smooth == null 		? true 	: settings.smooth;
	
	if (!obj.items && obj.parent) {
		obj.items = new Array();
		var elements = $(obj.parent).childElements();
		elements.each(function(item) {
			obj.items.push(item.identify());
			item.hide();
		});
	}

	obj.showNextImage = function (mode, obj, theduration)
	{
		isauto = true;
		if (mode == undefined || mode == null || mode == 'auto')
		{
			isauto = true;
		}
		else if (mode == "manual")
		{
			isauto = false;
		}
		if (theduration == undefined || theduration == null) theduration = .5;
		if (!obj.playing && isauto) return;
		clearTimeout(obj.timeout);
	
		if (obj.items.length>1)
		{
			var nextImageIndex = obj.currentImage + 1;
			var lastImageIndex = obj.currentImage;
			
			if (nextImageIndex < obj.items.length)
			{
				// Fade in next image
				if (obj.smooth)
				{
					// Smooth overlay
					$(obj.items[nextImageIndex]).appear({duration:obj.fadeduration});
				}
				else
				{
					if (nextImageIndex > 0)
					{
						// Hide previous image first
						$(obj.items[obj.currentImage]).fade({duration:obj.fadeduration});
						$(obj.items[nextImageIndex]).appear({duration:obj.fadeduration,delay:obj.fadeduration});
					}
					else
					{
						// First image
						$(obj.items[nextImageIndex]).appear({duration:obj.fadeduration});
					}
				}
				obj.currentImage = nextImageIndex;
				
				if (isauto)
				{
					// Set timeout to next image
					obj.playing = true;
					obj.timeout = setTimeout(function() { obj.showNextImage(mode,obj) }, obj.delay);
				}
			}
			else
			{
				if (obj.smooth)
				{
					// Smooth overlay
					// It's the last image, so hide all the images but the first and last
					for (var i=1; i<obj.items.length-1; i++)
					{
						$(obj.items[i]).hide();
					}
					// Fade out the last image
					$(obj.items[obj.items.length-1]).fade({duration:obj.fadeduration});
				}
				else
				{
					$(obj.items[obj.items.length-1]).fade({duration:obj.fadeduration});
					$(obj.items[0]).appear({duration:obj.fadeduration,delay:obj.fadeduration});
				}
				
				obj.currentImage = 0;
				
				if (isauto)
				{
					// Set timeout to next image
					obj.playing = true;
					obj.timeout = setTimeout(function() { obj.showNextImage(mode,obj) }, obj.delay);
				}
			}
			if ($('thumbs')) {
				new Effect.Move('thumbs',{ x: 0, y: 100-(obj.currentImage*120), mode: 'absolute', duration:theduration });
				new Effect.Opacity('thumb'+(obj.currentImage+1), { from: 1.0, to: 0.3, duration:theduration });
				if (lastImageIndex > -1) new Effect.Opacity('thumb'+(lastImageIndex+1), { from: 0.3, to: 1, duration:theduration });
			}
			
			if (obj.currentImage == 0)
			{
				// This is the first image
				$('thumbarrow_up').hide();
				$('thumbarrow_up_inactive').show();
			}
			else
			{
				$('thumbarrow_up').show();
				$('thumbarrow_up_inactive').hide();
			}
			if (obj.currentImage == obj.items.length-1)
			{
				// This is the last image
				$('thumbarrow_down').hide();
				$('thumbarrow_down_inactive').show();
			}
			else
			{
				$('thumbarrow_down').show();
				$('thumbarrow_down_inactive').hide();
			}
		}
		else
		{
			$(obj.items[0]).show();
		}
		if (flashIsReady) $("flash0").setCurrentPhoto(obj.currentImage);
	};
	
	obj.showPreviousImage = function (obj, theduration)
	{
		// Stop autoplaying
		obj.playing = false;
		clearTimeout(obj.timeout);
	
		if (theduration == undefined || theduration == null) theduration = .5;
		if (obj.items.length>1)
		{
		
			var nextImageIndex = obj.currentImage - 1;
			var lastImageIndex = obj.currentImage;
			
			if (nextImageIndex > -1)
			{
				if (obj.smooth)
				{
					// Smooth overlay
					
					// Show previous image
					$(obj.items[nextImageIndex]).show();
					
					// Fade out current image
					$(obj.items[obj.currentImage]).fade({duration:obj.fadeduration});
				
					// Set currentimage index
					obj.currentImage = nextImageIndex;
				}
				else
				{
					// Fade out current image
					$(obj.items[obj.currentImage]).fade({duration:obj.fadeduration});
					
					// Show previous image
					$(obj.items[nextImageIndex]).appear({duration:obj.fadeduration, delay:obj.fadeduration});
				
					// Set currentimage index
					obj.currentImage = nextImageIndex;
				}
			}
			else
			{
				if (obj.smooth)
				{
					// It's the first image, so hide all the images but the last
					$(obj.items[obj.items.length-1]).appear({duration:obj.fadeduration});
					var timeout = setTimeout(function(){
						for (var i=0; i<obj.items.length-2; i++)
						{
							$(obj.items[i]).hide();
						}
					},500);
				}
				else
				{
					$(obj.items[0]).fade({duration:.5});
					$(obj.items[obj.items.length-1]).appear({duration:obj.fadeduration, delay:obj.fadeduration});
				}
				
				obj.currentImage = obj.items.length-1;
			}
			if ($('thumbs')) {
				new Effect.Move('thumbs',{ x: 0, y: 100-(obj.currentImage*120), mode: 'absolute', duration:theduration });
				new Effect.Opacity('thumb'+(obj.currentImage+1), { from: 1.0, to: 0.3, duration:theduration });
				if (lastImageIndex > -1) new Effect.Opacity('thumb'+(lastImageIndex+1), { from: 0.3, to: 1, duration:theduration });
			}
			
			if (nextImageIndex == 0)
			{
				// This is the first image
				$('thumbarrow_up').hide();
				$('thumbarrow_up_inactive').show();
			}
			else
			{
				$('thumbarrow_up').show();
				$('thumbarrow_up_inactive').hide();
			}
			if (nextImageIndex == obj.items.length)
			{
				// This is the last image
				$('thumbarrow_down').hide();
				$('thumbarrow_down_inactive').show();
			}
			else
			{
				$('thumbarrow_down').show();
				$('thumbarrow_down_inactive').hide();
			}
		}
		else
		{
			$(obj.items[0]).show();
		}
		// Set timeout to restart animation
		//obj.timeout = setTimeout(function(){ obj.playing=true; obj.showNextImage(null,obj) },obj.restartdelay);
		if (flashIsReady) $("flash0").setCurrentPhoto(obj.currentImage);
	};
	
	obj.showImage = function (no, obj, theduration)
	{
		// Stop autoplaying
		obj.playing = false;
		clearTimeout(obj.timeout);
		var lastImageIndex = obj.currentImage;
		
		if (theduration == undefined || theduration == null) theduration = .5;
		if (obj.currentImage == no)
		{
			// It's already visible
			return;
		}
		else if (obj.currentImage < no)
		{
			// Next photo is over
			$(obj.items[no]).appear({duration:obj.fadeduration});
			obj.currentImage = no;
		}
		else
		{
			// Next photo is under
			$(obj.items[no]).setStyle({'display':''});
			// Hide all between
			var nextImageIndex = no+1;
			for (var i=nextImageIndex; i<obj.currentImage; i++)
			{
				$(obj.items[i]).setStyle({'display':'none'});
			}
			// Hide current photo
			$(obj.items[obj.currentImage]).fade({duration:obj.fadeduration});
			obj.currentImage = no;
		}
		if ($('thumbs')) {
			new Effect.Move('thumbs',{ x: 0, y: 100-(no*120), mode: 'absolute', duration:theduration });
			new Effect.Opacity('thumb'+(obj.currentImage+1), { from: 1.0, to: 0.3, duration:theduration });
			if (lastImageIndex > -1) new Effect.Opacity('thumb'+(lastImageIndex+1), { from: 0.3, to: 1, duration:theduration });

		}
			
		if (obj.currentImage == 0)
		{
			// This is the first image
			$('thumbarrow_up').hide();
			$('thumbarrow_up_inactive').show();
		}
		else
		{
			$('thumbarrow_up').show();
			$('thumbarrow_up_inactive').hide();
		}
		if (obj.currentImage == obj.items.length-1)
		{
			// This is the last image
			$('thumbarrow_down').hide();
			$('thumbarrow_down_inactive').show();
		}
		else
		{
			$('thumbarrow_down').show();
			$('thumbarrow_down_inactive').hide();
		}
	
		// Set timeout to restart animation
		//obj.timeout = setTimeout(function(){ obj.playing=true; obj.showNextImage(null, obj) },obj.restartdelay);
		if (flashIsReady) $("flash0").setCurrentPhoto(obj.currentImage);
	};
	
	obj.pause = function ()
	{
		// Stop autoplaying
		var thisobj = this;
		thisobj.playing = false;
		clearTimeout(thisobj.timeout);
	};
	
	obj.play = function ()
	{
		// Stop autoplaying
		var thisobj = this;
		thisobj.playing = true;
		thisobj.showNextImage('auto', thisobj);
		//$("flash0").setCurrentPhoto(thisobj.currentImage);
		//thisobj.timeout = setTimeout(function(){ thisobj.showNextImage(null, thisobj) },thisobj.delay);
	};
	
	//if (obj.items.length > 0) obj.showNextImage(true, obj);
	
	return obj;
}
var flashIsReady = false;
var jsReady = false;
function isReady() 
{
	return jsReady;
}
function thisMovie(movieName) 
{
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}
function setXMLURL(value) {
	//alert("Setting URL to: "+value);
	/*
	var movie = $("flash0");
	if (movie.checkFlashReady()) alert("Flash is ready");
	alert(movie.setXMLURL(value));
	*/
}
function clickMenuItem(id)
{
	$(id).addClassName("active");
}
