var pictureWindow;
var PictWinOut;
var viewMethod;
var CenteredOut;
var OriginalTitle = document.title;
var PhotoDivElement;;
var PhotoTableElement;
var PhotoTrHeaderElement;
var PhotoThHeaderElement;
var PhotoImgElement;
var viewMethodv;

function viewPhoto(image, width, height, title) {
	if(window.pictureWindow) {
		if (!pictureWindow.closed) {
			pictureWindow.close();
		}
	}
	if(document.getElementById('ViewMethod')) {viewMethodv = document.getElementById('ViewMethod').value;}
	else {viewMethodv = "Popup";}
		
	switch(viewMethodv) {
		case "Popup":
			pictureWindow = window.open('', "PicWin", "width=" + width +",height=" + height + ",scrollbars=no, location=no, menubar=no, statusbar=no, toolbar=no, resizable=no");
			
			PictWinOut = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" oncontextmenu=\"return false;\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><meta http-equiv=\"Cache-Control\" content=\"no-cache\" /><meta http-equiv=\"Expires\" content=\"0\" /><meta http-equiv=\"Pragma\" content=\"no-cache\" />";
			PictWinOut = PictWinOut + "<title>" + title + "</title>";
			PictWinOut = PictWinOut + "<style type=\"text/css\">html, body {margin: 0px;} body {background: url(" + image + ") no-repeat top left;} #imgHolder {width: 100%; height: 100%; margin: 0px; padding: 0px; background: url(./images/blank.gif) repeat;}</style>";
			PictWinOut = PictWinOut + "</head><body><div id=\"imgHolder\">";
			PictWinOut = PictWinOut + "<img src=\"./images/blank.gif\" title=\"" + title + " ::: Click here to close this window.\" onclick=\"window.close();\" oncontextmenu=\"return false;\" onmousedown=\"return false;\" style=\"height: " + height + "px; width: " + width + "px;\"  alt=\"\" />";
			PictWinOut = PictWinOut + "</div></body></html>";
			
			pictureWindow.document.write(PictWinOut);
			pictureWindow.document.close();
			pictureWindow.focus();
			break;
		case "Centered":
			
			//document.title = title;
			
			PhotoDivElement = document.createElement("div");
			PhotoDivElement.setAttribute("style", "z-index: 50; position: absolute; position: fixed; top: 0px; bottom: 0px; right: 0px; left: 0px; behavior: url(iepngfix.htc); background: url(./images/trans.png)");
			PhotoDivElement.setAttribute('id', 'PhotoDivElement');
			
			PhotoTableElement = document.createElement('table');
			PhotoTableElement.setAttribute('id', 'PhotoTableElement');
			PhotoTableElement.setAttribute('style', 'margin-left: auto; margin-right: auto; margin-top: auto; margin-bottom: auto; background: #FFFFFF; color: #000000; border-collapse: collapse; border: 1px solid #000000;');
			
			PhotoTrHeaderElement = document.createElement('tr');
			PhotoTrHeaderElement.setAttribute('id', 'PhotoTrHeaderElement');
			
			PhotoThHeaderElement = document.createElement('th');
			PhotoThHeaderElement.setAttribute('id', 'PhotoThHeaderElement');
			PhotoThHeaderElement.setAttribute('style', 'text-align: center; vertical-align: middle;');
			
			var PhotoThHeaderText = document.createTextNode(title);
			
			var PhotoTrContentElement = document.createElement('tr');
			PhotoTrContentElement.setAttribute('id', 'PhotoTrContentElement');
			PhotoTrContentElement.setAttribute('style', 'background: url('+ image +') no-repeat center;');
			
			var PhotoTdContentElement = document.createElement('td');
			PhotoTdContentElement.setAttribute('id', 'PhotoTdContentElement');
			PhotoTdContentElement.setAttribute('style', 'text-align: center; vertical-align: middle; background: url(./images/blank.gif);');
			
			var PhotoTrFooterElement = document.createElement('tr');
			PhotoTrFooterElement.setAttribute('id', 'PhotoTrFooterElement');
			
			var PhotoTdFooterElement = document.createElement('td');
			PhotoTdFooterElement.setAttribute('id', 'PhotoTdFooterElement');
			PhotoTdFooterElement.setAttribute('style', 'text-align: center;');
			
			var PhotoTdFooterText1 = document.createTextNode('[');
			
			var PhotoTdFooterAElement = document.createElement('a');
			PhotoTdFooterAElement.setAttribute('id', 'PhotoTdFooterAElement');
			PhotoTdFooterAElement.setAttribute('href', '#');
			PhotoTdFooterAElement.setAttribute('onclick', 'resetPhotoView(); return false;');
			PhotoTdFooterAElement.setAttribute('onmousedown', 'return false;');
			PhotoTdFooterAElement.setAttribute('oncontextmenu', 'return false;');
			
			var PhotoTdFooterAText = document.createTextNode('Close this photo.');
			
			var PhotoTdFooterText2 = document.createTextNode(']');
			
			var PhotoImgElement = document.createElement('img');
			PhotoImgElement.setAttribute('src', './images/blank.gif');
			PhotoImgElement.setAttribute('style', 'width: ' + width + 'px; height: ' + height + 'px;');
			PhotoImgElement.setAttribute('onclick', 'resetPhotoView();');
			PhotoImgElement.setAttribute('title', 'Click to close photo.');
			
			
			//CenteredOut = "<img src=\"./images/blank.gif\" title=\"" + title + " ::: Click here to close this window.\" onclick=\"\" oncontextmenu=\"return false;\" onmousedown=\"return false;\" style=\"height: " + height + "px; width: " + width + "px;\"  alt=\"\" />"
			
			document.getElementById("container").appendChild(PhotoDivElement);
			
			document.getElementById('PhotoDivElement').appendChild(PhotoTableElement);
			
			document.getElementById('PhotoTableElement').appendChild(PhotoTrHeaderElement);
			document.getElementById('PhotoTrHeaderElement').appendChild(PhotoThHeaderElement);
			document.getElementById('PhotoThHeaderElement').appendChild(PhotoThHeaderText);
			
			document.getElementById('PhotoTableElement').appendChild(PhotoTrContentElement);
			document.getElementById('PhotoTrContentElement').appendChild(PhotoTdContentElement);
			document.getElementById('PhotoTdContentElement').appendChild(PhotoImgElement);
			
			document.getElementById('PhotoTableElement').appendChild(PhotoTrFooterElement);
			document.getElementById('PhotoTrFooterElement').appendChild(PhotoTdFooterElement);
			document.getElementById('PhotoTdFooterElement').appendChild(PhotoTdFooterText1);
			document.getElementById('PhotoTdFooterElement').appendChild(PhotoTdFooterAElement);
			document.getElementById('PhotoTdFooterAElement').appendChild(PhotoTdFooterAText);
			document.getElementById('PhotoTdFooterElement').appendChild(PhotoTdFooterText2);
	
			break;
	}


}

function resetPhotoView() {
	document.getElementById('container').removeChild(PhotoDivElement);
	//document.title = OriginalTitle;	
}
