function rollOver(image) {
	newpath = image.src;
	if(/_off/.test(newpath)) {
		newpath = newpath.substr(0, newpath.length-8);
		newpath = newpath + '_on.jpg';
		image.src = newpath;
	}
}

function rollOut(image) {
	newpath = image.src;
	if(/_on/.test(newpath)) {
		newpath = newpath.substr(0, newpath.length-7);
		newpath = newpath + '_off.jpg';
		image.src = newpath;
	}
}

function setPrefix(elmName) {
	if (document.getElementById != null) {
		return document.getElementById(elmName);
	}
	if (document.all != null) {
		return document.all[elmName];
	}
}

function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 100;
  var opacity = options.opacity || 60;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');          // Create the layer.
	tnode.style.position='absolute';                 	// Position absolutely
	tnode.style.top='0px';                           	// In the top
	tnode.style.left='0px';                          	// Left corner of the page
	tnode.style.overflow='hidden';                   	// Try to avoid making scroll bars            
	tnode.style.display='none';                      	// Start out Hidden
	tnode.onclick = function() {
		grayOut(false);
		hideImagePopup();
	}

	tnode.id='darkenScreenObject';                   	// Name it so we can find it later
	tbody.appendChild(tnode);                           // Add it to the web page
	dark=document.getElementById('darkenScreenObject'); // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if ( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
    	var pageWidth = document.body.scrollWidth+'px';
    	var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
    	var pageWidth = document.body.offsetWidth+'px';
    	var pageHeight = document.body.offsetHeight+'px';
    } else {
    	var pageWidth='100%';
    	var pageHeight='100%';
    }  
	
	// hide select boxes for ie6 +
	var isIE6 = ((navigator.userAgent.indexOf("MSIE 6.") != -1) && (navigator.userAgent.indexOf("Opera") == -1));
	if (isIE6) {
		var arrSelect = document.getElementsByTagName("select");
		for  (i=0;i<arrSelect.length;i++) {
			arrSelect[i].style.visibility = "hidden";
		}
	}
	
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';                          
  } else {
	// show select boxes for ie6 +
	var isIE6 = ((navigator.userAgent.indexOf("MSIE 6.") != -1) && (navigator.userAgent.indexOf("Opera") == -1));
	if (isIE6) {
		var arrSelect = document.getElementsByTagName("select");
		for  (i = 0;i<arrSelect.length;i++) {
			arrSelect[i].style.visibility = "visible";
		}
	}
    dark.style.display='none';
  }
}

var unlim_index = 0;
var g_filenameArray;
var g_captionArray;
var g_galleryID = 0;

function showImagePopup(filenameArray, captionArray, galleryID, index) {
	unlim_index = index;
	g_filenameArray = filenameArray;
	g_captionArray = captionArray;
	g_galleryID = galleryID;

	posy = (window.innerHeight || document.documentElement.clientHeight)/2 + (window.pageYOffset || document.documentElement.scrollTop) - 536/2;
	if (posy < 0) posy = 0;
	posx = (window.innerWidth || document.documentElement.clientWidth)/2 - 330;
	//grayOut(true);
	var divPopup = setPrefix('divPopup');

	if (!divPopup) {
		var pBody = document.getElementsByTagName('body')[0];
		divPopup = document.createElement('div');
		divPopup.style.position = 'absolute';
		divPopup.style.width = '670px';
		divPopup.style.top = posy + 'px';
		divPopup.style.left = posx + 'px';
		divPopup.style.display = 'none';
		divPopup.style.zIndex = 300;
		divPopup.id = 'divPopup';
		pBody.appendChild(divPopup);
		divPopup = setPrefix('divPopup');
	} else {
		divPopup.style.top = posy + 'px';
		divPopup.style.left = posx + 'px';
		//grayOut(true);
	}
	
	divPopup.innerHTML = '' +
		'<table border="0" cellpadding="0" cellspacing="0" style="border:1px solid #000000"><tr valign="top">' +
			'<td align="right" style="background:#ffffff"><img src="../pic/close.gif" style="cursor:pointer" onclick="hideImagePopup();" /></td>' +
		'</tr><tr>' +
			'<td>' +
				'<table border="0" width="360" cellpadding="5" cellspacing="0" style="background:#f2f2f2; border:5px solid #ffffff"><tr>' +
					'<td><img id="unlimGalleryImage" src="../photos/' + galleryID + '/orig_' + filenameArray[index] + '" style="cursor:pointer" onclick="hideImagePopup();" /></td>' +
				'</tr></table>' +
			'</td>' +
		'</tr><tr>' +
			'<td style="padding:10px; text-align:left; background:#ffffff" id="unlimCaption">'+captionArray[index]+'</td>' +
		'</tr><tr>' +
			'<td style="padding:0px; background:#fffffF"><br /><br /><div style="float:left"><img src="../pic/prevarrow.gif" onclick="prevUnlim()" style="cursor:pointer" /></div><div style="float:right"><img src="../pic/nextarrow.gif" style="cursor:pointer" onclick="nextUnlim()" /></div></td>' +
		'</tr></table>';

	divPopup.style.display = 'block';
}

function hideImagePopup(){
	//grayOut(false);
	setPrefix("divPopup").style.display = 'none';
}

function prevUnlim(){
	if(unlim_index == 0){
		setPrefix("unlimGalleryImage").src = '../photos/' + g_galleryID + '/orig_' + g_filenameArray[g_filenameArray.length-1];
		setPrefix("unlimCaption").innerHTML = g_captionArray[g_captionArray.length-1];
		unlim_index = g_filenameArray.length-1;
	}
	else {
		setPrefix("unlimGalleryImage").src = '../photos/' + g_galleryID + '/orig_' + g_filenameArray[unlim_index-1];
		setPrefix("unlimCaption").innerHTML = g_captionArray[unlim_index-1];
		unlim_index = unlim_index-1;
	}
}

function nextUnlim(){
	if(unlim_index == g_filenameArray.length-1){
		setPrefix("unlimGalleryImage").src = '../photos/' + g_galleryID + '/orig_' + g_filenameArray[0];
		setPrefix("unlimCaption").innerHTML = g_captionArray[0];
		unlim_index = 0;
	}
	else {
		setPrefix("unlimGalleryImage").src = '../photos/' + g_galleryID + '/orig_' + g_filenameArray[unlim_index+1];
		setPrefix("unlimCaption").innerHTML = g_captionArray[unlim_index+1];
		unlim_index = unlim_index+1;
	}
}