// JavaScript Document
var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all
var imageWidth;
var imageHeight;
var lastImage;
function hidebox(){
	crossobj=ns6? document.getElementById("popout") : document.all.popout;
	if(crossobj.style.visibility=="hidden") return;
	var pageWrap = ns6? document.getElementById("pageWrap") : document.all.pageWrap;
	var image = ns6? document.getElementById("popupImage") : document.all.popupImage;
	// Reset image sizes to original 
	if(lastImage == image.src) {
		image.width = imageWidth;
		image.height = imageHeight;
	} else {
		image.width = 0;
		image.height = 0;
	}
	changeOpac(100, 'pageWrap');
	changeOpac(30, 'rhs-bg');
	if (ie4||ns6)
	crossobj.style.visibility="hidden";
	else if (ns4)
	document.showimage.visibility="hide";
}
function showLoadingDiv(){
	document.createElement("div");
	document.createElement("");
	
}
function showImage(s, txt){
	try{
		var image = ns6? document.getElementById("popupImage") : document.all.popupImage;
		var box = ns6? document.getElementById("popout") : document.all.popout;
		
		var closeLink = ns6? document.getElementById("closeLink") : document.all.closeLink;
		viewportwidth = GetViewportWidth();
		viewportheight = GetViewportHeight();
		var scrollPos = getScrollXY();
		theLeft = scrollPos[0];
		theTop = scrollPos[1];
		var myImage = new Image;
		myImage.src='/gallery/'+s;
		image.src='/gallery/'+s;
		//alert(image.width+' x '+image.height);
		var imgSize = resizeImage(viewportwidth, viewportheight, myImage.width, myImage.height);
		
		//var imgSize = resizeImage(viewportwidth, viewportheight, image.naturalWidth, image.naturalHeight);
		// Remember image size for later
		lastImage = image.src;
		imageWidth = image.width;
		imageHeight = image.height;
		// Resize images
		image.width = imgSize[0];
		image.height = imgSize[1];
		var txtDesc = ns6? document.getElementById("popoutDesc") : document.all.popoutDesc;
		txtDesc.style.width=(Math.round(imgSize[0])-10)+'px';
		txtDesc.style.top=(Math.round(imgSize[1])-15)+'px';
		txtDesc.innerHTML=txt;
		changeOpac(20, 'pageWrap');
		box.style.width = image.width+'px';
		box.style.height = image.height+'px';
		box.style.backgroundColor='#000';
		box.style.left = ((viewportwidth-image.width)/2)+'px';
		box.style.top = theTop+5+'px';
		closeLink.style.top = '10px';
		closeLink.style.right = '15px';
		box.style.visibility="visible";
	} catch(err){
		return true;
	}
	return false;
}
 function keyPressHandler(e) {
	var kC  = (window.event) ?    // MSIE or Firefox?
			 event.keyCode : e.keyCode;
	var Esc = (window.event) ?   
			27 : e.DOM_VK_ESCAPE // MSIE : Firefox
	if(kC==Esc)
		hidebox();	
}

function GetViewportWidth(){
	var viewportwidth;
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
	{
	  viewportwidth = window.innerWidth;
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined'
	 && typeof document.documentElement.clientWidth !=
	 'undefined' && document.documentElement.clientWidth != 0)
	{
	   viewportwidth = document.documentElement.clientWidth;
	}
	// older versions of IE
	else
	{
	   viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
	}
	return viewportwidth;
}
function GetViewportHeight(){
	var viewportheight;
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
	{
	  viewportheight = window.innerHeight;
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined'
	 && typeof document.documentElement.clientWidth !=
	 'undefined' && document.documentElement.clientWidth != 0)
	{
	   viewportheight = document.documentElement.clientHeight;
	}
	// older versions of IE
	else
	{
	   viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	}
	return viewportheight;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function resizeImage(clientWidth, clientHeight, imgWidth, imgHeight){
	var convFactor = 1;
	if(imgHeight >= clientHeight+20){
		convFactor = clientHeight/imgHeight*0.98;
	} else if (imgWidth >= clientWidth){
		convFactor = clientWidth/imgWidth*0.98;
	}
	// Only downsize image
	if(convFactor > 0.98) convFactor=0.98;
	return [(imgWidth*convFactor), (imgHeight*convFactor)];
}

nn=(document.layers)?true:false; ie=(document.all)?true:false; 
function keyDown(e) { 
	var evt=(e)?e:(window.event)?window.event:null; 
	if(evt){ 
		var key=(evt.charCode)?evt.charCode: ((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0)); 
		if(key=="27") hidebox(); 
	} 
} 

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
	
}
document.onkeydown=keyDown; 
if(nn) document.captureEvents(Event.KEYDOWN);
