/* --------------------------------------------------------------------------------------------------------
AUTHOR:			Ryan Marincovich
DATE CREATED:	2007.12.07
File Purpose:	Structural Graphics Common Javascript File
Revisions:
	2009.08.20.RAM - Added functionality to landing page build for photo overlay
-------------------------------------------------------------------------------------------------------- */


// MAIN NAVIGATION FUNCTIONS/DATA ------------------------------------------

// load nav images
if (document.images) {
	nav_who_on = new Image();
	nav_who_on.src = "/_images/nav/nav_who_on.gif";
	nav_who_off = new Image();
	nav_who_off.src = "/_images/nav/nav_who_off.gif";
	nav_what_on = new Image();
	nav_what_on.src = "/_images/nav/nav_what_on.gif";
	nav_what_off = new Image();
	nav_what_off.src = "/_images/nav/nav_what_off.gif";
	nav_clients_on = new Image();
	nav_clients_on.src = "/_images/nav/nav_clients_on.gif";
	nav_clients_off = new Image();
	nav_clients_off.src = "/_images/nav/nav_clients_off.gif";
	nav_work_on = new Image();
	nav_work_on.src = "/_images/nav/nav_work_on.gif";
	nav_work_off = new Image();
	nav_work_off.src = "/_images/nav/nav_work_off.gif";
	nav_contact_on = new Image();
	nav_contact_on.src = "/_images/nav/nav_contact_on.gif";
	nav_contact_off = new Image();
	nav_contact_off.src = "/_images/nav/nav_contact_off.gif";
	nav_arrow_on = new Image();
	nav_arrow_on.src = "/_images/framework/nav_arrow_on.gif";
	nav_arrow_off = new Image();
	nav_arrow_off.src = "/_images/framework/nav_arrow_off.gif";
}

// function to roll a nav button on
function navOn(which) {
	showNav(which);
	return true;
}
// function to roll a nav button off
function navOff(which) {
	hideNav(which);
	return true;
}

// function to roll a subnav panel on
function navSubOn(subwhich) {
	showSubNav(subwhich);
	return true;
}
// function to roll a subnav panel off
function navSubOff(subwhich) {
	hideSubNav(subwhich);
	return true;
}

function navStayOn(which) {
	changeImages("nav_"+which,"nav_"+which+"_on");
}

function navStayOff(which) {
	changeImages("nav_"+which,"nav_"+which+"_off");
}

// vars for dropdown menus
var navTimer = null;
var navSubTimer = null;
var thumbTimer = null;
var currNav = null;
var currSubNav = null;
var currThumb = null;
var navHideDelay = 500;
var isNavLoaded = false;

// build dropdown objects (run onload)
function buildNav() {
	whoDropNavObj = eval(doc + '"whoDropNav"' + sty);
	whatDropNavObj = eval(doc + '"whatDropNav"' + sty);
	applicationsSubDropNavObj = eval(doc + '"applicationsSubDropNav"' + sty);
	sg_exclusivesSubDropNavObj = eval(doc + '"sg_exclusivesSubDropNav"' + sty);
	sensory_effectsSubDropNavObj = eval(doc + '"sensory_effectsSubDropNav"' + sty);
	applicationsSubImageObj = eval(doc + '"applicationsSubImage"' + sty);
	sg_exclusivesSubImageObj = eval(doc + '"sg_exclusivesSubImage"' + sty);
	sensory_effectsSubImageObj = eval(doc + '"sensory_effectsSubImage"' + sty);
	clientsDropNavObj = eval(doc + '"clientsDropNav"' + sty);
	workDropNavObj = eval(doc + '"workDropNav"' + sty);
	contactDropNavObj = eval(doc + '"contactDropNav"' + sty);
	// set var to note objects are built and ready
	isNavLoaded = true;
}

// shows a dropdown menu, hides any other dropdown that is currently showing
function showNav(which) {
	if (isNavLoaded) {
		clearTimeout(navTimer);
		navTimer = null;
		if ((currNav != null) && (currNav != which)) {
			eval(currNav + "DropNavObj.visibility = 'hidden'");
			if (currSubNav != null) {
				eval(currSubNav + "SubDropNavObj.visibility = 'hidden'");
			}
		}
		if ((which == "who") || (which == "what") || (which == "clients") || (which == "work") || (which == "contact") || (which == "gallery")) {
			currNav = which;
			eval(currNav + "DropNavObj.visibility = 'visible'");
		}
	}
}
// hides a dropdown menu on a time delay
function hideNav(which) {
	if (isNavLoaded) {
		clearTimeout(navTimer);
		navTimer = null;
		if ((which == "who") || (which == "what") || (which == "clients") || (which == "work") || (which == "contact") || (which == "gallery")) {
			navTimer = setTimeout(which + "DropNavObj.visibility = 'hidden'", navHideDelay);
		}
	}
}

// shows a dropdown menu, hides any other dropdown that is currently showing
function showSubNav(subwhich) {
	if (isNavLoaded) {
		clearTimeout(navSubTimer);
		navSubTimer = null;
		if ((currSubNav != null) && (currSubNav != subwhich)) {
			eval(currSubNav + "SubDropNavObj.visibility = 'hidden'");
			eval(currSubNav + "SubImageObj.background = 'none'");
		}
		if ((subwhich == "applications") || (subwhich == "sg_exclusives") || (subwhich == "sensory_effects")) {
			currSubNav = subwhich;
			eval(currSubNav + "SubDropNavObj.visibility = 'visible'");
			eval(currSubNav + "SubImageObj.background = '#ceebf9'");
		}
	}
}
// hides a dropdown menu on a time delay
function hideSubNav(subwhich) {
	if (isNavLoaded) {
		clearTimeout(navSubTimer);
		navSubTimer = null;
		if ((subwhich == "applications") || (subwhich == "sg_exclusives") || (subwhich == "sensory_effects")) {
			navSubTimer = setTimeout(subwhich + "SubDropNavObj.visibility = 'hidden'", navHideDelay);
			eval(currSubNav + "SubImageObj.background = 'none'");
		}
	}
}



// PHOTO EXPAND FUNCTIONS --------------------------------------------------

// show thumb popup
function showThumbExpand(which) {
	clearTimeout(thumbTimer);
	thumbTimer = null;
	if ((currThumb != null) && (currThumb != which)) {
		eval("page" + currThumb + "ThumbObj.visibility = 'hidden'");
	}
	currThumb = which;
	eval("page" + currThumb + "ThumbObj.visibility = 'visible'");
}

// hide thumb popup
function hideThumbExpand(which) {
	clearTimeout(thumbTimer);
	thumbTimer = null;
	thumbTimer = setTimeout("page" + which + "ThumbObj.visibility = 'hidden'", navHideDelay);
}

// VIDEO LANDING PAGE FUNCTIONS -------------------------------------------

// set vars
var isResizeDone = false;

// resize bg image
var resizeBg = function() {
	var imageHeight = self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	var imageWidth = self.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
	var siteBG = document.getElementById('bgImage');
	if (imageWidth > imageHeight) {
		siteBG.width = imageWidth;
		siteBG.height = imageWidth;
	} else {
		siteBG.height = imageHeight;
		siteBG.width = imageHeight;
	}
}

// OVERLAY OBJECTS --------------------------------------------------------

var isOverlayLoaded = false;

// build overlay objects (run onload)
function buildOverlay() {
	overlayF2FObj = eval(doc + '"overlayF2F"' + sty);
	overlayBGformObj = eval(doc + '"overlayBGform"' + sty);
	overlayBGflashObj = eval(doc + '"overlayBGflash"' + sty);
	
	overlayViewerFlashObj = eval(doc + '"overlayViewerFlash"' + sty);
	overlayViewerFlashContentObj = eval(doc + '"overlayViewerFlashContent"' + sty);
	
	overlayViewerImageObj = eval(doc + '"overlayViewerImage"' + sty);
	overlayViewerImageContentObj = eval(doc + '"overlayViewerImageContent"' + sty);
	
	overlayViewerGlobalObj = eval(doc + '"overlayViewerGlobal"' + sty);
	
	overlayContentObj = document.getElementById('overlayContent');
	overlayViewerWindowObj = document.getElementById('overlayF2F');
	overlayViewerBodyObj = document.getElementById('bodyContainer');
	
	windowHeight = overlayViewerWindowObj.offsetHeight;
	contentHeight = overlayViewerBodyObj.offsetHeight;
	
	overlayBGformObj.height = Math.max(windowHeight, contentHeight) + "px";
	overlayBGflashObj.height = Math.max(windowHeight, contentHeight) + "px";
	
	// global defs for ajax overlay
	overlayAjaxObj = eval(doc + '"overlayAjax"' + sty);
	overlayBGObj = eval(doc + '"overlayBG"' + sty);
	
	overlayAjaxWindowObj = document.getElementById('overlayAjax');
	windowHeightAjax = overlayAjaxWindowObj.offsetHeight;
	contentHeightAjax = overlayViewerBodyObj.offsetHeight;
	overlayBGObj.height = Math.max(windowHeightAjax, contentHeightAjax) + "px";
	// set var to note objects are built and ready
	isOverlayLoaded = true;
}

var isLandingOverlayLoaded = false;

// build overlay objects (run onload)
function buildLandingOverlay() {
	overlayBGLandingObj = eval(doc + '"overlayBGLanding"' + sty);
	overlayBGPhotoObj = eval(doc + '"overlayBGPhoto"' + sty);
	overlayViewerLandingObj = eval(doc + '"overlayViewerLanding"' + sty);
	overlayViewerPhotoObj = eval(doc + '"overlayViewerPhoto"' + sty);
	overlayContentObj = document.getElementById('overlayContent');
	overlayContentPhotoObj = document.getElementById('overlayContentPhoto');
	overlayViewerWindowObj = document.getElementById('overlayViewerLanding');
	overlayViewerWindow2Obj = document.getElementById('overlayViewerPhoto');
	overlayViewerBodyObj = document.getElementById('siteContainer');
	windowHeight = overlayViewerWindowObj.offsetHeight;
	window2Height = overlayViewerWindow2Obj.offsetHeight;
	contentHeight = overlayViewerBodyObj.scrollHeight;
	//alert(contentHeight);
	overlayBGLandingObj.height = Math.max(windowHeight, contentHeight) + "px";
	overlayBGPhotoObj.height = Math.max(window2Height, contentHeight) + "px";
	// set var to note objects are built and ready
	isLandingOverlayLoaded = true;
}

// center landing page overlay
function centerLandingOverlay() {
	overlayLandingContentVideoObj = document.getElementById('overlayLandingContentVideo');
	overlayLandingContentPhotoObj = document.getElementById('overlayLandingContentPhoto');
	// set top margin for content
	if (windowHeight) {
		intTopMargin = Math.round((windowHeight - 570) / 2);
		if (intTopMargin < 0) intTopMargin = 0;
	} else {
		intTopMargin = 0;
	}
	strTopMargin = '' + intTopMargin + 'px';
	//alert('strTopMargin = ' + strTopMargin + '\nVideo: ' + overlayLandingContentVideoObj.style.paddingTop + '\nPhoto: ' + overlayLandingContentPhotoObj.style.paddingTop);
	overlayLandingContentVideoObj.style.paddingTop = strTopMargin;
	overlayLandingContentPhotoObj.style.paddingTop = strTopMargin;
	//alert('strTopMargin = ' + strTopMargin + '\nVideo: ' + overlayLandingContentVideoObj.style.paddingTop + '\nPhoto: ' + overlayLandingContentPhotoObj.style.paddingTop);
}

// function to open f2f form overlay
function f2fOpen() {
	scroll(0, 0);
	overlayF2FObj.visibility = 'visible';
}
// function to close f2f form overlay
function f2fClose() {
	overlayF2FObj.visibility = 'hidden';
}

// function to open viewer overlay
function viewerOpen(which) {
	scroll(0, 0);
	eval("overlayViewer"+which+"Obj.visibility = 'visible';");
	if (which == "Flash") {
		overlayViewerFlashContentObj.display = "block";
	} else if (which == "Image") {
		overlayViewerImageContentObj.display = "block";
	}
}
// function to close viewer overlay
function viewerClose(which) {
	eval("overlayViewer"+which+"Obj.visibility = 'hidden';");
	if (which == "Flash") {
		overlayViewerFlashContentObj.display = "none";
	} else if (which == "Image") {
		overlayViewerImageContentObj.display = "none";
	} else if (which == "Landing") {
		overlayContentObj.innerHTML = '';
	} else if (which == "Global") {
		overlayContentObj.innerHTML = '';
	}
}

// function to open ajax overlay
function ajaxOverlayOpen(strActiveLayer, strSourceURL) {
	scroll(0, 0);
	// object for btome div
	overlayShowObj = eval(doc + '"' + strActiveLayer + '"' + sty);
	
	overlayAjaxObj.visibility = 'visible';
	overlayShowObj.visibility = 'visible';
	
	var xmlHttp = GetXmlHttpObject();
	var objAjaxContainer = document.getElementById(strActiveLayer);
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
			objAjaxContainer.innerHTML = xmlHttp.responseText;
		}
	}
	var url = strSourceURL;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

// function to open ajax overlay
function ajaxOverlayClose(strActiveLayer) {
	// object for btome div
	overlayShowObj = document.getElementById(strActiveLayer);
	overlayShowObjStyle = eval(doc + '"' + strActiveLayer + '"' + sty);
	
	overlayAjaxObj.visibility = 'hidden';
	overlayShowObjStyle.visibility = 'hidden';
	overlayShowObj.innerHTML = '';
}

// function to play landing page video
function playLandingVideo(strFlashSRC) {
	centerLandingOverlay();
	viewerOpen("Landing");
	var overlayContentObj = document.getElementById('overlayContent');
	// init html var and fill with content
	var strHTML = '';
	strHTML += '<div style="text-align:center; margin-bottom: 10px; display:none;">Playing: ' + strFlashSRC + '</div>';
	strHTML += '<script type="text/javascript">';
	strHTML += '	AC_FL_RunContent(\'writeToID\',\'overlayContent\',\'codebase\',\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\',\'width\',\'640\',\'height\',\'480\',\'wmode\',\'transparent\',\'title\',\'Video\',\'src\',\'sg_landing_video?strVideoFilename=' + strFlashSRC + '\',\'quality\',\'high\',\'pluginspage\',\'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\',\'movie\',\'sg_landing_video?strVideoFilename=' + strFlashSRC + '\');';
	strHTML += '<\/script>';
	strHTML += '<noscript>';
	strHTML += '	<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="640" height="480" title="Video">';
	strHTML += '		<param name="movie" value="sg_landing_video.swf?strVideoFilename=' + strFlashSRC + '" />';
	strHTML += '		<param name="quality" value="high" />';
	strHTML += '		<param name="wmode" value="transparent" />';
	strHTML += '		<embed src="sg_landing_video.swf?strVideoFilename=' + strFlashSRC + '" quality="high" wmode="transparent" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="640" height="480"></embed>';
	strHTML += '	</object>';
	strHTML += '</noscript>';
	// set video frame html
	overlayContentObj.innerHTML = strHTML;
	// eval all script that was set in html
	var x = overlayContentObj.getElementsByTagName("script");
	for (var i=0; i < x.length; i++) {
		eval(x[i].text);
	}
}

// function to show landing page photo
function showLandingPhoto(strImageSRC) {
	centerLandingOverlay();
	viewerOpen("Photo");
	var overlayContentObj = document.getElementById('overlayContentPhoto');
	// init html var and fill with content
	var strHTML = '';
	strHTML += '<img src="' + strImageSRC + '" class="float_left" hspace="0" border="0" vspace="0" alt="Image" />';
	// set video frame html
	overlayContentObj.innerHTML = strHTML;
	// eval all script that was set in html
	var x = overlayContentObj.getElementsByTagName("script");
	for (var i=0; i < x.length; i++) {
		eval(x[i].text);
	}
}

// function to play landing page video
function playGlobalVideo(strFlashSRC) {
	viewerOpen("Global");
	var overlayContentObj = document.getElementById('overlayContent');
	// init html var and fill with content
	var strHTML = '';
	strHTML += '<div style="text-align:center; margin-bottom: 10px; display:none;">Playing: ' + strFlashSRC + '</div>';
	strHTML += '<script type="text/javascript">';
	strHTML += '	AC_FL_RunContent(\'writeToID\',\'overlayContent\',\'codebase\',\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\',\'width\',\'460\',\'height\',\'390\',\'wmode\',\'transparent\',\'title\',\'Video\',\'src\',\'/_framework/sg_global_video?strVideoFilename=/_uls/resources/' + strFlashSRC + '\',\'quality\',\'high\',\'pluginspage\',\'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\',\'movie\',\'/_framework/sg_global_video?strVideoFilename=/_uls/resources/' + strFlashSRC + '\');';
	strHTML += '<\/script>';
	strHTML += '<noscript>';
	strHTML += '	<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="460" height="390" title="Video">';
	strHTML += '		<param name="movie" value="/_framework/sg_global_video.swf?strVideoFilename=/_uls/resources/' + strFlashSRC + '" />';
	strHTML += '		<param name="quality" value="high" />';
	strHTML += '		<param name="wmode" value="transparent" />';
	strHTML += '		<embed src="/_framework/sg_global_video.swf?strVideoFilename=/_uls/resources/' + strFlashSRC + '" quality="high" wmode="transparent" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="460" height="390"></embed>';
	strHTML += '	</object>';
	strHTML += '</noscript>';
	// set video frame html
	overlayContentObj.innerHTML = strHTML;
	// eval all script that was set in html
	var x = overlayContentObj.getElementsByTagName("script");
	for (var i=0; i < x.length; i++) {
		eval(x[i].text);
	}
}

// UTILITY FUNCTIONS/DATA --------------------------------------------------

// sets cursor focus on the field given by param (formID.fieldID)
function formFocus(strFormAndFieldIDs) {
	if (isPageLoaded) {
		eval("document.forms." + strFormAndFieldIDs + ".focus();");
	} else {
		setTimeout("formFocus('" + strFormAndFieldIDs + "')", 100);
	}
}

// swap one or more images
function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			var argArray = arguments[i].split('.');
			var objName;
			if ((document.layers && argArray.length > 1) || argArray.length <= 1) {
				objName = eval("document." + arguments[i]);
			} else {
				objName = eval("document." + argArray[argArray.length - 1]);
			}
			objName.src = eval(changeImages.arguments[i+1] + ".src");
		}
	}
}

// dhtml layer variables for cross-browser compatability
if (document.layers) {	// Netscape 4
	doc = "document[";
	conDoc = "document";
	sty = "]";
	htm = ".document";
	cls = "].className";
} else if (document.getElementById) {	// NS 6 or IE 5 and up (W3C compliant browsers).
	doc = "document.getElementById(";
	conDoc = "document.getElementById(";
	sty = ").style";
	htm = ".document";
	cls = ").className";
} else if (document.all) {	// IE 4
	doc = "document.all[";
	conDoc = "document.all[";
	sty = "].style";
	htm = "";
	cls = "].className";
}