function PhotoManager()
{
	this.Enabled = true;
	this.Items = null;
	this.Window = null;
	this.Target = null;
	this.CurrentPhoto = null;
	this.Rotate = new Rotator(this);
	
	function Photo(id, key, src)
	{
		this.Id = id;
		this.Key = key;
		this.Image = new Image();
		this.Image.src = src;
	}
	
	function Rotator(manager)
	{
		this.Manager = manager;
		this.Enabled = false;
		
		this.Timer = null;
		this.Delay = 7000;
		
		this.Start = function ()
		{
			if (this.Manager.Items == null || this.Manager.Items.length < 1)
			{
				top.window.status = "ERROR: PhotoManager.Rotate.Start - Not enough images";
				return;
			}
			
			this.Enabled = true;
			
			var x = this;
			this.Timer = setTimeout(function() {x.NextPhoto();},this.Delay);
		}
		
		this.Stop = function ()
		{
			this.Enabled = false;
			
			clearTimeout(this.Timer);
			this.Timer = null;
		}
		
		this.Pause = function()
		{
			clearTimeout(this.Timer);
			this.Timer = null;
		}
		
		this.NextPhoto = function ()
		{
			if (!this.Manager.CurrentPhoto)
				this.Manager.CurrentPhoto = this.Manager.Items[0];
			
			var key = this.Manager.CurrentPhoto.Key + 1;
			if (this.Manager.Items.length - 1 < key)
			{
				key = 0;
			}
						
			this.Manager.SetPhoto(this.Manager.Items[key].Id);
			
			if (this.Enabled)
			{
				var x = this;
				this.Timer = setTimeout(function() {x.NextPhoto();},this.Delay);
			}
		}
	}
	
	this.AddPhoto = function (id, src)
	{
		if (!this.Enabled)
			return; // Had a problem, PhotoManager is disabled
					
		if (id == "" || id == null)
		{
			top.window.status = "ERROR: PhotoManager AddPhoto - Invalid Id";
			this.Enabled = false;
			this.Rotate.Enabled = false;
			return;
		}
				
		if (src == "" || src == null)
		{
			top.window.status = "ERROR: PhotoManager.AddPhoto - Invalid Src";
			this.Enabled = false;
			this.Rotate.Enabled = false;
			return;
		}
		
		if (!this.Items)
			this.Items = new Array();
				
		this.Items[this.Items.length] = new Photo(id, this.Items.length, src);
	}
	
	this.SetPhoto = function (id)
	{
		if (!this.Enabled)
			return; // Had a problem, PhotoManager is disabled
				
		var photo = this.GetPhoto(id);
		if (photo != null)
		{
			this.CurrentPhoto = photo;
			this.Target.src = photo.Image.src;
		}
	}
	
	this.EnlargePhoto = function ()
	{
		if (!this.Enabled)
			return; // Had a problem, PhotoManager is disabled
				
		if (!this.CurrentPhoto)
			this.CurrentPhoto = this.Items[0];
		
		if (this.Window)
		{
			this.Window.close();
			this.Window = null;
		}
		
		// Required for some IE versions only
		if(window.event) window.event.cancelBubble = true;
		this.Window = window.open("", "picPopup", "width=200,height=200,location=0,menubar=0,statusbar=0");
		this.Window.document.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n" +
			"	\"http://www.w3.org/TR/html4/strict.dtd\">\n" +
			"<html>\n<head>\n" +			"<style type=\"text/css\">" +
			"html,body{margin:0;padding:0;overflow:hidden;width:100%;height:100%;}" +
			"img{margin:0;padding:0;}" +
			"p{margin:0;padding:0.5em;text-align:center;}" +
			"</style>\n" +			"<scri" + "pt type=\"text/javascript\">" +
			"function loadImage()" +
			"{" +
			"	var img = new Image();" +
			"	img.src = \"" + this.CurrentPhoto.Image.src + "\";" +
			"	if (img.width == 0)" +
			"	{" +
			"		document.body.innerHTML = \"<table width='100%' height='100%'><tr><td align='center' valign='middle'>Image Unavailable...</td></tr></table>\"" +
			"	}" +
			"	else" +
			"	{" +
			"		var width = (img.width > 640) ? 640 : img.width;" +
			"		document.body.innerHTML = \"<a href='javascript:window.close();'><img src='\" + img.src + \"' width='\" + width + \"' border='0'></a>\";" +
			"		resizeWin();" +
			"	}" +
			"}" +
			"function resizeWin()" +
			"{" +
			"	var NS = (navigator.appName==\"Netscape\") ? true : false;" +
			"	iWidth = (NS) ? window.innerWidth : document.body.clientWidth;" +
			"	iHeight = (NS) ? window.innerHeight : document.body.clientHeight;" +
			"	iWidth = document.images[0].width - iWidth;" +
			"	iHeight = document.images[0].height - iHeight;" +
			"	window.resizeBy(iWidth, iHeight);" +
			"	self.focus();" +
			"}" +			"</scr" + "ipt>\n" +			"</head>\n" +			"<body onload=\"loadImage();\"><img src=\"" + this.CurrentPhoto.Image.src + "\"></body></html>");
		this.Window.document.close();
		return !this.Window;
	}
	
	this.MouseOver = function(id)
	{
		if (!this.Enabled)
			return; // Had a problem, PhotoManager is disabled
		
		if (this.Rotate.Enabled)
			this.Rotate.Pause();
		
		if (id)
		{
			this.SetPhoto(id);
		}
	}
	
	this.MouseOut = function()
	{
		if (!this.Enabled)
			return; // Had a problem, PhotoManager is disabled
		
		if (this.Rotate.Enabled)
			this.Rotate.Start();
	}
	
	this.GetPhoto = function (id)
	{
		if (id == "" || id == null)
		{
			top.window.status = "ERROR: PhotoManager GetPhoto - Invalid Id";
			this.Enabled = false;
			this.Rotate.Enabled = false;
			return;
		}
		
		for (var i = 0; i < this.Items.length; i++)
		{
			if (this.Items[i].Id == id)
				return this.Items[i];
		}

		top.window.status = "ERROR: PhotoManager.GetPhoto - Unable to find Photo [" + id + "]";
		this.Enabled = false;
		this.Rotate.Enabled = false;
		
		return null;
	}
}