/************************************************************************************************
Runtime Inline Page Additions
*************************************************************************************************/
/* Hack to hide the contents of a page when include it within an IFrame of Another Page.*/
if(window.location.href.indexOf("HideContent=1")>0)
{
	document.write("<link rel='stylesheet' type='text/css' href='/clientimages/34035/webresources/HideContent.css'>");
}


/************************************************************************************************
DHTML Management Functions
*************************************************************************************************/
function GetContentIFrameDocument()
{
	return window.top.frames["contentFrame"].document;
}

function ContentIncluder(elementToInsertIFrameBefore,URLToLoadInIFrameOrIDofFormToSubmitIntoFrame,IFrameOnLoadCallback)
{
	//set up the Iframe to draw in page Content			
	var n = "contentFrame";
	var iFrame = document.createElement("IFRAME");
	iFrame.width = 400;
	iFrame.height = 0;
	iFrame.frameBorder = 0;
	iFrame.scrolling = "NO";
	iFrame.style.paddingBottom = "25px";			
	iFrame.id = n;
	iFrame.name = n;		
	
	//create spinning loading waitThing
	var waitDiv = document.createElement("div");
	waitDiv.id = "WaitThing";
	waitDiv.style.fontFamily="font-family:Trebuchet MS;";
	var cent = document.createElement("center");
	waitDiv.appendChild(cent);
	var img = document.createElement("img");
	img.src = "/clientimages/34035/images/loading_tinyred.gif";			
	cent.appendChild(img);
	cent.appendChild(document.createTextNode(" Loading content..."));
	
	//insert the waitThing and iFrame
	elementToInsertIFrameBefore = GetElement(document, elementToInsertIFrameBefore);	
	if (!elementToInsertIFrameBefore)
	{
		//can't find the insertionpoint, lets try to find one.
		var insertionPoint = GetElement(document,"bodyCopy");
		if (insertionPoint)
		{
			insertionPoint.appendChild(waitDiv);
			insertionPoint.appendChild(iFrame);
		}
		else
		{
			document.body.appendChild(document.createTextNode("Unable to locate the insertion point for the content to include."));
		}
	}
	else
	{
		elementToInsertIFrameBefore.parentNode.insertBefore(waitDiv,elementToInsertIFrameBefore);			
		elementToInsertIFrameBefore.parentNode.insertBefore(iFrame,elementToInsertIFrameBefore);
	}
	
	//var iFrameDoc = window.frames[n].document;				
	//iFrameDoc.write("<center><img src='/clientimages/34035/images/loading_tinyred.gif' width='10' height='10' hspace=3><font size=2 face='sans-serif''><i>Loading...</i></font></center>"); //this causes a History item in IE
    
    //check to see if this looks like an form element on the page or not.
    var possibleForm = GetElement(window.document,URLToLoadInIFrameOrIDofFormToSubmitIntoFrame);
    if (possibleForm)
    {
        //hey, this looks like a form element. Submit it.
        possibleForm.target = n;
        possibleForm.submit();
    }
    else
    {        
        //nope, this is likely a URL, set the src.
	    iFrame.src = URLToLoadInIFrameOrIDofFormToSubmitIntoFrame + "&HideContent=1";
    }
	
	addEvent(iFrame,"load",ContentIncluderBeforeIFrameCallback);
	addEvent(iFrame,"load",IFrameOnLoadCallback);
	addEvent(iFrame,"load",ContentIncluderAfterIFrameCallback);
	
}

//fired when the Content is loaded within
function ContentIncluderBeforeIFrameCallback()
{	
	window.document.getElementById("WaitThing").style.display = "none";
	var iFrameDoc = GetContentIFrameDocument();
	anchors = getElementsByTagName(iFrameDoc,"A");
	for (var i = 0; i < anchors.length ; i++)
	{
		anchors[i].target = "_parent";
	}
}

function ContentIncluderAfterIFrameCallback()
{
	autofitIframe(GetElement(document,"contentFrame"),GetContentIFrameDocument());
}


function ElementMover(doc, objOrObjIDToMove, objOrObjIDTargetDestination, SourceCleanserCallBack, IsUseEncloser)
{
	var src = GetElement(doc, objOrObjIDToMove);
	var dest = GetElement(doc, objOrObjIDTargetDestination);

	//call the cleanser callback
	if (SourceCleanserCallBack)
	{
		src = SourceCleanserCallBack(src,doc);
	}
	
	//create a new encloser since we probably lost one, and align it left
	var newEncloser = doc.createElement('div');
	newEncloser.style.textAlign = "left";

	//first remove the src node
	src.parentNode.removeChild(src);
	
	//append it to the new parent
	newEncloser.appendChild(src);
	
	//then append the node infront of it.
	dest.parentNode.insertBefore(newEncloser,dest);
}

//simple wrapper function for getElementById
function GetElement(doc, objOrObjID)
{
	if (typeof(objOrObjID)=="string")
	{
		return GetByID(doc, objOrObjID);
	}
	else
	{
		return objOrObjID;
	}
}

//simple wrapper function for getElementById
function GetByID(doc, elementName)
{
	return doc.getElementById(elementName);
}

//Returns an array of elements that have the classname
function getElementsByClassName(doc,classname) {
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = doc.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

//Returns an array of elements that have the classname
function getElementsByTagName(doc, tagName) {
	if (doc.all)
	{
		els = doc.all.tags(tagName);
	}
	else
	{
		els = doc.getElementsByTagName(tagName);
	}
	return els;
}

function IsWindowInFrame()
{
	return (window.top != window);
}

function RemoveChildren(el)
{
    if (el && el.childNodes)
    {
        var l = el.childNodes.length
        for(var i=0; i< l; i++)
        {
            el.removeChild(el.childNodes[0]);
        }
    }
}

/************************************************************************************************
Utility Functions
*************************************************************************************************/

/*Makes querystring items available via an array */
// sm-querystring.js - Query String Convenience Functions - Copyright (c) 2006 ScriptingMagic.com
//deleted

//Parses a parameter from a querystring-likes string and returns the value
function ParseLikeQueryString(queryString, qsParam)
{
	var regexS = "(^|[\\?&])+"+qsParam+"=([^&#]*)";
	var regex = new RegExp( regexS, "i" );
	var tmpURL = queryString;
	var results = regex.exec( tmpURL );
	if( results == null )
		return "";
	else
		return results[2];
}

//Parses a parameter from the URL querystring based on name and returns the value
function gup(qsParam)
{
	return ParseLikeQueryString(window.location.href,qsParam);
}

//fits an IFrame to the size of the content
function autofitIframe(iFrameObject, DocWithinIFrame){
	if (!window.opera && !document.mimeType && document.all && document.getElementById)
	{
		iFrameObject.style.height = DocWithinIFrame.body.offsetHeight + 0 + "px";
	}
	else if(document.getElementById)
	{
		iFrameObject.style.height = DocWithinIFrame.body.scrollHeight + 10 + "px"
	}
}

function dateFormat(aDate, displayPat){
    /********************************************************
    *   Valid Masks:
    *   !mmmm = Long month (eg. January)
    *   !mmm = Short month (eg. Jan)
    *   !mm = Numeric date (eg. 07)
    *   !m = Numeric date (eg. 7)
    *   !dddd = Long day (eg. Monday)
    *   !ddd = Short day (eg. Mon)
    *   !dd = Numeric day (eg. 07)
    *   !d = Numeric day (eg. 7)
    *   !yyyy = Year (eg. 1999)
    *   !yy = Year (eg. 99)
   ********************************************************/

    intMonth = aDate.getMonth();
    intDate = aDate.getDate();
    intDay = aDate.getDay();
    intYear = aDate.getFullYear();

    var months_long =  new Array ('January','February','March','April',
       'May','June','July','August','September','October','November','December')
    var months_short = new Array('Jan','Feb','Mar','Apr','May','Jun',
       'Jul','Aug','Sep','Oct','Nov','Dec')
    var days_long = new Array('Sunday','Monday','Tuesday','Wednesday',
       'Thursday','Friday','Saturday')
    var days_short = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat')

    var mmmm = months_long[intMonth]
    var mmm = months_short[intMonth]
    var mm = intMonth < 9?'0'+ (1 + intMonth) + '':(1+intMonth)+'';
    var m = 1+intMonth+'';
    var dddd = days_long[intDay];
    var ddd = days_short[intDay];
    var dd = intDate<10?'0'+intDate+'':intDate+'';
    var d = intDate+'';
    var yyyy = intYear;

    century = 0;
    while((intYear-century)>=100)
        century = century + 100;

    var yy = intYear - century
    if(yy<10)
        yy = '0' + yy + '';

    displayDate = new String(displayPat);

    displayDate = displayDate.replace(/!mmmm/i,mmmm);
    displayDate = displayDate.replace(/!mmm/i,mmm);
    displayDate = displayDate.replace(/!mm/i,mm);
    displayDate = displayDate.replace(/!m/i,m);
    displayDate = displayDate.replace(/!dddd/i,dddd);
    displayDate = displayDate.replace(/!ddd/i,ddd);
    displayDate = displayDate.replace(/!dd/i,dd);
    displayDate = displayDate.replace(/!d/i,d);
    displayDate = displayDate.replace(/!yyyy/i,yyyy);
    displayDate = displayDate.replace(/!yy/i,yy);

    return displayDate;
}

/************************************************************************************************
Event Management Functions
*************************************************************************************************/

/* Adds an even to fire on page load. */

function addOnloadEvent(fnc){

addEvent(window,"load",fnc);

}

/**
 * addEvent & removeEvent -- cross-browser event handling
 * Copyright (C) 2006-2007  Dao Gottwald
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Contact information:
 *   Dao Gottwald  <dao at design-noir.de>
 *
 * @version  1.1.7
 
 */

function addEvent(o, type, fn) {
	o.addEventListener(type, fn, false);
}
function removeEvent(o, type, fn) {
	o.removeEventListener(type, fn, false);
}
/*@cc_on if (!window.addEventListener) {
	var addEvent = function(o, type, fn) {
		if (!o._events) o._events = {};
		var queue = o._events[type];
		if (!queue) {
			o._events[type] = [fn];
			if (!o._events._callback)
				o._events._callback = function(e) { theEvent._callListeners(e, o) };
			o.attachEvent("on" + type, o._events._callback);
		} else if (theEvent._fnIndex(o, type, fn) == -1)
			queue.push(fn);
		else return;
		theEvent._mem.push([o, type, fn]);
	};
	var removeEvent = function(o, type, fn) {
		var i = theEvent._fnIndex(o, type, fn);
		if (i < 0) return;
		var queue = o._events[type];
		if (queue.calling) {
			delete queue[i];
			if (queue.removeListeners)
				queue.removeListeners.push(i);
			else
				queue.removeListeners = [i];
		} else
			if (queue.length == 1)
				theEvent._detach(o, type);
			else
				queue.splice(i, 1);
	};
	var theEvent = {
		AT_TARGET: 2,
		BUBBLING_PHASE: 3,
		stopPropagation: function() { this.cancelBubble = true },
		preventDefault: function() { this.returnValue = false },
		_mem: [],
		_callListeners: function(e, o) {
			e.stopPropagation = this.stopPropagation;
			e.preventDefault = this.preventDefault;
			e.currentTarget = o;
			e.target = e.srcElement;
			e.eventPhase = e.currentTarget == e.target ? this.AT_TARGET : this.BUBBLING_PHASE;
			switch (e.type) {
				case "mouseover":
					e.relatedTarget = e.fromElement;
					break;
				case "mouseout":
					e.relatedTarget = e.toElement;
			}
			var queue = o._events[e.type];
			queue.calling = true;
			for (var i = 0, l = queue.length; i < l; i++)
				if (queue[i])
					queue[i].call(o,e);
			queue.calling = null;
			if (!queue.removeListeners)
				return;
			if (queue.length == queue.removeListeners.length) {
				this._detach(o, e.type);
				return;
			}
			queue.removeListeners = queue.removeListeners.sort(function(a,b){return a-b});
			var i = queue.removeListeners.length;
			while (i--)
				queue.splice(queue.removeListeners[i], 1);
			if (queue.length == 0)
				this._detach(o, e.type);
			else
				queue.removeListeners = null;
		},
		_detach: function(o, type) {
			o.detachEvent("on" + type, o._events._callback);
			delete o._events[type];
		},
		_fnIndex: function(o, type, fn) {
			var queue = o._events[type];
			if (queue)
				for (var i = 0, l = queue.length; i < l; i++)
					if (queue[i] == fn)
						return i;
			return -1;
		},
		_cleanup: function() {
            if (!this.mem) return;
			for (var m, i = 0; m = this._mem[i]; i++)
				if (m[1] != "unload" || m[2] == this._cleanup)
					removeEvent(m[0], m[1], m[2]);
		}
	};
	addEvent(window, "unload", theEvent._cleanup);
} @*/


/* Adds event to fire when a page unloads */
function addUnloadEvent(fnc){
	addEvent(window,"unload",fnc);
}








/************************************************************************************************
Ministy Content Page <-> Group Handling
*************************************************************************************************/

//This gcpArray simply maps the GroupID to a ContentPageID since the site doesn't provide this out of box.
var xxxxxx = 0;
var yyyyyy = 0;
var gcpArray = new Array();  //stores the GroupID, ContentPage associations
gcpArray.push(new Array(28505, 383327)); 	//AAA
gcpArray.push(new Array(28557, 383322));  	//Adult Life
gcpArray.push(new Array(28506, 383341));	//Binge on Books
gcpArray.push(new Array(28631, 388180));	//Cinemania
gcpArray.push(new Array(28582, 383323));	//Couples with a Purpose
gcpArray.push(new Array(35275, 508201));	//Dinners for Eight
gcpArray.push(new Array(28583, 342838));	//Families in Fellowship
gcpArray.push(new Array(32239, 504329));	//Financial Peace
gcpArray.push(new Array(32240, 504335));	//Front Porch
gcpArray.push(new Array(28699, 383330));	//Ivanresters
gcpArray.push(new Array(28963, 394743));	//Koinonia
gcpArray.push(new Array(28545, 383328));	//Nifty Fifties Dinner Club
gcpArray.push(new Array(30375, 444613));	//Prayer Shawl Ministry
gcpArray.push(new Array(28700, 383324));	//Sidekicks
gcpArray.push(new Array(28595, 383326));	//Sparks
gcpArray.push(new Array(31564, 487790));	//Men's Bible Studies
gcpArray.push(new Array(29013, 396336));	//Men's Bible Studies - The Life You've Always Wanted
gcpArray.push(new Array(29014, 396339));	//Men's Bible Studies - A Study of Romans
gcpArray.push(new Array(30475, 446497));	//Men's Minstries
gcpArray.push(new Array(28904, 392435));	//Women's Bible Studies
gcpArray.push(new Array(29015, 396340));	//Women's Bible Studies - The Gospel of John
gcpArray.push(new Array(29016, 396343));	//Women's Bible Studies - Philippians: God's Guide to Joy
gcpArray.push(new Array(31561, 483539));	//Women in the Word
gcpArray.push(new Array(31657, 490134));	//Beautiful Womanhood
gcpArray.push(new Array(30714, 458752));      //Women's Summer Coffee and Book Club
gcpArray.push(new Array(34067, 576274));      //Serve God, Save the Planet

gcpArray.push(new Array(29281, 404973));	//Coffee Break

gcpArray.push(new Array(29017, 396346));	//Choir
gcpArray.push(new Array(29097, 400251));	//Praise Teams
gcpArray.push(new Array(29098, 400258));	//Instrumentalists

gcpArray.push(new Array(28688, 388868));	//Kingdom Kids Red
gcpArray.push(new Array(28689, 388871));	//Kingdom Kids Purple
gcpArray.push(new Array(28690, 342831));	//Kingdom Kids Blue
gcpArray.push(new Array(28691, 388872));	//Kingdom Kids Green
gcpArray.push(new Array(28692, 388874));	//Kingdom Kids Yellow
gcpArray.push(new Array(28693, 388888));	//Kingdom Kids Orange
gcpArray.push(new Array(28694, 388890));	//Kingdom Kids - Little Stars
gcpArray.push(new Array(28697, 388892));	//Kingdom Kids Summer Program

gcpArray.push(new Array(28960, 394416));	//Junior Campers / Camp Ivanrest (1st)
gcpArray.push(new Array(28681, 342832));	//Camp Ivanrest (2-3)
gcpArray.push(new Array(28898, 392427));	//Camp Ivanrest (4-5)
gcpArray.push(new Array(28900, 392429));	//Camp Ivanrest (6)

gcpArray.push(new Array(28686, 388891));	//Basic Living (10th - 12th Grades)
gcpArray.push(new Array(28684, 388885));	//Basic Training (8th & 9th Grades)
gcpArray.push(new Array(28683, 388877));	//Boot Camp (7th Grade)
gcpArray.push(new Array(28696, 388904));	//Cadets
gcpArray.push(new Array(28687, 342834));	//GEMS
gcpArray.push(new Array(28902, 389390));	//7-8ers
gcpArray.push(new Array(28839, 392130));	//Peak3
gcpArray.push(new Array(xxxxxx, yyyyyy));	//zzzzzzzzzzzzz

//Inefficient search of to retrieve a Groups ministry page.
function GetMinistryPageIDFromGroupID(GroupID)
{
	for (var i=0; i < gcpArray.length; i++)
	{
		if (GroupID==gcpArray[i][0]) return gcpArray[i][1];
	}
	return null;
}

//Inefficient search of to retrieve a Ministry's group page.
function GetGroupIDFromMinistryPageID(MinistryPageID)
{
	for (var i=0; i < gcpArray.length; i++)
	{
		if (MinistryPageID==gcpArray[i][1]) return gcpArray[i][0];
	}
	return null;
}


/************************************************************************************************
Generic Page Cleansing using DTHML
*************************************************************************************************/
function RemovePageHeader(elementToCleanse)
{
	var src = elementToCleanse;
	try
	{
		if (src && src.childNodes && src.childNodes[0].tagName=="H1")
		{
			src.removeChild(src.childNodes[0]);
		}
	}
	catch(e){}
	return src;
}


/************************************************************************************************
Ministry Page Handling
*************************************************************************************************/
//Initializes the ministry page display. Primarily responsible for automagically drawing in group leader content reduce data entry.
function initMinistryPageDisplay()
{
	if (IsWindowInFrame()) return;
	
	var PageID = gup("PID");
	if (PageID)
	{				
		var GroupID = GetGroupIDFromMinistryPageID(PageID);
		if (GroupID)
		{			
			//This is a ministry page which has coorresponding Group page. Try to find a suitble spot
			//to inject the group page.
			var insertLoc = GetElement(document, "bodyCopy");
			if (insertLoc.childNodes.length>0)
			{	
				insertLoc =  insertLoc.childNodes[((insertLoc.childNodes[0].tagName=="H1") ? 1 : 0)];
			}
			else
			{
				insertLoc = insertLoc.appendChild(document.createElement("div"));
			}

			if (!insertLoc) return; //cant find the insertLoc, exit;
			
			//looks good, include the content
			var URLToLoad = "/templates/System/details.asp?id=34035&PG=Groups&CID=" + GroupID.toString();
			ContentIncluder(insertLoc,URLToLoad,FinishMinistryPageLoad);
		}	
		else
		{
			//this is probably some other page that doesn't have a group to map to. Fine.
		}
	}
}

//Cleanses a group page to display with in ministry page frame.
function CleanseGroupPageWithinMinistryPageFrame(elementToCleanse)
{
	var src = RemovePageHeader(elementToCleanse);
	var LnkBack = getElementsByClassName(src,"LnkBack")[0];

	//purge the linkback and extra line feeds
	LnkBack.parentNode.parentNode.removeChild(LnkBack.parentNode);
	var extraParagraphNode = src.childNodes[src.childNodes.length-1];
	if (extraParagraphNode && extraParagraphNode.tagName=="P")
	{
		extraParagraphNode.parentNode.removeChild(extraParagraphNode);
	}	
	return src;
}


function FinishMinistryPageLoad()
{
	var iFrameDoc = GetContentIFrameDocument();
	var bod = GetElement(iFrameDoc,"bodyCopy");
	var content = GetElement(iFrameDoc,"content");
	ElementMover(iFrameDoc,bod,content,CleanseGroupPageWithinMinistryPageFrame,true);
	autofitIframe(GetElement(document,"contentFrame"),iFrameDoc);
}


/************************************************************************************************
Group Page Handling
*************************************************************************************************/
//Initializes the group page display. Primarily responsible for automagically drawing in page content to a group display
//page to reduce data entry.
function initGroupDisplay()
{
	var GroupID = gup("CID");
	if (gup("PG")=="Groups" && GroupID)
	{				
		//we've found a group display page.
		try
		{
			//add the schedule link
			var sched = getElementsByClassName(document,"LblSchedule")[0].parentNode.parentNode.nextSibling;
			var anc = document.createElement('a');
			anc.href = "/templates/System/details.asp?id=34035&PG=events&searchType=&LID=" + gup("CID") + "&intRange=90&intView=0";
			anc.title = "Click to see this group's calendar.";
			var calendarIcon = document.createElement("img");
			calendarIcon.src = "/clientimages/34035/images/calendaricon.gif";
			calendarIcon.border=0;
			calendarIcon.style.paddingRight="3px";
			calendarIcon.hspace=0;
			anc.appendChild(calendarIcon);
			anc.appendChild(document.createTextNode('See Calendar'));
			sched.appendChild(document.createTextNode(' '));
			sched.appendChild(anc);	

			//add a facilities map page link
			var lblLoc = getElementsByClassName(document,"LblLocation")[0];
			var locat = lblLoc.parentNode.parentNode.nextSibling;
			if (locat.innerHTML.indexOf("Various")<0)
			{
				anc = document.createElement('a');
				anc.href = "/templates/System/details.asp?id=34035&PID=404986";
				anc.title = "Click to find about this location.";
				var mapicon = document.createElement("img");
				mapicon.src = "/clientimages/34035/images/icons/mapicon.gif";
				mapicon.border=0;
				mapicon.style.paddingRight="3px";
				mapicon.hspace=0;
				anc.appendChild(mapicon);
				anc.appendChild(document.createTextNode('See Map'));
				locat.appendChild(document.createTextNode(' '));
				locat.appendChild(anc);
			}
		}
		catch(e){}
		
		if (IsWindowInFrame()) return;
		
		/* Previously, we used a special form to support linking. Now its in the array.
		
		//first, see if we can grab the Page ID where the Group Content is located		
		var ContentPageID = "";
		var HelperForm = window.document.ContentPageHelper;		
		if (HelperForm && HelperForm["ContentPageID"])
		{
			ContentPageID = HelperForm["ContentPageID"].value;
		}
		*/		
		var backLink = getElementsByClassName(document,"LnkBack")[0];
		
		if (!backLink) return; //cant find the backLink, exit;
		
		
		if (!GroupID)
		{
			//do nothing, we don't have a group id
			var div = document.createElement("div");
			div.id = "WaitThing";
			div.title = "Need form named 'ContentPageHelper' with hidden 'ContentPageID' field to dynamically load content.";
			div.style.fontFamily="font-family:Trebuchet MS;";
			var par = document.createElement("p");
			div.appendChild(par);
			par.appendChild(document.createTextNode("For more information see the Ministry area."));
			backLink.parentNode.insertBefore(div,backLink);			
		}
		else
		{
			//looks good, include the content
			var URLToLoad = "/templates/System/details.asp?id=34035&PID=" + GetMinistryPageIDFromGroupID(GroupID).toString();
			ContentIncluder(backLink,URLToLoad,FinishGroupLoad);
		}
	}
}

//Cleanses the Page Header if necessary.
function CleansePageHeadingTitle(elementToCleanse)
{
	return RemovePageHeader(elementToCleanse);
}

function FinishGroupLoad()
{
	var iFrameDoc = GetContentIFrameDocument();
	var bod = GetElement(iFrameDoc,"bodyCopy");
	var content = GetElement(iFrameDoc,"content");
	ElementMover(iFrameDoc,bod,content,CleansePageHeadingTitle,true);
	autofitIframe(GetElement(document,"contentFrame"),iFrameDoc);
}





/************************************************************************************************
Event Registration
*************************************************************************************************/

//all group pages need this
addOnloadEvent(initGroupDisplay);
addOnloadEvent(initMinistryPageDisplay);













/***********************************************
* Ultimate Fade-In Slideshow (v1.5a): ? Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
*
* This has been customize for Ivanrest's use with an extra styleinfo parameter, and no initial fade in.
***********************************************/
var fadebgcolor="white"

////NO need to edit beyond here/////////////

var fadearray=new Array() //array to cache fadeshow instances
var fadeclear=new Array() //array to cache corresponding clearinterval pointers

var dom=(document.getElementById) //modern dom browsers
var iebrowser=document.all

function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder,extraStyleInfo){
this.pausecheck=pause
this.mouseovercheck=0
this.delay=delay;
this.rotatecount = 0;
this.degree=10 //initial opacity degree (10%)
this.curimageindex=0
this.nextimageindex=1
fadearray[fadearray.length]=this
this.slideshowid=fadearray.length-1
this.canvasbase="canvas"+this.slideshowid
this.curcanvas=this.canvasbase+"_0"
if (typeof displayorder!="undefined")
theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
this.theimages=theimages
this.imageborder=parseInt(borderwidth)
this.postimages=new Array() //preload images
for (p=0;p<theimages.length;p++){
this.postimages[p]=new Image()
this.postimages[p].src=theimages[p][0]
}

var fadewidth=fadewidth+this.imageborder*2
var fadeheight=fadeheight+this.imageborder*2

extraStyleInfo = (extraStyleInfo=="") ? "position:relative" :  extraStyleInfo ;

if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
document.write('<div id="master'+this.slideshowid+'" style="' + extraStyleInfo + ';width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);-moz-opacity:10;-khtml-opacity:10;background-color:'+fadebgcolor+'"></div><div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);-moz-opacity:10;background-color:'+fadebgcolor+'"></div></div>')
else
{
//do nothing for now.
//document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>')
}

if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
this.startit()
else{
//do nothign for now
//this.curimageindex++
//setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay)
}
}

function fadepic(obj){
if (!obj) { return; }
if (obj.degree<100){
obj.degree+=10
if (obj.tempobj.filters&&obj.tempobj.filters[0]){
if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
obj.tempobj.filters[0].opacity=obj.degree
else //else if IE5.5-
obj.tempobj.style.filter="alpha(opacity="+obj.degree+")"
}
else if (obj.tempobj.style.MozOpacity)
obj.tempobj.style.MozOpacity=obj.degree/101
else if (obj.tempobj.style.KhtmlOpacity)
obj.tempobj.style.KhtmlOpacity=obj.degree/100
else if (obj.tempobj.style.opacity&&!obj.tempobj.filters)
obj.tempobj.style.opacity=obj.degree/101
}
else{
clearInterval(fadeclear[obj.slideshowid])
obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
obj.populateslide(obj.tempobj, obj.nextimageindex)
obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
}
}

fadeshow.prototype.populateslide=function(picobj, picindex){
var slideHTML=""
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML='<a href="'+this.theimages[picindex][1]+'" target="'+this.theimages[picindex][2]+'">'
slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">'
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML+='</a>'
picobj.innerHTML=slideHTML
}


fadeshow.prototype.rotateimage=function(){
if (this.pausecheck==1) //if pause onMouseover enabled, cache object
var cacheobj=this
if (this.mouseovercheck==1)
setTimeout(function(){cacheobj.rotateimage()}, 100)
else if (iebrowser&&dom||dom){
this.resetit()
this.rotatecount++;
var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
crossobj.style.zIndex++
fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"])",50)
this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
}
else{
var ns4imgobj=document.images['defaultslide'+this.slideshowid]
ns4imgobj.src=this.postimages[this.curimageindex].src
}
this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
}

fadeshow.prototype.resetit=function(){
this.degree=10
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
if (crossobj.filters&&crossobj.filters[0]){
if (typeof crossobj.filters[0].opacity=="number") //if IE6+
crossobj.filters(0).opacity=this.degree
else //else if IE5.5-
crossobj.style.filter="alpha(opacity="+this.degree+")"
}
else if (crossobj.style.MozOpacity)
crossobj.style.MozOpacity=this.degree/101
else if (crossobj.style.KhtmlOpacity)
crossobj.style.KhtmlOpacity=this.degree/100
else if (crossobj.style.opacity&&!crossobj.filters)
crossobj.style.opacity=this.degree/101
}
 


fadeshow.prototype.startit=function(){
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
this.populateslide(crossobj, this.curimageindex)
if (this.pausecheck==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
var cacheobj=this
var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid)
crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}
}
this.rotateimage()
}


