var text="";
var PicsArray = [];
var TextArray = [];
var rX = 0, rY = 0;
var myWidth = 0, myHeight = 0;
var opac = 0;
var TimeToFade = 500.0;


function AssignPosition(d) {
	rX = 0; rY = 0;
	myWidth = 0; myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) 
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else 
	if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} 
	else 
	if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	if(self.pageYOffset) 
	{
		rX = self.pageXOffset;
		rY = self.pageYOffset;
	}
	else 
	if(document.documentElement && document.documentElement.scrollTop) 
	{
		rX = document.documentElement.scrollLeft;
		rY = document.documentElement.scrollTop;
	}
	else 
	if(document.body) 
	{
		rX = document.body.scrollLeft;
		rY = document.body.scrollTop;
	}
	else
	if(window.opera)
	{
	    fixedElement = document.getElementById('main-wrapper');
	    rX = fixedElement.style.pixelHeight;
	    rY = fixedElement.style.pixelWidth;
	}

	winW = 700;
	divWidth = d.offsetWidth;
	divHeight = d.offsetHeight;
	d.style.left = (winW / 2) - (divWidth / 2) + "px";
	d.style.top = ((myHeight/2) - (divHeight/2) + rY) + "px";
}

function TextPopup(path) {
	var dd = document.getElementById('textpopup');

	var Request = new XMLHttpRequest();
	Request.open( "GET", path, false )
	Request.send(null);

	dd.style.background="#efefef";
	html=Request.responseText;
	
	dd.innerHTML = html;
	dd.style.height="100%";
	dd.style.display = "block";
	dd.style.zIndex="99";
	AssignPosition(dd);
	dd.style.top=rY+"px";

	opac=0;
	fadeIn('textpopup');
}

function HideTextPopup() {
	var dd = document.getElementById('textpopup');
	opac=100;
	fadeOut('textpopup');
}

function SimplePopup(image) {
    var pi = document.getElementById('popi');
	pi.src="images/loading.gif";
	pi.onload = function() {
		LoadSimpleImage();
	};
	pi.src=image;
}

function LoadSimpleImage() {
    var dd = document.getElementById('popup');
	opac=0;
	fadeIn('popup');
	dd.style.display = "block";
	dd.style.zIndex="99";
	AssignPosition(dd);
}

function HideSimpleImage() {
    var dd = document.getElementById('popup');
	opac=100;
	fadeOut('popup');
}

function Display(image,t) {
	var ext = (/[.]/.exec(image)) ? /[^.]+$/.exec(image) : undefined;
	var dd = document.getElementById('viewer');

	if(ext == "gif" || ext == "jpg")
	{
//		document['scaled'].src="images/loading.gif";
		var img = new Image();
		img.onload = function() { 
		LoadImage(image, t);
		};
		img.src=image;
	}
	else
	if(ext == "php")
	{
		LoadImage(image,t);
		AssignPosition(dd);
		dd.style.top=rY+"px";
	}
}

function LoadImage(image, t) {
	var ext = (/[.]/.exec(image)) ? /[^.]+$/.exec(image) : undefined;
	var dd = document.getElementById('viewer');
	if ( navigator.appName != "Microsoft Internet Explorer" )
	{
		document.getElementById('dimmer').style.visibility = "visible";
		document.getElementById('dimmer').style.zIndex = "10";
	}
	text=t;
	for(i=0; i<PicsArray.length; i++)
	{
		if(image == PicsArray[i])
		{
			next_image=PicsArray[i+1];
			next_text=TextArray[i+1];
			prev_image=PicsArray[i-1];
			prev_text=TextArray[i-1];
		}
	}

	html="<table style=\"width:100%; height:100%; background:#000000\"><thead style=\"vertical-align:middle;\"><tr><td>";
	html=html+"<center><table height=\"100%\" width=\"100%\"><thead style=\"vertical-align:bottom;\">";
	html=html+"<tr><td colspan=3><a href=\"javascript:HideViewer();\">";
	html=html+"<img id=\"closebut\" style=\"border:0px solid black;float:right;\" src=\"images/xb.gif\" alt=\"close\" title=\"Close Viewer\"></a><br>";
	html=html+"</td></tr></thead><thead style=\"vertical-align:middle;\">";
	html=html+"<tr><td>";

	if(prev_image!=null) 
	{
		html=html+"<a onclick=\"javascript:HideButtons();\" href=\"javascript:Display('" + prev_image + "','" + prev_text + "');\">";
		html=html+"<img id=\"prevbut\" style=\"border:0px solid black; float:left;\" src=\"images/pb.gif\" alt=\"Prev\" title=\"Prev\"></a>";
	}
	else
	{
		html=html+"<img style=\"border:0px solid black;\" src=\"images/db.gif\" alt=\"Prev\"></a>";
		html=html+"<img id=\"prevbut\" style=\"border:0px solid black; float:left;\" src=\"images/db.gif\" alt=\"Prev\" title=\"Prev\"></a>";
	}

	html=html+"</td><td><center>";
	if(ext == "gif" || ext == "jpg")
	{
		html=html+"<img class=\"PICviewer\" onclick=\"javascript:HideViewer();\" name=\"scaled\" src=\"" + image + "\">";
		dd.style.background="#000000";
	}
	else
	if(ext == "php" )
	{
		var Request = new XMLHttpRequest();
		Request.open( "GET", image, false )
		Request.send(null);

		html=html+"<div style=\"width:700px;background:#efefef;\" onclick=\"javascript:HideTextViewer();\"><br /><br />";
		html=html+Request.responseText+"</div>";
	}
	html=html+"<br><font id=\"piclabel\" style=\"color:#999999; font-family:Arial, Helvetica, Sans-Serif;\"><center><b><i>" + text + "</i></b></center></font>";
	html=html+"</td></center><td>";
	
	if(next_image!=null) 
	{
		html=html+"<a onclick=\"javascript:HideButtons();\" href=\"javascript:Display('" + next_image + "','" + next_text + "');\">";
		html=html+"<img id=\"nextbut\" style=\"float:right; border:0px solid black;\" src=\"images/nb.gif\" alt=\"Next\" title=\"Next\"></a>";
	}
	else
	{
		html=html+"<img style=\"border:0px solid black;\" src=\"images/db.gif\" alt=\"Next\"></a>";
		html=html+"<img id=\"nextbut\" style=\"float:right; border:0px solid black;\" src=\"images/db.gif\" alt=\"Next\" title=\"Next\"></a>";
	}
	
	html=html+"</td></tr></thead><tr><td><img style=\"border:0px solid black;\" src=\"images/db.gif\" alt=\"\">";
	html=html+"</td></tr></table>";
	dd.innerHTML=html;
	if(ext == "php")
		dd.style.height="100%";
	ShowViewer();
}

function ShowViewer() {
	var dd = document.getElementById('viewer');
	dd.style.display = "block"; 
	dd.style.zIndex="99"; 
	AssignPosition(dd);
	opac=0;
	fadeIn('viewer');
} 

function HideViewer() {
	var dd = document.getElementById('viewer');
	opac=100;
	fadeOut('viewer');
}

function fadeIn(eid) { 
	var dd = document.getElementById(eid);
	if(opac!= 100)
	{ 
		opac+=10; 
		dd.style.opacity = opac/100; 
		setTimeout("fadeIn('" + eid + "')", 20); 
	}
	else	
	{
		dd.style.display = "block"; 
	}	
} 

function fadeOut(eid) { 
	var dd = document.getElementById(eid);
	if(opac!= 0)
	{ 
		opac-=10; 
		dd.style.opacity = opac/100; 
		setTimeout("fadeOut('" + eid + "')", 20); 
	}
	else	
	{
		dd.style.display = "none"; 
		document.getElementById('dimmer').style.visibility = "hidden";
	}	
} 

function HideTextViewer() {
	var dd = document.getElementById('viewer');
	opac=100;
	fadeOut();
//	dd.style.display = "none"; 
//	document.getElementById('dimmer').style.visibility = "hidden";
}

function HideButtons() {
    document.nextbut.style.visibility='hidden';
    document.prevbut.style.visibility='hidden';
    document.closebut.style.visibility='hidden';
	document.getElementById('piclabel').style.display='none';
	document.scaled.style.visibility='hidden';
}
 

