function CImg(title, url)
{
	this.ID = 0;
	this.Title = title;
	this.URL = url;
	this.cache = new Image;
	this.cache.src = url;
}
function CImgs()
{
	var pointer = -1;
	var timerID;
	//setting properties
	var p = new CImgsConfiguration();
	for (prop in p)
		this[prop] = p[prop];
	p = null;
	//Imgs holds all of the images
	this.Imgs = new Array();
	//followings are the APIs
	this.AddImg = addImg;
	this.ShowFirst = first;
	this.ShowLast = last;
	this.ShowPrevious = previous;
	this.ShowNext = next;
	this.ShowImg = show;
	//this.SlideShow = play;//does not work
	this.Stop = stop;
	/*
	function AddImg(img)
	{
		this.Imgs[this.Imgs.length] = img;
	}
	*/
	function addImg(title, url)
	{
		var img = new CImg(title, url);
		img.ID = this.Imgs.length;
		this.Imgs[this.Imgs.length] = img;
	}
	function previous()
	{
		pointer--;
		if (pointer < 0 )
			pointer = this.Imgs.length - 1 ;
		this.ShowImg();
	}
	function next()
	{
		pointer++;
		if (pointer >= this.Imgs.length)
			pointer = 0;
		this.ShowImg();
	}
	function show()
	{
		if( window.crossfade ) {
			crossfade(document.getElementById(this.DisplayImgCellID),document.getElementById(this.DisplayImgCellID + "Dupe"),this.Imgs[pointer].URL,'1',this.Imgs[pointer].Title);	
		}
		else {
			document.getElementById(this.DisplayImgCellID).src = this.Imgs[pointer].URL;
		}
		document.getElementById(this.DisplayImgTitleID).innerHTML = this.Imgs[pointer].Title;
		document.getElementById(this.DisplayNumberID).innerHTML = (pointer + 1) + "/" + this.Imgs.length;
	}
	function first()
	{
		pointer = 0;
		this.ShowImg();
	}
	function last()
	{
		pointer = this.Imgs.length - 1;
		this.ShowImg();
	}
	/*
	function play()
	{
		timerID = window.setInterval(next, this.ImgShowTime);
	}
	*/
	function stop()
	{
		try
		{
			window.clearInterval(timerID);
		}
		catch(e){}
	}			
}


/*
//followings will be created by server side code
var imgs = new CImgs();
	imgs.AddImg("Title_" + i++, "http://localhost/LPSites/Uploads/1/1/Photos/front.jpg");
	imgs.AddImg("Title_" + i++, "http://localhost/LPSites/Uploads/1/1/Photos/HomeShow02.jpg");
	imgs.AddImg("Title_" + i++, "http://localhost/LPSites/Uploads/1/1/Photos/LivingRoom.jpg");
	imgs.AddImg("Title_" + i++, "http://localhost/LPSites/Uploads/1/1/Photos/familyRoom.jpg");
	imgs.AddImg("Title_" + i++, "http://localhost/LPSites/Uploads/1/1/Photos/HomeShow01.jpg");
	imgs.AddImg("Title_" + i++, "http://localhost/LPSites/Uploads/1/1/Photos/LivingRoom.bmp");
	imgs.AddImg("Title_" + i++, "http://www.baynetsites.com/images/miniature1.jpg");
	imgs.AddImg("Title_" + i++, "http://localhost/LPSites/Uploads/1/1/Photos/BackYard.jpg");
	imgs.AddImg("Title_" + i++, "http://localhost/LPSites/Uploads/1/1/Photos/Kitchen.jpg");
	imgs.AddImg("Title_" + i++, "http://localhost/LPSites/Uploads/1/1/Photos/entertainment.jpg");
*/
			
//client use: event handlers
function ShowImg(action)
{
	switch(action)
	{
		case "-1":
			imgs.ShowPrevious();
			break;
		case "+1":
			imgs.ShowNext();
			break;
		case "first":
			imgs.ShowFirst();
			break;
		case "last":
			imgs.ShowLast();
			break;
		case "play":
			iTimerID = window.setInterval("ShowImg('+1')", imgs.ImgShowTime)
			//imgs.SlideShow();
			break;
		case "stop":
			try
			{
				window.clearInterval(iTimerID);
			}
			catch(e){}
			//imgs.Stop();
			break;
	}
}
