// JavaScript Document

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}



// this is for the staff page
function init() {
var pathname = location.pathname;
var filename = pathname.substr(pathname.lastIndexOf("/")+1,pathname.length);	
		
		document.getElementById('navbar_legacy').style.display = "none";

		if (document.getElementById)
			var x = document.getElementById('navbar').getElementsByTagName('div');
		else if (document.all)
			var x = document.all['navbar'].all.tags('div');
		else return;
		
		for (var i=0;i<x.length;i++)
		{
		
			document.getElementById(x[i+1].id).style.display = "none";
			new Effect.Opacity(x[i+1].id, { from: 1.0, to: 0.0, duration: 0.01 });
			// set the mouseover and mouseout
			document.getElementById(x[i].id).onmouseover = function () {new Effect.Opacity('over_'+this.id, { from: 0.0, to: 1.0, duration: 0.1 });}
			document.getElementById(x[i].id).onmouseout =  function () {new Effect.Opacity('over_'+this.id, { from: 1.0, to: 0.0, duration: 0.1 });}


			var targetlink2;
			targetlink2 = x[i].id+'.html';
			j = (i) / 2;
			if (i == 0) {
			document.getElementById(x[i+1].id).innerHTML = "<img border=0 width=\"109\" src=\"images/nav/"+x[i].id+"_s2.gif\" onclick=\"nav_go('"+x[i].id+"','"+j+"');\">";
			document.getElementById(x[i].id).style.width = "109px";
			} else {

			document.getElementById(x[i+1].id).innerHTML = "<img border=0 src='images/nav/"+x[i].id+"_s2.gif' onclick=\"nav_go('"+x[i].id+"','"+j+"');\">";
			}
			// set background images
			document.getElementById(x[i].id).className = "navbutton";
			document.getElementById(x[i+1].id).className = "navbutton";
			document.getElementById(x[i].id).style.backgroundImage = "url('images/nav/"+x[i].id+"_s1.gif')";
			document.getElementById(x[i+1].id).style.backgroundImage = "url('images/nav/"+x[i].id+"_s2.gif')";

			window.setTimeout("document.getElementById('"+x[i+1].id+"').style.display = 'block';",100);
			i += 1;
			
		}


		
	if ((filename == "index.php") || (filename == "index2.php") || (filename == "")) {
		MM_preloadImages('images/715_escape.jpg', 'images/715_prayer.gif', 'images/715_leadership.jpg');
		rotate();
	}

	if ((filename == "staff_main.html")) {	
		if (document.getElementById)
			var x = document.getElementById('staff_mouseovers').getElementsByTagName('div');
		else if (document.all)
			var x = document.all['staff_mouseovers'].all.tags('div');
		else return;
		
		for (var i=0;i<x.length;i++)
		{
			document.getElementById(x[i+1].id).style.display = "none";
			new Effect.Opacity(x[i+1].id, { from: 1.0, to: 0.0, duration: 0.01 });

			// set the mouseover and mouseout
			document.getElementById(x[i].id).onmouseover = function () {new Effect.Opacity(this.id+'2', { from: 0.0, to: 1.0, duration: 0.3 });}
			document.getElementById(x[i].id).onmouseout =  function () {new Effect.Opacity(this.id+'2', { from: 1.0, to: 0.0, duration: 0.3 });}


			var targetlink;
			targetlink = x[i].id;
			targetlink = targetlink.substring(3);

//			document.getElementById(x[i].id).onclick =  "function () {window.location.href = 'staff_"+x[i].id+".html';}"
	
			// set background images
			document.getElementById(x[i].id).style.cursor = "pointer";
			document.getElementById(x[i+1].id).innerHTML = "<a href=\"staff_"+targetlink+".html\"><img border=0 src='images/director2/"+x[i].id+"_s2.jpg'></a>";
			document.getElementById(x[i].id).style.backgroundImage = "url('images/director2/"+x[i].id+"_s1.jpg')";


//			document.getElementById(x[i+1].id).style.backgroundImage = "url('images/director2/"+x[i].id+"_s2.jpg')";

			document.getElementById(x[i].id).style.width = "198px";
			document.getElementById(x[i].id).style.height = "346px";
		window.setTimeout("document.getElementById('"+x[i+1].id+"').style.display = \"block\";", 100);
			i += 1;
			
		}
	}
	

}

function nav_go(obj3,target) {
var urltable = new Array();
urltable[0] = "whatis.html";
urltable[1] = "staff_main.html";
urltable[2] = "leaders.html";
urltable[3] = "applications.html";
urltable[4] = "prayer.php";
urltable[5] = "donate.html";
urltable[6] = "merch.html";
urltable[7] = "parents.html";
urltable[8] = "contact.php";

	new Effect.Opacity('over_'+obj3, { from: 1.0, to: 0.0, duration: 0.01 });
	window.setTimeout("window.location.href = '"+urltable[target]+"'",20);
}

var rotateindex;
rotateindex = -1;

function doIt(img,url,j) {
if (j != null) {
document.getElementById("rotatelink[0]").className = "rotator_off";
document.getElementById("rotatelink[1]").className = "rotator_off";
document.getElementById("rotatelink[2]").className = "rotator_off";
document.getElementById("rotatelink["+j+"]").className = "rotator_on";
}

//	Effect.BlindUp('homepage_gfx');
//	Effect.BlindDown('homepage_gfx2');

// make sure the container DIV is holding the new image
document.getElementById('homepage_gfxholder').style.backgroundImage = 'url(images/'+img+')';

// fade out the gfxholder2 - nested DIV
new Effect.Opacity('homepage_gfxholder2', { from: 1.0, to: 0.0, duration: 0.4 });

// change the nested DIV to the new image
window.setTimeout("document.getElementById('homepage_gfxholder2').style.backgroundImage = 'url(images/"+img+")';",400);

// fade the nested DIV back in again
window.setTimeout("new Effect.Opacity('homepage_gfxholder2', { from: 0.0, to: 1.0, duration: 0.01});",401);


// set the nested DIV to go to the link when clicked
document.getElementById('homepage_gfxholder2').onclick = function () { window.location.href = url };
}

var rotatehash;

function rotate(i,m) {
if (i != null) {
rotatehash = null;
}
if ((m == rotatehash) || (rotatehash == null)) {
	// if we are specifying a certain index in i
	// then we need to change the rotateindex accordingly
	// if not we just advance
	if (i != null) {
	rotateindex = i;
	} else {
	rotateindex += 1;
	}
	
	
	// are we at the end of the cycle? if so, restart
	if ((rotateindex > 2)) { 
	rotateindex = 0;
	}
	
	var rotatelist = new Array();
	rotatelist[0] = "breakout_splash.jpg";
	rotatelist[1] = "715_prayer.gif";
	rotatelist[2] = "715_leadership.jpg";

	
	var rotateurl = new Array();
	rotateurl[0] = "breakout.html";
	rotateurl[1] = "prayer.php";
	rotateurl[2] = "applications.html";

//	rotatehash = Math.random();
//	window.setTimeout("rotate('','"+rotatehash+"')",3000);



    doIt(rotatelist[rotateindex],rotateurl[rotateindex],rotateindex);

	// only one loop at a time	
//		if (i == null) {
		rotatehash = Math.random(1,100);
		window.setTimeout("rotate(null,'"+rotatehash+"')",10000);
//		}
	
	}
}

