var __PanoramaShow__Object__ = new Array;
var __PanoramaShow__Count__ = 0;

function PanoramaShow (panoramaShowDivID) {
	var PanoramaShowIndex = __PanoramaShow__Count__;
	__PanoramaShow__Count__++;
	__PanoramaShow__Object__[PanoramaShowIndex] = this;

	var PanoramaShowDivField = document.getElementById(panoramaShowDivID);
	var PanoramaViewerField = null;
	var PanoramaCaptionField = null;
	var PanoramaSrc = new Array();
	var ThumbSrc = new Array();
	var PanoramaCaption = new Array();
	var PanoramaTitle = new Array();
//	var CachedPanoramas = new Array();
	var PanoramaCount = 0;
	var PanoramaPageNumber = 0;
	var TimeoutID;
	
	this.AddPanorama = function(imageSrc, thumbSrc, caption, title) {
		PanoramaCount++;
		PanoramaSrc[PanoramaCount] = imageSrc;
		ThumbSrc[PanoramaCount] = thumbSrc;
		PanoramaCaption[PanoramaCount] = caption;
		PanoramaTitle[PanoramaCount] = title;
	}

	this.Show = function() {
		PanoramaShowDivField.style.display = "block";
		//SlideShow();
	}
	
	this.Hide = function() {
		if (TimeoutID) {
			clearTimeout(TimeoutID);
		}
		PanoramaViewerField.execpano("set(\"camera\", \"play\", false);");
		PanoramaShowDivField.style.display = "none";
	}
	
	this.ShowPanorama = function(PageNumber) {
		if (TimeoutID) {
			clearTimeout(TimeoutID);
		}
		if (PageNumber > PanoramaCount) {
			PageNumber = 1;
		}
		if (PageNumber <= 0) {
			PageNumber = PanoramaCount;
		}

		PanoramaViewerField.execpano("set(\"camera\", \"play\", false);");
		PanoramaViewerField.execpano("loadpano(\"" + PanoramaSrc[PageNumber] + "\", false);");

		PanoramaCaptionField.innerHTML = "<b>" + PanoramaCaption[PageNumber] + "</b>";
		PanoramaPageNumber = PageNumber;
	}
	
	this.Preload = function() {
/*
		html = "<img title=\"\" alt=\"Panorama Viewer\" id=\"__PanoramaShow__PanoramaViewer__" +
			PanoramaShowIndex + "__\" style=\"border:thin solid black\" src=\"" + PanoramaSrc[1] + "\"><br>" +
			"<div id=\"__PanoramaShow__PanoramaCaption__" + PanoramaShowIndex +
			"__\" style=\"text-align:center\"><b>" + PanoramaCaption[1] + "</b></div>";
*/

// panorama/Edwards_GreatRoom.panoxml
//		"<param name=\"panorama\" value=\"" + PanoramaSrc[1] +
//		"<param name=\"antialiasing\" value=\"everytime\">" +
//		"<param name=\"antialiasing\" value=\"onstop\">" +
//		"<param name=\"gui\" value=\"include/gui.panoxml\">" +

		html = "<div style=\"border:thin solid black;width:600px;height:400px\">" +
		"<applet id=\"__PanoramaShow__PanoramaViewer__" + PanoramaShowIndex +
		"__\" name=\"__PanoramaShow__PanoramaViewer__" + PanoramaShowIndex +
		"__\" archive=\"include/PurePlayerPro.jar\" code=\"PurePlayerPro.class\" width=\"600\" height=\"400\" mayscript>" +
		"<param name=\"gui\" value=\"include/gui.panoxml\">" +
		"<param name=\"panorama\" value=\"" + PanoramaSrc[1] +
		"\"><param name=\"optimizememory\" value=\"true\">" +
		"<param name=\"antialiasing\" value=\"everytime\">" +
"</applet></div>";
		html +=	"<div id=\"__PanoramaShow__PanoramaCaption__" + PanoramaShowIndex +
				"__\" style=\"text-align:center\"><b>" + PanoramaCaption[1] + "</b></div>";

		if (PanoramaCount > 1) {
			html += "<button onclick=\"__PanoramaShow__Object__[" + PanoramaShowIndex + "].PreviousPanorama();\" style=\"text-align:center;width:120px;\">&lt;&lt; Previous &lt;&lt;</button>";
			html += "<button onclick=\"__PanoramaShow__Object__[" + PanoramaShowIndex + "].SlideShow();\" style=\"width:120px;\">Slide Show</button>";
			html += "<button onclick=\"__PanoramaShow__Object__[" + PanoramaShowIndex + "].NextPanorama();\" style=\"width:120px;\">&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;Next&nbsp;&nbsp;&nbsp;&nbsp;&gt;&gt;</button>";
			html += "<br><div style=\"text-align:center;float:left;overflow:auto;width:600px;height:200px\"><table><tr>";

			column = 0;
			htmlThumbRow = '';
			for (i = 1; i <= PanoramaCount; i++) {
				if (column >= 1) {
					html += "<tr>" + htmlThumbRow + "</tr>";
					htmlThumbRow = '';
					htmlCaptionRow = '';
					column = 1;
				} else {
					column++;
				}
				htmlThumbRow += "<td><img alt=\"Page " + i +
					"\" title=\"" + PanoramaTitle[i] +
					"\" onclick=\"__PanoramaShow__Object__[" +
					PanoramaShowIndex + "].ShowPanorama(" + i +
					");\" border=\"2\" src=\"" +
					ThumbSrc[i] + "\">" +
					"<br><a href=\"javascript:__PanoramaShow__Object__[" +
					PanoramaShowIndex + "].ShowPanorama(" + i +
					");\">" +
					PanoramaTitle[i] + "</a></td>";
			}
			html += "<tr>" + htmlThumbRow + "</tr>";
			html += "</table></div>";
		}
		PanoramaShowDivField.innerHTML = html;
		PanoramaViewerField = document.getElementById("__PanoramaShow__PanoramaViewer__" + PanoramaShowIndex + "__");
		PanoramaCaptionField = document.getElementById("__PanoramaShow__PanoramaCaption__" + PanoramaShowIndex + "__");
		
		for (i = 1; i < PanoramaCount; i++) {
//			CachedPanoramas[i] = new Panorama();
//			CachedPanoramas[i].src = PanoramaSrc[i];
		}
		//SlideShow();
	}
	
	this.NextPanorama = function() {
		this.ShowPanorama(PanoramaPageNumber + 1);
	}
	
	this.PreviousPanorama = function() {
		this.ShowPanorama(PanoramaPageNumber - 1);
	}
	
	this.SlideShow = SlideShow;
	
	function SlideShow() {
		if (PanoramaCount > 1) {
			__PanoramaShow__Object__[PanoramaShowIndex].NextPanorama();
			TimeoutID = setTimeout(SlideShow, 45000);
		}
	}
	
}

