var directory = 'images/index.html';

//add image file names to this array
var imagesOff = new Array(
	//NAV
	'navMinistries.html',
	'navMessages.html',
	'navEvents.html',
	'navServe.html',
	'navAbout.html',
	//sectImages
	'sectImage_5.html',
	'sectImage_4.html',
	'sectImage_3.html',
	'sectImage_2.html',
	'sectImage_1.html',
	//home right touts
	'hometout_justForKids.html',
	'hometout_studentSite.html',
	//home 4easy ways
	'ew1_attend.html',
	'ew2_register.html',
	'ew3_join.html',
	'ew4_serve.html'
	);

//add image file names to this array
var imagesOn = new Array(
	//NAV
	'navMinistries_on.html',
	'navMessages_on.html',
	'navEvents_on.html',
	'navServe_on.html',
	'navAbout_on.html',
	//sectImages
	'sectImage_5.html',
	'sectImage_4.html',
	'sectImage_3.html',
	'sectImage_2.html',
	'sectImage_1.html',
	//home right touts
	'hometout_justForKids_on.html',
	'hometout_studentSite_on.html',
	//home 4easy ways
	'ew1_attend_on.html',
	'ew2_register_on.html',
	'ew3_join_on.html',
	'ew4_serve_on.html'
	);

//add static image file names to this array
var imagesStatic = new Array(
	'navMinistries_on.html',
	'navMessages_on.html',
	'navEvents_on.html',
	'navServe_on.html',
	'navAbout_on.html',
	//sectImages
	'sectImage_5.html',
	'sectImage_4.html',
	'sectImage_3.html',
	'sectImage_2.html',
	'sectImage_1.html',
	//home right touts
	'hometout_justForKids_on.html',
	'hometout_studentSite_on.html',
	//home 4easy ways
	'ew1_attend.html',
	'ew2_register.html',
	'ew3_join.html',
	'ew4_serve.html'
	);
	
//add image 'names' to this array
var imageNames = new Array(
	'ministries',
	'messages',
	'events',
	'serve',
	'about',
	//sectImages
	'sectImage_5.html',
	'sectImage_4.html',
	'sectImage_3.html',
	'sectImage_2.html',
	'sectImage_1.html',
	//home right touts
	'kids',
	'students',
	//home 4easy ways
	'ew1',
	'ew2',
	'ew3',
	'ew4'
	
	);

var imageOff = new Array();
var imageOn = new Array();
var imageStatic = new Array();


// Preload rollover images
if (document.images) 
	{ // preload both states of each image and put filename in an associative array
		for (var i = 0; i < imagesOn.length; i++)
		{
			rolloverName = imageNames[i];
			imageOff[rolloverName] = new Image();
			imageOn[rolloverName] = new Image();
			imageStatic[rolloverName] = new Image();
			imageOff[rolloverName].src = directory + imagesOff[i];
			imageOn[rolloverName].src = directory + imagesOn[i];
			imageStatic[rolloverName].src = directory + imagesStatic[i];
		}
	}
//}


// On state activation
function turnOn(img, layer) {
	if (document.images && imageOn[img]) {
		
		// rollovers in layers in NS4 require a different image reference
		if (layer != null && document.layers) {
			if (typeof(layer) == 'object') layer.document.images[img].src = imageOn[img].src;
			else if (typeof(layer) == 'string') eval('document.layers["' + layer + '"].document.images[img].src = imageOn[img].src');
		}
		
		// non-layer rollovers in NS4 and all rollovers in other browsers
		else if (document.images[img]) document.images[img].src = imageOn[img].src;
	}
}


// Off state activation
function turnOff(img, layer) {
	if (document.images && imageOff[img]) {

		// rollovers in layers in NS4 require a different image reference
		if (layer != null && document.layers) {
			if (typeof(layer) == 'object') layer.document.images[img].src = imageOff[img].src;
			else if (typeof(layer) == 'string') eval('document.layers["' + layer + '"].document.images[img].src = imageOff[img].src');
		}
		
		// non-layer rollovers in NS4 and all rollovers in other browsers
		else if (document.images[img]) document.images[img].src = imageOff[img].src;
	}
}


//function to turn active navigation on
//'dirname' and 'file' are defined in the php doc that calls this function




//*********************************************
//*********************************************









//reload the window if Nav4 resized
function reloadPage(init) {  
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.pgW=innerWidth; document.pgH=innerHeight; onresize=reloadPage; }}
  else if (innerWidth!=document.pgW || innerHeight!=document.pgH) location.reload();
}

reloadPage(true);



//*********************************************
//*********************************************



//browser detection variables
  var platform = navigator.platform;
	var browser = navigator.appName;
	var version = parseInt(navigator.appVersion);
//function to load the approprate style sheet	
function drawStyle() 
{
   document.write("<link rel='stylesheet' href='/includes/css/screen.css' type='text/css'>");
}
drawStyle();


//MM Form Validation
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must be a valid e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must be a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}


function popIt(url,width,height)
{
var popped = window.open(url,"newWin","width=" + width + ",height=" + height);
popped.focus();
}

/*
function popRadio(url,width,height)
{
var radio = window.open(url,"radioWin","width=" + width + ",height=" + height);
radio.focus();
}
*/
//*********************************************
//Adjust 1st navigation
var section= 'home';
var w = window;
var l = location;

if(w.l.href.indexOf('ministries') != -1) {
	var section = 'ministries';
}
else
if(w.l.href.indexOf('messages') != -1) {
	var section = 'messages';
}
else
if(w.l.href.indexOf('events') != -1) {
	var section = 'events';
}
else
if(w.l.href.indexOf('serve') != -1) {
	var section = 'serve';
}
else
if(w.l.href.indexOf('about') != -1) {
	var section = 'about'
}

else
var page =""


function adjustNav()
{
	if (section != "home")
	{	imageOn[section].src = imageStatic[section].src;
		turnOn(section);
		imageOff[section].src = imageStatic[section].src;
		
		/*if (page != "")
		{
			imageOn[page].src = imageStatic[page].src;
			turnOn(page);
			imageOff[page].src = imageStatic[page].src;
		}*/
	}
}
	adjustNav();

/*************************************************************************
  This code is from Dynamic Web Coding 
  at http://www.dyn-web.com/
  Copyright 2001-3 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  Permission granted to use this code 
  as long as this entire notice is included.
*************************************************************************/

var cur_lyr;	// holds id of currently visible layer

function swapLayers(id) {
  if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
}

function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "visible";
}

function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "hidden";
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
} 

function registerForEvent(id) {
	//alert("Register for event "+id);
	window.open('includes/php/popEventRegisterTemplate7a92.html?eventId='+id,'register','height=425, width=600,scrollbars=no');
}

function openSeries(seriesId) {
	window.open('includes/php/popSeriesTemplatee688.html?seriesId='+seriesId,'Series','height=450, width=600,scrollbars=no');
}

function openMinistryForm(ministryId, action) {
	window.open('includes/php/popMinistryTemplatec293.html?ministryId='+ministryId+'&action='+action,'Ministry','height=450, width=600,scrollbars=no');
}

function onLoad() {
	//don't do anything
}
