/* --------------------------------------------------------------------------------------------------------
AUTHOR:			Ryan Marincovich
DATE CREATED:	2008.09.30
File Purpose:	Diana Rose Common Javascript File
-------------------------------------------------------------------------------------------------------- */


// MAIN NAVIGATION FUNCTIONS/DATA ------------------------------------------

// load nav images
if (document.images) {
	note_on = new Image();
	note_on.src = "/_images/framework/music-note_on.png";
	note_off = new Image();
	note_off.src = "/_images/framework/music-note.png";
}

function navOn(which) {
	showNav(which);
	return true;
}
function navOff(which) {
	hideNav(which);
	return true;
}

// function to roll a nav button on
function navStayOn(which) {
	changeImages("nav_"+which,"nav_"+which+"_roll");
	return true;
}
// function to roll a nav button off
function navStayOff(which, state) {
	changeImages("nav_"+which,"nav_"+which+"_"+state);
	return true;
}
// END NAVIGATION FUNCTIONS ----------------------------------------





// AUDIO PLAYER FUNCTIONS ---------------------------------------

// function to play audio file through flash player controls
function playAudio(strFilename, intNewSongNum) {
	var playerControlsObj = document.getElementById('player_controls');
	// init html var and fill with content
	var strHTML = '';
	strHTML += '<div style="text-align:center; margin-bottom: 10px; display:none;">Playing: ' + strFilename + '</div>';
	strHTML += '<script type="text/javascript">';
	strHTML += '	AC_FL_RunContent(\'writeToID\',\'player_controls\',\'codebase\',\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\',\'width\',\'305\',\'height\',\'80\',\'wmode\',\'transparent\',\'title\',\'player_controls\',\'src\',\'/_framework/audio?strAudioFilename=/_uls/resources/' + strFilename + '\',\'quality\',\'high\',\'pluginspage\',\'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\',\'movie\',\'/_framework/audio?strAudioFilename=/_uls/resources/' + strFilename + '\');';
	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="305" height="80" title="Audio Player">';
	strHTML += '		<param name="movie" value="/_framework/audio.swf?strAudioFilename=/_uls/resources/' + strFilename + '" />';
	strHTML += '		<param name="quality" value="high" />';
	strHTML += '		<param name="wmode" value="transparent" />';
	strHTML += '		<embed src="/_framework/audio.swf?strAudioFilename=/_uls/resources/' + strFilename + '" quality="high" wmode="transparent" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="305" height="80"></embed>';
	strHTML += '	</object>';
	strHTML += '</noscript>';
	// set container html
	playerControlsObj.innerHTML = strHTML;
	// eval all script that was set in html
	var x = playerControlsObj.getElementsByTagName("script");
	for (var i=0; i < x.length; i++) {
		eval(x[i].text);
	}
	// update indicator icon
	if (intNewSongNum != intSongNum) {
		eval("changeImages('note"+intSongNum+"', 'note_off');");
		eval("changeImages('note"+intNewSongNum+"', 'note_on');");
	}
	intSongNum = intNewSongNum;
}

// function to load flash audio player on document load
function loadFirstSong() {
	if (strFirstSongFilename != '') {
		playAudio(strFirstSongFilename, 1);
		changeImages('note1', 'note_on');
	}
}

// END AUDIO PLAYER FUNCTIONS ---------------------------------------





// OVERLAY FUNCTIONS ----------------------------------------------
var isOverlayLoaded = false;

// build overlay objects (run onload)
function buildOverlay() {
	mainOverlayObj = eval(doc + '"mainOverlay"' + sty);
	overlayBGObj = eval(doc + '"overlayBG"' + sty);
	overlayVideoPlayerObj = eval(doc + '"videoPlayer"' + sty);
	overlayViewerWindowObj = document.getElementById('mainOverlay');
	overlayViewerBodyObj = document.getElementById('bodyContainer');
	windowHeight = overlayViewerWindowObj.offsetHeight;
	contentHeight = overlayViewerBodyObj.offsetHeight;
	overlayBGObj.height = Math.max(windowHeight, contentHeight) + "px";
	// set var to note objects are built and ready
	isOverlayLoaded = true;
}

// function to open video overlay
function videoPlayerOpen() {
	scroll(0, 0);
	mainOverlayObj.visibility = 'visible';
	overlayVideoPlayerObj.visibility = 'visible';
}

// define function to start playing a video in a div obj without reloading the page
function playVideo(strFlashSRC) {
	// open the overlay
	videoPlayerOpen();
	// get video title and frame objects
	var objVideoFrame = document.getElementById('videoFrame');
	// 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(\'codebase\',\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\',\'width\',\'400\',\'height\',\'345\',\'wmode\',\'transparent\',\'title\',\'Video\',\'src\',\'/_framework/flash_video?strVideoFilename=/_uls/resources/' + strFlashSRC + '\',\'quality\',\'high\',\'pluginspage\',\'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\',\'movie\',\'/_framework/flash_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=9,0,28,0" width="400" height="345" title="Video">';
	strHTML += '		<param name="movie" value="/_framework/flash_video.swf?strVideoFilename=/_uls/resources/' + strFlashSRC + '" />';
	strHTML += '		<param name="quality" value="high" />';
	strHTML += '		<param name="wmode" value="transparent" />';
	strHTML += '		<embed src="/_framework/flash_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="400" height="345"></embed>';
	strHTML += '	</object>';
	strHTML += '</noscript>';
	// set video frame html
	objVideoFrame.innerHTML = strHTML;
	// eval all script that was set in html
	var x = objVideoFrame.getElementsByTagName("script");
	for (var i=0; i < x.length; i++) {
		eval(x[i].text);
	}
}

// function to stop a video (clears innerHTML of video frame)
function stopVideo() {
	mainOverlayObj.visibility = 'hidden';
	overlayVideoPlayerObj.visibility = 'hidden';
	var objVideoFrame = document.getElementById('videoFrame');
	objVideoFrame.innerHTML = '';
}
// END OVERLAY FUNCTIONS ------------------------------------------




// 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);
	}
}

// vars for dropdown menus
var navTimer = null;
var currNav = null;
var navHideDelay = 500;
var isNavLoaded = false;

// build dropdown objects (run onload)
function buildNav() {
	aboutDropNavObj = eval(doc + '"aboutDropNav"' + sty);
	servicesDropNavObj = eval(doc + '"servicesDropNav"' + sty);
	productsDropNavObj = eval(doc + '"productsDropNav"' + sty);
	clientsDropNavObj = eval(doc + '"clientsDropNav"' + sty);
	supportDropNavObj = eval(doc + '"supportDropNav"' + sty);
	contactDropNavObj = eval(doc + '"contactDropNav"' + sty);
	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 ((which == "about") || (which == "services") || (which == "products") || (which == "clients") || (which == "support") || (which == "contact")) {
			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 == "about") || (which == "services") || (which == "products") || (which == "clients") || (which == "support") || (which == "contact")) {
			navTimer = setTimeout(which + "DropNavObj.visibility = 'hidden'", navHideDelay);
		}
	}
}

// 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";
}
