//  Rotating headlines begins
var headline_arr = new Array();
var i = 0;

$(document).ready(function() {
	if($("#roller")) {
		$.get("/headlines.xml", function(data) {
			$(data).find('headline').each(function() {
				var item_text = $(this).text();
				headline_arr.push(item_text);
			});
			i=0;
			$("#roller").html(headline_arr[i]);
			$("#roller").animate( { top: "-4px" }, 250)
			setTimeout("rotateHeadlines()",4000);
		});
	}
	if($("#blueBar")) {
		$("#blueBar").html("<div id=\"scrollingText\">Did you know? In 2005, 19,000 visitors attended The Great ShakeUP at more than 2,000 churches. Those clubs grew 3.3%.</div>")
		scrollText()
	}
	if(navigator.appName.indexOf("Microsoft") >= 0 && navigator.appVersion.charAt(0) == 4) {
		var primaryNav = document.getElementById("primaryNav");
		for(i=0;i<=primaryNav.childNodes[0].childNodes.length;i+=2) {
			primaryNav.childNodes[0].childNodes[i].onmouseover = mouseOver;
			primaryNav.childNodes[0].childNodes[i].onmouseout = mouseOut;
		}
		function mouseOver() {
			if(this.parentNode.parentNode.id != "primaryNav") {
				this.style.backgroundColor = "#de6331";
			}
			if(this.childNodes[2]) {
				for(i=0;i<this.childNodes[2].childNodes.length;i++) {
					this.childNodes[2].childNodes[i].onmouseover = mouseOver;
					this.childNodes[2].childNodes[i].onmouseout = mouseOut;
				}
				this.childNodes[2].style.display = "block";
			}
		}
		function mouseOut() {
			if(this.parentNode.parentNode.id != "primaryNav") {
				this.style.background = "#f5853c";
			}
			if(this.childNodes[2]) {
				this.childNodes[2].style.display = "none";
			}
		}
	}
});
function rotateHeadlines() {
	i++
	if(i==headline_arr.length) {
		i=0;
	}
	$("#roller").animate( { top: "-24px" },	250, "swing", function() {
			$("#roller").css("top","16px");
			$("#roller").html(headline_arr[i]);
			$("#roller").animate( { top: "-4px" }, 250, "swing", setTimeout("rotateHeadlines()",4000) );
		}
	);
}
function scrollText() {
	$("#scrollingText").animate( { textIndent: "-800px" }, 20000, "linear", function() {
		$("#scrollingText").css("text-indent","750px");
		scrollText();
	});
}
//  Image security begins
function copyProtect(warning) {
	if(warning == "noAwanaTXT") {
		alert("Attention! The logo you are clicking is intellectual property of Awana Clubs International. Logos that are available for use by churches registered with Awana can be found on our clip art page at https://c.na3.visual.force.com/apex/clipart. ");
	} else {
		alert("The name Awana is a registered trademark. This logo graphic is a copyrighted image of Awana. Logos that are available for use by churches registered with Awana can be found on our clip art page at https://c.na3.visual.force.com/apex/clipart.");
		// window.location.href = "http://www.awana.org/";
	}
}
//  Image security ends
//  Video begins
function showVideo() {
	document.getElementById("awanaVideo").style.display = "block";
}
function hideVideo() {
	document.getElementById('awanaVideo').style.display='none';
}
function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}
function formSend(movie,text) {
	getFlashMovie(movie).sendTextToFlash(text);
}
//  Video ends
//  Search begins
function keypress(e, terms) {
	var charCode = (e.which) ? e.which : e.keyCode;
	if(charCode==13) {
		search(terms);
	}
}
function search(terms) {
	window.location='http://search.awana.org/search?q='
	+ escape(terms)
	+ '&site=Awana_All&client=Awana_All&proxystylesheet=Awana_All&output=xml_no_dtd';
}
function clearSearch(clear) {
	if(clear == "clear" && document.getElementById("tbxSearch").value == "Search...") {
		document.getElementById("tbxSearch").value = "";
		document.getElementById("tbxSearch").style.color = "#000000";
	} else if(clear == "fill" && document.getElementById("tbxSearch").value == "") {
		document.getElementById("tbxSearch").style.color = "#9E9E9E";
		document.getElementById("tbxSearch").value = "Search...";
	}
}
//  Search ends
//  HPS Volunteer Page Begins
function volunteerInfo(info,status) {
	var volunteerFields = new Array("popupBox","director","headCoach","coaches","zoneLeader","hCoordinator","others");
	for(vField=0;vField<volunteerFields.length;vField++) {
		document.getElementById(volunteerFields[vField]).style.display = "none";
	}
	document.getElementById("popupBox").style.display = status;
	document.getElementById(info).style.display = status;
}
//  HPS Volunteer Page Ends
//  Spanish Discover Awana Page Starts
function uncheckOther(other) {
	document.getElementById(other).checked = false;
}
//  Spanish Discover Awana Page Ends
//  Parent page begins
var currentDesc;
function hideDescription() {
	document.getElementById(currentDesc).style.display = "none";
}
function showDescription(desc) {
	if(currentDesc) {
		hideDescription();
	}
	if(window.innerWidth) {
		document.getElementById(desc).style.left = ""+(window.innerWidth-420)/2+"px";
		document.getElementById(desc).style.top = ""+(window.innerHeight-174)/2+"px";
	} else {
		document.getElementById(desc).style.left = ""+(document.documentElement.clientWidth-420)/2+"px";
		document.getElementById(desc).style.top = ""+(document.documentElement.clientHeight-174)/2+"px";
	}
	
	document.getElementById(desc).style.display = "block";
	currentDesc = desc;
}
//  Parent page ends
//  Dreamweaver Image Swap Begins
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_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];}
}
//  Dreamweaver Image Swap Ends