// JavaScript Document

	 // create object
     imageObj = new Image();
      
	 //Over
	 navImages = [
	 "/images/top/youthPrograms_over.png",
	 "/images/top/socialServices_over.png",
	 "/images/top/whatsNew_over.png",
	 "/images/top/aboutUs_over.png",
	 "/images/top/alumni_over.png"];
	 
	 //Drop down menus
	 dropDowns = new Array();
	 dropDowns[0] ="/images/top/aboutUs01.png";
	 dropDowns[1] ="/images/top/aboutUs02.png";
	 dropDowns[2] ="/images/top/aboutUs03.png";
	 dropDowns[3] ="/images/top/aboutUs04.png";
	 dropDowns[4] ="/images/top/aboutUs05.png";
	 dropDowns[5] ="/images/top/aboutUs06.png";
	 dropDowns[6] ="/images/top/aboutUs07.png";
	 dropDowns[7] ="/images/top/socialServices01.png";
	 dropDowns[8] ="/images/top/socialServices02.png";
	 dropDowns[9] ="/images/top/socialServices03.png";
	 dropDowns[10] ="/images/top/socialServices04.png";
	 dropDowns[11] ="/images/top/socialServices05.png";
	 dropDowns[12] ="/images/top/socialServices06.png";
	 dropDowns[13] ="/images/top/socialServices07.png";
	 dropDowns[14] ="/images/top/youthProg01.png";
	 dropDowns[15] ="/images/top/youthProg02.png";
	 dropDowns[16] ="/images/top/youthProg03.png";
	 dropDowns[17] ="/images/top/youthProg04.png";
	 dropDowns[18] ="/images/top/youthProg05.png";
	 dropDowns[19] ="/images/top/youthProg06.png";
	 dropDowns[20] ="/images/top/youthProg07.png";
	 dropDowns[21] ="/images/top/gradient.gif";
	 dropDowns[22] ="/images/top/menuTop.png";
	 dropDowns[23] ="/images/top/menuBottom01.png";
	 
	 getInvolved = new Array();
	 getInvolved[0]="/images/top/getInvolved_top.gif";
	 getInvolved[1]="/images/top/getInvolved_top_over.gif";
	 getInvolved[2]="/images/formExtendBack.gif";
	 
	 var dropDownMenus = ["youthDrop", "socialDrop", "aboutUsDrop"];

/***************** Initialize load events *****************/




$(document).ready(
function()
{				
	//Find if link should be highlighted
	
	//mouseOvers
	 $('div#navBar img.navigationLinks')
	.bind("mouseover", hideDropDown)
	.bind("mouseover", linkOver)
	.bind("mouseout", linkOut)
	.bind("mouseover", overBar) 
	.bind("mouseout", outBar);
	
	
	
	$('img#getInvoled').bind("mouseover",linkOver).bind("mouseout", linkOut); //Get involved image
	
	$('img#youthProgram, img#socialServices, img#aboutUs')
	.hover(dropOver, dropOut)
	.bind('barOff', outBar) //Drop down menus
	.unbind("mouseout", outBar);
	
	$('div.dropDown').hover(menuOver, menuOut);	 //Keep menus visible/hide menus
	currentLink();
	
	//Decode mail
	$('a.emailTxt').each(function(){ replaceMailText(this); })
	$('a.email').attr('href', replaceMail);
	
	
});

//Functions for when window is loaded
function windowLoaded()
{	
	preLoader(navImages);
	preLoader(dropDowns);
	preLoader(getInvolved);
}

$(window).load(windowLoaded);


var dropDownHovered = false;
var hideInterval = 1000; //Delay time for dropdown hide
//preload images
function preLoader(imgArray)
{
	for(i=0; i< imgArray.length; i++) 
	{
		imageObj.src = imgArray[i];
	}	
}
//Change mouseover source
function linkOver() 
{
	if(!ie6Test())//This was breaking in IE6 for some reason
	{
		var getSrc = /(.*)(\.\w{3})/; //Regexp to separate file name from extension
		var editSrc = $(this).attr('src').replace(getSrc, "$1_over$2"); //Add hover text
		$(this).attr('src', editSrc); //set source	
	}
}
//Change mouseover source backto default
function linkOut()
{
	if(!ie6Test()) //This was breaking in IE6 for some reason
	{
		var removeSrc = /(_over)/; //Regexp to find _over
		var editSrc = $(this).attr('src').replace(removeSrc, ""); //Remove _over
		$(this).attr('src', editSrc); //Insert new source	
	}
}	
//Blue Mouseover bar
function overBar()
{
	var barID =  '#' + this.id + "Bar";
	$(barID).show();
}
function outBar()
{
	var barID =  '#' + this.id + "Bar";
	$(barID).hide();
}
//Show drop down menu
function dropOver()
{
	var overID = this.id;
	dropDownHovered = true;
	switch(overID)
	{
		case "youthProgram" : 
		$("#youthDrop").show();
		break;
		
		case "socialServices" : 
		$("#socialDrop").show();
		break;
		
		case "aboutUs" : 
		$("#aboutUsDrop").show();
		break;
		
		default: 
		break;
	}
}
//Hide drop out menu after a period of time
function dropOut()
{
	dropDownHovered = false; 
	setTimeout(hideDropDown, hideInterval); 
}
//If the mouswe is not over a menu, hide it
function hideDropDown() 
{ 
	if(!dropDownHovered) 
	{
		$('div.dropDown').hide(); //Hide dropDown
		$('div#navBar img.navigationLinks').trigger('barOff'); //Hide all onbars 
	}
	
}
//Mouse is over menu
function menuOver() { dropDownHovered = true; }
//Hide menu when mouse leaves it
function menuOut()  
{
	dropDownHovered = false;
	dropOut();
}


function currentLink()
{
	//Match the navigation link to its own subsection
	var subDirs = [ 
				   [/youthPrograms/, "#youthProgram"], 
				   [/socialServices/, "#socialServices"], 
				   [/whatsNew/, "#whatsNew"], 
				   [/aboutUs/, "#aboutUs"], 
				   [/alumni/, "#alumni"],
				   [/getInvolved/, "#getInvoled"]
				   ];
	//If there is a match, switch to mouseover image and unbind mouseover events
	for(i = 0; i < subDirs.length; i++)
	{
		if(subDirs[i][0].test(window.location))
		{
			$(subDirs[i][1])
			.bind("isCurrent", linkOver)
			.bind("isCurrent", overBar)
			.trigger("isCurrent")
			.unbind("mouseover", overBar)
			.unbind("mouseover", linkOver)
			.unbind("mouseout", linkOut)
			.unbind("mouseout", outBar)
			.unbind("barOff");
			break;
		}
			
	}
	
}

/* Obscure */ 

// Email obfuscator script 2.1 by Tim Williams, University of Arizona
// Random encryption key feature by Andrew Moulden, Site Engineering Ltd
// This code is freeware provided these four comment lines remain intact
// A wizard to generate this code is at http://www.jottings.com/obfuscator/

//Modified by Nick Inhofe 2009

//spambot code keys (no, these aren't secret!)
var keyCodes = [ 
				["Kjhn2pSgp3qn@Kjhn2pSgp3qn.p2P", "c3QpEC0YtaMvx9gWHdmA82IfnyXRiKOsL4u1oDjFGzVPBNwhlZ5UbSrJTe7kq6"], //cameronhouse 0
				["FupU4E@4EFXtup5uDSX.utM", "HEnWghOuAKJikLb1NIctGw9yPpeM5sDY2dUVqQm7a48Z0BozjXR6SfvlxCr3TF"], //Monica 1		
				["fvPF@LwZPBvp7vaDP.vBs", "0CehjYsqvw16HWTL2ZXklJAP7fzDiu9dUG5N3EnrSFIRyQVgtoa84xMbcKmpBO"], //joel 2
				["cmeb@YiGpWm7bm6ep.mWP", "X0LcoSuykntbl3TDipWRxCgHYmI68O7915FVQsMfUzAPjEG4KBdvhJZNwaer2q"], // josh 
				["irDXaA2m2qX92sq@lHAs9rmarDqs.r9U", "IHmV7re3qBXCYxG6iULFNcz8KPRukTpanWAoE9sdtOwbvfyg215ZSl4j0JMDQh"], //youth ministries 4
				["J1yd.3Uqy@PqLoxSy4SUJo.Sxd", "3mf6OSsrukaPE5RebMVig8jhy7tLDZzXJxUWqQY2wo0Bl1dcK4CAHTFINv9pnG"], //sing.quan 5 
				["FbNAh@Fk23NOebOGh3.ONT", "WHpCR3MBjPzDiFwmLNygohlnSvdXauQEtZA4J2f80TObYe7V59kG1cUIqr6xKs"], //chris 6 
				["k7cz@i7kucF0VFwju.Fcr", "TVwXvMmjzfH9c4J2PtKoLxe1ENOkInl3gipU86aDFZhubqCGsy0Q5rYAdSW7RB"],  //mary 7
				["yqiYL4@9yY1b5Lu5i81.5b3", "fBnqeAyGTUM7oPWKr3X09iNHRLs1OCvpmZ65FhVbxJlQ4aEDw8zdS2kYgIjcut"], //alumni 8
				["YQZbxwN@5Qb9YxwixGv9.xYk", "p75oMBaTwUskuy6I9L3mrdSFVXhxJjQHtPvKGZfWcCObYNnz2giRlDe8EA041q"], //Raymond 9
				["ghOA@wngKplOElSTK.lpA", "i1dLoCTD9UewnVzpFgyGRhvkMlxP5QIKjO287NAtuBEHbWYsq4X0caJZr6mf3S"], //ming 10	
				["4qCuqyqn@2nXICVy6Vv5I.VCu", "5dB6ivKApEPM8moWlgnrRNITfc37Gq4Yz1w9OsXVhjuyCt0DkH2SxLbaUQFeZJ"], //Virginia 11
				["uS.FANFYtuS@urgqYNNqrzGV.rtf", "glRpt9v5iNodcTKCXELPhZO6D2xnfaeqVBm7zyrAu0Ms34JQSkW8bjHGwYFUI1"], //Ch.EDsearch 12
				["qG4LPS9S9LrBX@r9GZJdpRv.RrZ", "G6CIzbykeqmnFUQcM0Phtx2VjdHA7fai4XvrNBRYwKSTuOJZ5sgWLoE189p3lD"] //urbdocacademy 13
				
				];

function pubScure(keyCode)
{ 
  var coded = keyCode[0];
  var key = keyCode[1];
  
  shift= coded.length;
  link="";
  for (i=0; i<coded.length; i++) 
  {
    if (key.indexOf(coded.charAt(i))==-1) 
	{
      ltr = coded.charAt(i);
      link += (ltr);
    }
    else {     
      ltr = (key.indexOf(coded.charAt(i))-shift+key.length) % key.length;
      link += (key.charAt(ltr));
    }
  }
	return link;
}

//return decoded email href
var currentKey = /\d+(?=\?*)/;
function replaceMail()
{
	
	var keyCode = this.href.match(currentKey)[0];//keycode is before the subject line

	subjectLine = this.href.match(/\?.*/);
		 
	if(subjectLine) subjectLine = subjectLine[0]; //if there is a match, it is the first one
	else subjectLine = "";
	
	var theAddress = pubScure(keyCodes[keyCode]);
	
	return "mailto:" + theAddress + subjectLine; //decoded mail and the subject line
}
//return email text
function replaceMailText(mailAnchor, upperCase)
{
	var keyCode = mailAnchor.href.match(currentKey)[0];
	var theAddress = pubScure(keyCodes[keyCode]);
	if(upperCase) theAddress = theAddress.toUpperCase();
	$(mailAnchor).text(theAddress);
}

//Check if browser is IE6
function ie6Test()
{
	if(jQuery.browser.msie && jQuery.browser.version.substr(0,1) == "6")
	return true;
	else return false;
}