function CImg(title, url, address, city, state, price, bedsbaths, mls, detailPage)
{
	this.ID = 0;
	this.Title = title;
	this.URL = url;
	//this.cache = new Image;
	//this.cache.src = url;
	this.Address = address;
	this.City = city;
	this.State = state;
	this.Price = price;
	this.BedsBaths = bedsbaths;
	this.MLS = mls;
	this.DetailPage = detailPage;
}
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.ShowTable = showTable;
	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, address, city, state, price, bedsbaths, mls, detailPage)
	{
		var img = new CImg(title, url, address, city, state, price, bedsbaths, mls, detailPage);
		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 showTable(startPict)
	{
		idx = 0;
		notDone = true;
		pointer = startPict;
		while (notDone)
		{
			objName = "ActList" + idx;
			document.getElementById(objName).src = this.Imgs[pointer].URL;
			objName = "ALPrice" + idx;
			document.getElementById(objName).innerHTML = this.Imgs[pointer].Price;
			objName = "ALCityZip" + idx;
			document.getElementById(objName).innerHTML = this.Imgs[pointer].CityState;
			objName = "HiddenURL" + idx;
			document.getElementById(objName).value = this.Imgs[pointer].DetailPage;
			idx++;
			pointer++;
			if(pointer>=this.Imgs.length)
			{
				if(pointer < 6)
					notDone=false;	// Less than the number of pics to fill the table, just stop
				pointer=0;
			}
			if(notDone & idx > 5)
			{
				notDone=false;	//idx = 0;
				// Set Timer and next starting photo
				startPict-=2;
				if(startPict < 0)
					startPict=this.Imgs.length-1;
				window.setTimeout('imgs.ShowTable(' + startPict + ')',7000);
			}
		}
	}
	
	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;
		document.getElementById(this.ListingAddress).innerHTML = this.Imgs[pointer].Address;
		document.getElementById(this.ListingCity).innerHTML = this.Imgs[pointer].City;
		document.getElementById(this.ListingState).innerHTML = this.Imgs[pointer].State;
		document.getElementById(this.ListingBedsBaths).innerHTML = this.Imgs[pointer].BedsBaths;
		document.getElementById(this.ListingMLS).innerHTML = "";
		document.getElementById(this.ListingPrice).innerHTML = "";
		if(this.Imgs[pointer].BedsBaths == "" && this.HideBlanks == "Y")
			document.getElementById(this.ListingBedsBaths).innerHTML = this.Imgs[pointer].MLS;
		else
			document.getElementById(this.ListingMLS).innerHTML = this.Imgs[pointer].MLS;
		if((this.Imgs[pointer].BedsBaths == "") && (this.Imgs[pointer].MLS == "") && this.HideBlanks == "Y")
			document.getElementById(this.ListingBedsBaths).innerHTML = this.Imgs[pointer].Price;
		else if(this.Imgs[pointer].MLS == "" && this.HideBlanks == "Y")
			document.getElementById(this.ListingMLS).innerHTML = this.Imgs[pointer].Price;
		else
			document.getElementById(this.ListingPrice).innerHTML = this.Imgs[pointer].Price;
		document.getElementById(this.HiddenURL).value = this.Imgs[pointer].DetailPage;
	}
	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;
	}
}
