function preloadImages() {
	if (document.images) {
		for (var i = 0; i < preloadImages.arguments.length; i++) {
			(new Image()).src = preloadImages.arguments[i];
		}
	}
}
function roll(img_name, img_src){document[img_name].src = img_src;}

var isNav4, isIE4, isNav6 = false;
var range = "";
var styleObj = "";

if (navigator.appVersion.charAt(0) >= 4) {
	if (navigator.appName == "Netscape") {
		if (navigator.appVersion.charAt(0) >= 5) {isNav6 = true;}
		else {isNav4 = true;}
	}
	else {
		isIE4 = true;
		range = "all.";
		styleObj = ".style";
	}
}

function getObject(obj) {
	var theObj;
	if (typeof obj == "string") {
		if (isNav6) {
			theObj = document.getElementById(obj);
			if (theObj != null) theObj = theObj.style;
		}
		else {
			theObj = eval("document." + range + obj);
			if (theObj != null) theObj = eval("theObj" + styleObj);
		}
	}
	else {theObj = obj;}
	return theObj;
}

function show() {
	var theObj;
	
		for (var i = 0; i < show.arguments.length; i++) {
			theObj = getObject(show.arguments[i]);
			if (theObj != null) {
				theObj.display = "block";
				theObj.visibility = "visible";
			}
		}
}

function hide() {
	var theObj;
	for (var i = 0; i < hide.arguments.length; i++) {
		theObj = getObject(hide.arguments[i]);
		if (theObj != null) {
			theObj.display = "none";
			theObj.visibility = "hidden";
		}
	}
}

function deactivateVR() {mediaAction('btnMedia01'); hide('virtualTourBlock'); show('slideShowBlock');}
function externalWindow(url){var ExternalLink = window.open (url, "ExternalLink");}
 
/***********************************
	NEWSLETTERS
 ***********************************/
function gotoURL() {
	var Current = document.newsletterForm.newsletterFormSelect.selectedIndex;
	var pdfLink = document.newsletterForm.newsletterFormSelect.options[Current].value;
	window.open (pdfLink,'pdfWindow'); 
}

function goToGoogle() {
	var address = "";
	var GoogleAddress = "http://maps.google.com/maps?saddr=" + address + "&daddr=24243 Valencia Boulevard Valencia, CA 91355&hl=en";
	/*alert(GoogleAddress + address);*/
	window.location.href= GoogleAddress;
	return false;
}
 
 
/***********************************
	EXPANDING NAV
 ***********************************/
function navAction(tBox){
	var tCount = 3;
	for (var i = 1; i <= tCount; i++)
	{
		var tID = i;
		var tHead = "nav0" + tID;
		var tContent = "navBlock0" + tID;		
		if (tBox == tHead)
		{
			document.getElementById(tHead).className='leftNavBtnOn';
			show(tContent);
		}
		else
		{
			document.getElementById(tHead).className='leftNavBtn';
			hide(tContent);
		}
	}
}

/***********************************
	MEDIA BUTTONS
 ***********************************/
function mediaAction(mediaBox){
	var mediaCount = 2;
	for (var i = 1; i <= mediaCount; i++)
	{
		var mediaID = i;
		var mediaButton = "btnMedia0" + mediaID;
		if (mediaBox == mediaButton)
		{
			document.getElementById(mediaButton).className='btnMediaOn';
		}
		else
		{
			document.getElementById(mediaButton).className='btnMediaOff';
		}
	}
}


/***********************************
	FAQ BUTTONS
 ***********************************/
function faqAction(faqBox){
	var faqCount = 8;
	for (var i = 1; i <= faqCount; i++)
	{
		var faqID = i;
		var faqButton = "q0" + faqID;
		var faqContent = "a0" + faqID;
		if (faqBox == faqButton)
		{
			document.getElementById(faqButton).className='faqBtnOn';
			show(faqContent);
		}
		else
		{
			document.getElementById(faqButton).className='faqBtn';
			hide(faqContent);
		}
	}
}

/***********************************
	SLIDESHOW FUNCTION
 ***********************************/
function slideshow(sBox){
	var sCount = 6;
	for (var i = 1; i <= sCount; i++)
	{
		var sID = i;
		var sHead = "historyNav0" + sID;
		var sContent = "historyDate0" + sID;		
		if (sBox == sHead)
		{
			document.getElementById(sHead).className='current';
			show(sContent);
		}
		else
		{
			document.getElementById(sHead).className='hdrLinks';
			hide(sContent);
		}
	}
}
			

/***********************************
	HOMEPAGE FUNCTIONS 
 ***********************************/
function activateHome01() {hide('contentHome02','contentHome03','blockHome01'); show('contentHome01','blockHome02','blockHome03');}
function activateHome02() {hide('contentHome01','contentHome03','blockHome02'); show('contentHome02','blockHome01','blockHome03');}
function activateHome03() {hide('contentHome02','contentHome01','blockHome03'); show('contentHome03','blockHome02','blockHome01');}
function deactivateAll() {hide('contentHome01','contentHome02','contentHome03'); show('blockHome01','blockHome02','blockHome03');}

function deactivateHome01() {hide('contentHome01'); show('blockHome01');}
function deactivateHome02() {hide('contentHome02'); show('blockHome02');}
function deactivateHome03() {hide('contentHome03'); show('blockHome03');}

var panel01;
var panel02;
var panel03;
function closePanel01() {panel01 = setTimeout('deactivateHome01()',1000);}
function closePanel02() {panel02 = setTimeout('deactivateHome02()',1000);}
function closePanel03() {panel03 = setTimeout('deactivateHome03()',1000);}
function globalClose() {
	panel01 = setTimeout('deactivateHome01()',1000);
	panel02 = setTimeout('deactivateHome02()',1000);
	panel03 = setTimeout('deactivateHome03()',1000);
}
function clearPanelClose() {clearTimeout(panel01); clearTimeout(panel02); clearTimeout(panel03);}


/***********************************
	Map Overlay + Video Player 
 ***********************************/
//Windows Media Video Embed
function play(target, movid){
	document.getElementById(target).innerHTML=
	'<OBJECT ID="WMPlay" width="440" height="362" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"'
	+'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,70" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">'
	+'<PARAM name="URL" Value="'+movid+'">'
	+'<PARAM name="DisplaySize">'
	+'<PARAM name="AllowChangeDisplaySize" value="True">'
	+'<PARAM NAME="ShowControls">'
	+'<PARAM NAME="WindowlessVideo">'
	+'<PARAM NAME="ShowDisplay">'
	+'<PARAM NAME="ShowStatusBar">'
	+'<PARAM NAME="AutoStart" Value="TRUE">'
	+'<PARAM NAME="InvokeURLS" Value="False">'
	+'<PARAM NAME="stretchToFit" Value="True">'
	+'<embed name="WMplay" width="440" height="362" type="application/x-mplayer2"'
	+'pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/"'
	+'src="'+movid+'" Name="WMPlay" stretchToFit="True" AllowChangeDisplaySize="True" ShowControls="1" AutoStart="True" ShowDisplay="0" ShowStatusBar="1"><\/embed><\/object>'
}

function setSize(){
	var newHeight = getNewHeight('mapContainer');
	document.getElementById('mapBG').style.height = 'auto';
	document.getElementById('mapBG').style.height = newHeight + 'px';
}

function setSizePlanBG(){
	var newHeight = getNewHeight('modelPlan');
	document.getElementById('mapBG').style.height = 'auto';
	document.getElementById('mapBG').style.height = eval(newHeight + 50)+'px';
}

function setSizeContactBG(){
	var newHeight = getNewHeight('contactContainer');
	document.getElementById('mapBG').style.height = 'auto';
	document.getElementById('mapBG').style.height = newHeight + 'px';
}

function getNewHeight(container){
	var contentHeight = 0;
	if($('content'))
		contentHeight = $('content').getHeight();	
	var containerHeight = $(container).getHeight();	
	return larger(contentHeight, containerHeight) + 10;
}

function larger(val1, val2){
	var returner = val1;
	if(val2 > val1)
		returner = val2;
	return returner;
}



/***********************************
	Pop-up Window 
 ***********************************/
function addEvent(elm, evType, fn, useCapture){if(elm.addEventListener){elm.addEventListener(evType, fn, useCapture);return true;}else if (elm.attachEvent){var r = elm.attachEvent('on' + evType, fn);return r;}else{elm['on' + evType] = fn;}}
var newWindow = null;

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	
	closeWin();
		
	type = type.toLowerCase();
	
	if (type == "fullscreen"){
		strWidth = screen.availWidth;
		strHeight = screen.availHeight;
	}
	var tools="";
	if (type == "standard") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console" || type == "fullscreen") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}

function doPopUp(e)
{
//set defaults - if nothing in rel attrib, these will be used
var t = "standard";
var w = "900";
var h = "480";
//look for parameters
attribs = this.rel.split(" ");
if (attribs[1]!=null) {t = attribs[1];}
if (attribs[2]!=null) {w = attribs[2];}
if (attribs[3]!=null) {h = attribs[3];}
//call the popup script
popUpWin(this.href,t,w,h);
//cancel the default link action if pop-up activated
if (window.event) 
	{
	window.event.returnValue = false;
	window.event.cancelBubble = true;
	} 
else if (e) 
	{
	e.stopPropagation();
	e.preventDefault();
	}
}

function findPopUps()
{
var popups = document.getElementsByTagName("a");
for (i=0;i<popups.length;i++)
	{
	if (popups[i].rel.indexOf("popup")!=-1)
		{
		// attach popup behaviour
		popups[i].onclick = doPopUp;	
		// add info to title attribute to alert fact that it's a pop-up window
		popups[i].title = popups[i].title + " [Opens in pop-up window]";
		}
	}
}

addEvent(window, 'load', findPopUps, false);




function init() {preloadImages('images/btn_topnav_homes_on.gif', 'images/btn_topnav_town_on.gif', 'images/btn_topnav_schools_on.gif', 'images/btn_topnav_jobs_on.gif');}
window.onload = init;
   