function AssignPosition(d) {
	var rX = 0; var rY = 0;
	var 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;
	}

	divWidth = d.offsetWidth;
	divHeight = d.offsetHeight;
	d.style.left =(myWidth/2 - divWidth/2 + rX) - 100 + "px";
	d.style.top = (myHeight/2 - divHeight/2 + rY) -130 + "px";
	d.style.left = "-100px";
}

function SimplePopup(image) {
    var pi = document.getElementById('pop1');
	pi.onload = function() {
		LoadSimpleImage();
	};
	pi.src=image;
}

function LoadSimpleImage() {
    var dd = document.getElementById('popup');

    if(dd.style.display == "none")
        {
            dd.style.display = "block";
            dd.style.zIndex="99";
            AssignPosition(dd);
        }
        else
        {
            dd.style.display = "none";
        }
 }


function Display(image,t) {
	document['scaled'].src="images/loading.gif";
	var img = new Image();
	img.onload = function() { 
	LoadImage(image, t);
	};
	img.src=image;
}


function LoadImage(image, t) {
	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 width=\"100%\" height=\"100%\"><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 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 href=\"javascript:Display('" + prev_image + "','" + prev_text + "');\">";
		html=html+"<img  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+"</td><td><center>";
	html=html+"<img onClick=\"javascript:HideViewer();\" name=\"scaled\" src=\"" + image + "\">";
	html=html+"<br><font style=\"color:#999999; font-family:Arial, Helvetica, Sans-Serif;\"><center><b><i>" + text + "</i></b></center></font>";
	html=html+"</td><td>";
	if(next_image!=null) 
	{
		html=html+"<a href=\"javascript:Display('" + next_image + "','" + next_text + "');\">";
		html=html+"<img 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+"</td></tr></thead><tr><td><img style=\"border:0px solid black;\" src=\"images/db.gif\" alt=\"\">";
	html=html+"</td></tr></table>";
	dd.innerHTML=html;
	ShowViewer();
}

function ShowViewer() {
	var dd = document.getElementById('viewer');
	dd.style.display = "block"; 
	dd.style.zIndex="99"; 
	AssignPosition(dd);
	document.scaled.style.display = "block";
	document.scaled.style.visibility = "visible";
}

function HideViewer() {
	var dd = document.getElementById('viewer');
	document.scaled.src="images/loading.gif";
	dd.style.display = "none"; 
	document.getElementById('dimmer').style.visibility = "hidden";
}


