
/**
  *  
  *  these functions are only used to control the homepage slideshow
*/
initDone=false
//  declare global variables
	SCENES=3  // number of scenes (each scene has a phot file (e.g. photo-nn) and a text div with id=v01
	state="NONE"  // can be NONE, INITIALIZE, RESET, PLAY, STOP
	step=1 // indicates what step we are at in the current state
	scene=null // points to the active scene
	topScene=null




function alertIE7(message) {
if ((parseInt(jQuery.browser.version) == 7) && (jQuery.browser.msie)) alert(message)
}




function bg_initialize () {

var theBrowser

browserVersion = parseInt(jQuery.browser.version)

// if IE6 route user directly to the About page
if (jQuery.browser.msie && (browserVersion < 7)) {
	window.location.href='http://ephesians.org/wordpress/about'
	}
else {
	$('#screenBox').show()
	$('#shapecutout').show()
	Collage.buildHTML()
	$('#collageTree').show()
	setTimeout('Collage.showPhoto()',2000)
		
	// if there is no content in the Announcement post then hide the borders of the message div
	if ($('#messageExcerpt').text().length ==0) {
		$('#message').empty()
		$('#message').css('border','none')
		}
	
	resetSceneImages()
	
	// if cookie not set then proceed to show announcement, otherwise return
	if (Cookie.get("visited")==1) {
		state="HOME"
		step=1
		return
		}
	else Cookie.set("visited",1,1)
	
	state="ANNOUNCEMENT"
	step=1
	setTimeout('showAnnouncement()',8000)
	
	}
} // bg_initialize()



var Collage = {
	photosPath: 'http://ephesians.org/StaffPhotos/',
	N: 18,
	next: 0,
	names: new Array('McKeelJay','FryCora','GoldenJewell','KahlerMaryJo','KangKay','ProctorBelita','KershawMaureen','MarlerLeslie','CuomoSheila','MillsDarius','MoliaSieh','NadeemCarolBinta','OsterhoutSteve','ProctorJoAnn','SarcinelliAnnette','TuckerPat','WineglassJonesIzola','RichAmy'),
	buildHTML: function () {
		var cHTML
		
		cHTML =''
		for (i=0; i<Collage.N; i++) {
			 cHTML += '<div class="aBlock photoBorder"><img  alt="'+Collage.names[i]+'" src="'+Collage.photosPath+Collage.names[i]+'.jpg"></img></div>'
			 if (i==5) cHTML += '<div class="aBlock photoBorder" id="blank1"><p>Our counselors are rooted in God and committed to your healing.</p></div>'
			 if (i==9) cHTML += '<div class="aBlock photoBorder" id="blank2"><img id="collageTree" src="'+EPATH+'images/tree.png"></img></div>'
			 }
		$('#thePhotosCollage').append(cHTML)
	},  // buildHTML
	showPhoto: function () {
		var parsedString, name
		if (Collage.next==0) Collage.randomizeTheList()
		if (Collage.next<Collage.N) {
			parsedString = Collage.names[Collage.next].match(/(\w+)\s(\w+)/); 
			name = parsedString[2]
			$('#thePhotosCollage img[alt='+name+']').show()
			Collage.next++
			setTimeout('Collage.showPhoto()',250)
		}
	}, // showRandom
	
	compare : function (a,b) {
		// used by sort function to decide precedence
		var parsedString, num1, num2
		
		parsedString = a.match(/(\w+)\s(\w+)/); 
		num1 = 1*parsedString[1]
		
		parsedString = b.match(/(\w+)\s(\w+)/); 
		num2 = 1*parsedString[1]
		
		return num1-num2
				
	},  // compare()

	randomizeTheList : function () {  // sort the images array randomly
		var i

		for (i=0; i<Collage.N; i++) {
			Collage.names[i] = Math.round(Math.random()*100) + ' ' + Collage.names[i]
		}

		Collage.names.sort(Collage.compare)

		
	}  // sortList()
	
} // Collage




function resetSceneImages() {

// load the first two scenes starting with a random one
scene=Math.round(Math.random()*(SCENES-1))
num="0" + scene
$('#photo_1').attr('src',EPATH + "images/photo-" + num.substring(num.length-2) + ".jpg")
$("#text_1").text($('#v_' + num.substring(num.length-2)).text())

// pre-load the next scene's photo and text
num="0" + (scene+1)%(SCENES)
$('#photo_0').attr('src',EPATH + "images/photo-" + num.substring(num.length-2) + ".jpg")
$("#text_0").text($('#v_' + num.substring(num.length-2)).text())

$('.testimonialPhoto').hide()
$('.testimonialText').hide()
topScene=1

}


// display the donation appeal
function showAnnouncement () {
switch (step) {
	case 1 :
		$('#announcement').slideDown('slow')
		setTimeout('resume_task()',8000)
		step=2
		break
	case 2 :
		state="HOME"
		step=1
		$('#announcement').slideUp('slow',function() {resume_task()})
		break
	}

}  // showAnnouncement()


function showStories () {
if (state!="HOME" && state!="STORIES") return  // don't allow showStories yet because we're still showing announcement
state="STORIES"
switch (step) {
	case 1 :
		resetSceneImages()
		$('#thePhotosCollage').fadeOut('slow',function() {resume_task()})
		step=2
		break
	case 2 :
		$('#storyBox').hide()
		$("#photo_1").fadeIn('slow', function () {
			$("#text_1").fadeIn('slow', function () {
				$('#playbutton').show()
			})
		})
		
		if (topScene==1) currentScene="1"
			else currentScene="0"

		state="PLAY"
		step=1
		break
	}
} // showStories()


function play (state) {

if (state=="next" & step!=1) return  // don't allow play yet because we're still processing

switch (step) {
	case 1 :
		switch (topScene) {
			case 1 :
				currentScene="1"
				nextScene="0"
				break
			case -1 :
				currentScene="0"
				nextScene="1"
			}
		topScene=-1*topScene
		step=2
		$("#photo_" + currentScene).fadeOut('slow')
		$("#text_" + currentScene).fadeOut('slow', function () {
			$("#photo_" + nextScene).fadeIn('slow', function () {
				$("#text_" + nextScene).fadeIn('slow')
			})
		})
		scene=(scene+1)%(SCENES)
		setTimeout('resume_task()',2000)
		break
		
	case 2 :
		num="0" + (scene+1)%(SCENES)
		$("#photo_" + currentScene).attr('src',EPATH + "images/photo-" + num.substring(num.length-2) + ".jpg")
		$("#text_" + currentScene).text($("#v_" + num.substring(num.length-2)).text())
		step=1
		break

	}
	
} // play()


// executed when HOME is selected from the menu
function goHome () {

$('.testimonialPhoto').hide()
$('.testimonialText').hide()
$("#thePhotosCollage").fadeIn('slow')
$("#playbutton").hide()
$('#storyBox').show()
state="HOME"
step=1
} // goHome()


// this function synchronizes the animation steps
function resume_task () {
//alert("state=" + state + " step =" + step)
	switch (state) {
		case "NONE" :
			break;
		case "INITIALIZE" :
			bg_initialize();
			break;
		case "ANNOUNCEMENT" :
			showAnnouncement();
			break;
		case "STORIES" :
			showStories();
			break;
		case "HOME" :
			state="STORIES"
			step=1
			$("#storyBox").show()
			break;
		case "PLAY" :
			play("resume")
			break;
		case "STOP" :
			break;
		default:
	}
}  // resume_task()

	

/**   The following code deals with the visitor form dialog box that pops up when the
 *     slideshow "play" button is pressed.
 *
 * This object, Cookie, is simply a mechanism to allow for easier access of the
 * document.cookie object for the page. It contains the following methods:
 * - set(p_name, p_value, p_expires)
 * - get(p_name)
 * - erase(p_name)
 * - accept( )
 */
var Cookie = {
	/**
	 * This method, set, creates a cookie with the name equal to /p_name/ with a
	 * value of /p_value/ that expires at the specified /p_expires/ should it
	 * exist, returning whether the cookie was created or not.
	 *
	 * @member Cookie
	 * @param {String} p_name The name for the cookie to be set.
	 * @param {String} p_value The value for the cookie to be set.
	 * @param {Float} p_expires The time before the cookie to be set expires.
	 * @return Returns whether the cookie was set or not.
	 * @type Boolean
	 */
	set: function(p_name, p_value, p_expires) {
		/* The expires string for the cookie */
		var expires = '';

		/* Was an expires time sent to the method? */
		if (p_expires != undefined) {
			/* Get a base time for the expiration date */
			var expirationDate = new Date( );

			/* Set the expiration to one day times the passed /p_expires/ value */
			expirationDate.setTime(expirationDate.getTime( ) + (86400000 * parseFloat(p_expires)));
			/* Create the expires string for the cookie */
			expires = '; expires=' + expirationDate.toGMTString( );
		}
		return (document.cookie = escape(p_name) + '=' + escape(p_value || '') + expires);
	},
	/**
	 * This method, get, returns the cookie with a name equal to the passed /p_name/
	 * variable if one exists.
	 *
	 * @member Cookie
	 * @param {String} p_name The name for the cookie to return.
	 * @return Returns the cookie data if it exists or /null/ otherwise.
	 * @type String
	 */
	get: function(p_name) {
		/* Get the matching cookie */
		var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(p_name) + '=([^;\\s]*)'));

		return (cookie ? unescape(cookie[2]) : null);
	},
	/**
	 * This method, erase, removes the cookie with the passed /p_name/ variable from
	 * the document. It returns the erased cookie (i.e., null if erase succeeded,
	 * the cookie otherwise).
	 *
	 * @member Cookie
	 * @param {String} p_name The name for the cookie to erase.
	 * @return Returns the cookie after it is erased.
	 * @type Boolean | String
	 */
	erase: function(p_name) {
		/* Get the cookie with the passed /p_name/ variable */
		var cookie = Cookie.get(p_name) || true;

		/*
		 * Set the cookie with the passed /p_name/ variable to an empty string, and
		 * make it expire
		 */
		Cookie.set(p_name, '', -1);
		return (cookie);
	},
	/**
	 * This method, accept, tests to see if the browser accepts cookies and returns
	 * the results of this test.
	 *
	 * @member Cookie
	 * @return Returns whether the browser accepts cookies or not.
	 * @type Boolean
	 */
	accept: function( ) {
		/* Can the test be accomplished using the browser's built-in members? */
		if (typeof navigator.cookieEnabled == 'boolean')
			return (navigator.cookieEnabled);
		/* Attempt to set and erase a cookie and return the results */
		Cookie.set('_test', '1');
		return (Cookie.erase('_test') === '1');
	}
};


function showContactForm () {

document.getElementById('myForm').reset()
$('tr td:even').css('color','blue')
$('#formContainer').slideDown()

}  // showContactForm()

function bg_formSubmit() {

var xmlString='', name='blank', address='blank', phone='blank', message='blank', email='blank', insurance='blank', company='blank',patient='blank', reference='blank', comments='blank'


if ($('#myForm input[name=name]').attr('value').length>0) name=$('#myForm input[name=name]').attr('value')
if ($('#myForm textarea[name=address]').attr('value').length>0) address=$('#myForm textarea[name=address]').attr('value')
if ($('#myForm input[name=phone]').attr('value').length>0) phone=$('#myForm input[name=phone]').attr('value')
$("#myForm input[name=message]:checked").each(function () { message=$(this).attr('value')})

if ($('#myForm input[name=email]').attr('value').length>0) email=$('#myForm input[name=email]').attr('value')
$("#myForm input[name=insurance]:checked").each(function () { insurance=$(this).attr('value')})
if ($('#myForm input[name=company]').attr('value').length>0) company=$('#myForm input[name=company]').attr('value')


$("#myForm input[name=patient]:checked").each(function () { 
														patient=$(this).attr('value')
														if (patient=='other') patient=$('#myForm input[name=otherCounseling]').attr('value')
														})


$("#myForm input[name=reference]:checked").each(function () { 
														reference=$(this).attr('value')
														if (reference=='other') reference=$('#myForm input[name=otherReference]').attr('value')
														})
if ($('#myForm textarea[name=comments]').attr('value').length>0) comments=$('#myForm textarea[name=comments]').attr('value')

xmlString='<myForm>'
xmlString += '<name>'+name+'</name>'
xmlString += '<address>'+address+'</address>'
xmlString += '<phone>'+phone+'</phone>'
xmlString += '<message>'+message+'</message>'
xmlString += '<email>'+email+'</email>'
xmlString += '<insurance>'+insurance+'</insurance>'
xmlString += '<company>'+company+'</company>'
xmlString += '<patient>'+patient+'</patient>'
xmlString += '<reference>'+reference+'</reference>'
xmlString += '<comments>'+comments+'</comments>'
xmlString += '</myForm>'


// add the transaction to the member's transactionsBlob
$.ajax({
	type: "POST",
	url: EPATH+"emailRequestForm.php",
	data: 'tXML='+xmlString,
	dataType: "text",
	async: true,
	processData: false,
	success: function(data) {
		$('#contentBox').append('<p style="color:white">'+data+'</p>')
		} // success	
}); // ajax	

$('#formContainer').slideUp()


}  // formSubmit()


