var Slideshow3Param = {
	 album: '',
	 ready: false
};

$(function() {
		   
			var uri = "" + self.location;
			var fileArray = uri.split("/");
			var filename = fileArray[fileArray.length-1];

			$.get('nav_ajax.html', function(data) {
											document.getElementById('nav_div').innerHTML = data;
											var MenuBar1 = new Spry.Widget.MenuBar("Navigation", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});											
											});
			
		   
			if(filename == '' || filename == 'index.html')
			{
		   
				$('a.slideshow_nicaragua').click(function() {
												  	resetSlideshowLinks();
													$('a.slideshow_nicaragua').css('color', '#cad9f0');
													loadAlbum('nicaragua', 2);

													this.blur();
													return false;
															
														  });
				
				$('a.slideshow_philippines').click(function() {
													resetSlideshowLinks();
													$('a.slideshow_philippines').css('color', '#cad9f0');
													loadAlbum('philippines', 6);
													
													this.blur();
										  			return false;
														  
														  });
				
				$('a.slideshow_philippines2').click(function() {
													resetSlideshowLinks();
													$('a.slideshow_philippines2').css('color', '#cad9f0');
													loadAlbum('philippines2', 5);
													
													this.blur();
										  			return false;
														  
														  });

				var chosenAlbum = Math.floor(Math.random() * 2);

				if(chosenAlbum == 0)
					$('a.slideshow_philippines').click();
				else if(chosenAlbum == 1)
					$('a.slideshow_nicaragua').click();

			}
			else if(filename == 'listen_now.html')
			{
				   $.get('playAudio.php?album=6', function(data) { 
														   document.getElementById('audio_player_div').innerHTML = data;
														   });
				   
					// load latest album into play list
					$.get('audio_ajax.php?album=6', function(data) {
															 $('#album6').html(data);
															 
															 });
					
					// on click, load other albums
					$('.TabbedPanelsTab').click(function() { 
														  var albumNum = $(this).attr('albumNum');
														  $('#album' + albumNum).load('audio_ajax.php?album=' + albumNum);																									 												 });
			}
			else if(filename == 'prayer.html')
			{
				$('#submit').click(function() {
												var firstname = $('#first_name').attr('value');
												var lastname = $('#last_name').attr('value');
												var country = $('#country').children('[@selected]').text();
												var email = $('#email_address').attr('value');
												var prayerrequest = $('#prayer_request').attr('value');

												if(firstname == undefined) firstname = '';
												if(lastname == undefined) lastname = '';

												if(prayerrequest == '' || prayerrequest == undefined)
												{
													alert('Please enter your prayer request in the box');
													return;
												}
												if(email == '' || email == undefined)
												{
													alert('Please enter your e-mail address');
													return;
												}
												
												$.post('prayer_request.php', { 
														   firstname: firstname,
														   lastname: lastname,
														   country: country,
														   email: email,
														   prayerrequest: prayerrequest },
													   function(data) {
														   if(data == "1")
														   {
															   $('#content_main').html('');
															   $('#contact_paragraph').html('Your prayer request was successfully sent.');
														   }
													   });
											});
			}
		   
		   });

function slideshow3Ready()
{
	Slideshow3Param.ready = true;
}

function loadAlbum(album, pages)
{
	if(!Slideshow3Param.ready)
	{
		setTimeout("loadAlbum('" + album + "', 	" + pages + ")", 500);
		return;
	}
	
	if(Slideshow3Param.album != album)
	{
			document.Slideshow3Manager.loadAlbum(album, pages);
			Slideshow3Param.album = album;
	}
}

function memoryOverload()
{
	alert('Please close browser windows to free up some memory.');
}

function resetSlideshowLinks()
{
	$('a.slideshow_philippines').css('color', '#82ADDC');
	$('a.slideshow_nicaragua').css('color', '#82ADDC');
	$('a.slideshow_philippines2').css('color', '#82ADDC');	
}
function setVideo(videoUrl, videoTitle, videoCategory)
{

  if(videoUrl == '' || videoUrl == undefined) return;
  
  var obj = document.getElementById("special_div_marker");
  var callFunc = "playVideo('" + videoUrl + "', '" + videoTitle + "', '" + videoCategory + "')";  

    
  if(obj.style.display == "")
  {
    obj.style.display = "block";
    setVideoText(videoTitle, videoCategory);
    setTimeout(callFunc, 400);
	return;
  }

  setVideoText(videoTitle, videoCategory);
  eval(callFunc);

}

function setVideoText(videoTitle, videoCategory)
{
  MM_setTextOfLayer('video_title', '', videoTitle);
  MM_setTextOfLayer('video_category', '', videoCategory);
}

function playVideo(videoUrl, videoTitle, videoCategory) 
{
  
  if(document.VideoPlayer2_wrapper.setUrl == undefined)
  {
  	setTimeout('playVideo(\'' + videoUrl + '\',\'' + videoTitle + '\',\'' + videoCategory + '\')', 300);
	return;
  }
  
  document.VideoPlayer2_wrapper.setUrl(videoUrl);
}

var numDonationsLoaded = 0;

function loadAndReloadDonations()
{
	loadFragmentInToElement('http://www.godcanmakeaway.com/books_ajax.php', 'donations_div');
	
	numDonationsLoaded++;
	
	if(numDonationsLoaded <= 5)
	  	setTimeout('loadAndReloadDonations()', 10000);
}

function sameShippingClicked()
{
	var checkbox = document.forms[0].use_shipping_for_billing;
	
	if(checkbox.checked)
	{
		document.forms[0].billing_address_1.value = document.forms[0].shipping_address_1.value;
		document.forms[0].billing_address_2.value = document.forms[0].shipping_address_2.value;
		document.forms[0].billing_city.value = document.forms[0].shipping_city.value;		
		document.forms[0].billing_state.value = document.forms[0].shipping_state.value;
		document.forms[0].billing_zipcode.value = document.forms[0].shipping_zipcode.value;		
	}
}
