/* --------------------------------------------------------------------------------------------------------
AUTHOR:			Jeremy Burgeson
DATE CREATED:	2009.11.11
Client:         Horizon Pool Supply
File Purpose:	Common Javascript File
-------------------------------------------------------------------------------------------------------- */

/* ---------- OVERLAY AND MEDIA DATA AND FNS ------------------------------------------------ */
var isOverlayLoaded = false;

// build overlay objects (run onload)
function buildOverlay() {
	
	// global overlay elements
	overlayMainObj = document.getElementById('mainOverlay');
	overlayBodyObj = document.getElementById('container');
	overlayBGObj = document.getElementById('overlayBG');
	overlayGalleryObj = document.getElementById('photoGallery');
	
	// calc height
	windowHeight = overlayMainObj.offsetHeight;
	contentHeight = overlayBodyObj.offsetHeight;
	overlayBGObj.style.height = Math.max(windowHeight, contentHeight) + "px";
	
	// set var to note objects are built and ready
	isOverlayLoaded = true;
}

// open overlay
function overlayOpen(intResourceID, strLayerType) {
	scroll(0, 0);
	overlayMainObj.style.visibility = 'visible';
	var strTargetHTML = '';
	if (strLayerType == 'photos') {
		overlayGalleryObj.style.visibility = 'visible';
		var objContentContainer = overlayGalleryObj;
		objContentContainer.innerHTML = '';
		var url = "/_page_templates/gallery-detail.php?intResourceID="+intResourceID;
	}
	objContentContainer.innerHTML = strTargetHTML;
	ajaxOpenDetails(intResourceID, url, objContentContainer);
}

// ajax function to show detail in overlay
function ajaxOpenDetails(intResourceID, url, layerObject) {
	var xmlHttp = GetXmlHttpObject();
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
			layerObject.innerHTML += xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

var currGalleryImage = null;

function turnOnFirstImage(which) {
	if (currGalleryImage == null) {
		currGalleryImage = which;
	}
	document.getElementById("galleryMain" + currGalleryImage).style.visibility = 'visible';
	document.getElementById("tinyThumbOn" + currGalleryImage).style.visibility = 'visible';
	document.getElementById("descriptionMain" + currGalleryImage).style.visibility = 'visible';
}

function galleryNavOver(which) {
	if ((currGalleryImage != null) && (currGalleryImage != which)) {
		document.getElementById("galleryMain" + currGalleryImage).style.visibility = 'hidden';
	document.getElementById("tinyThumbOn" + currGalleryImage).style.visibility = 'hidden';
	document.getElementById("descriptionMain" + currGalleryImage).style.visibility = 'hidden';
	}
	currGalleryImage = which;
	document.getElementById("galleryMain" + currGalleryImage).style.visibility = 'visible';
	document.getElementById("tinyThumbOn" + currGalleryImage).style.visibility = 'visible';
	document.getElementById("descriptionMain" + currGalleryImage).style.visibility = 'visible';
	window.status = " ";
}

// close gallery
function closeGallery() {
	overlayGalleryObj.style.visibility = 'hidden';
	overlayMainObj.style.visibility = 'hidden';
	overlayGalleryObj.innerHTML = '';
}




// form field functions
function setSearchField() {
	var ffSearch = document.forms.frmSearch.q;
	if (!ffSearch.value) {
		ffSearch.style.color = "#999";
		ffSearch.value = " - Search - Powered by Google - ";
	}
}
function clearField(which) {
	if (which.value.indexOf('Search') >= 0) {
		which.value = "";
		which.style.color = "#000";
	}
}

