// JavaScript Document

function setPrefix(elmName) {
	if (document.getElementById != null) {
		return document.getElementById(elmName);
	}
	if (document.all != null) {
		return document.all[elmName];
	}
}

function setNavDefault() {
	var url = window.location;
	var myloc = window.location.href;
	var locarray = myloc.split("/");
	var arraytext = locarray[(locarray.length-2)];
	
	var navid;
	
	switch (arraytext) {
		case "home":
			navid = 'navbar_02';
			break;
		case "services":
			navid = 'navbar_03';
			break;
		case "gallery":
			navid = 'navbar_04';
			break;
		case "contact":
			navid = 'navbar_05';
			break;
	}
	
	setPrefix(navid).src = '../images/' + navid + '_on.jpg';
}

function changeNav(image,state) {
	image.src = '../images/' + image.id + '_' + state + '.jpg';
	
	setNavDefault();
}

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;

function showImagePopup(filenameArray, captionArray, index) {
	unlim_index = index;
	g_filenameArray = filenameArray;
	g_captionArray = captionArray;

	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="../images/close.gif" style="cursor:pointer" onclick="hideImagePopup();" /></td>' +
		'</tr><tr>' +
			'<td>' +
				'<table border="0" width="420" cellpadding="5" cellspacing="0" style="background:#f2f2f2; border:5px solid #ffffff;height:420px;"><tr>' +
					'<td><img id="unlimGalleryImage" src="../photos/' + filenameArray[index] + '" style="cursor:pointer" onclick="hideDivPicture();" /></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="../images/prevarrow.gif" onclick="prevUnlim()" style="cursor:pointer" /></div><div style="float:right"><img src="../images/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_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_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_filenameArray[0];
		setPrefix("unlimCaption").innerHTML = g_captionArray[0];
		unlim_index = 0;
	}
	else {
		setPrefix("unlimGalleryImage").src = '../photos/' + g_filenameArray[unlim_index+1];
		setPrefix("unlimCaption").innerHTML = g_captionArray[unlim_index+1];
		unlim_index = unlim_index+1;
	}
}
