	
	function loadWebcasts() {
		$("div#video_list").load("includes/home_video_webcasts.php");
	}
	
	function loadClips() {
		$("div#video_list").load("includes/home_video_clips.php");
	}
	
	function loadClip(id) {
		$("div#video_player").load("includes/you_tube.php", { 'v' : id } );
	}
	
	function loadArchive(id) {
		$("div#video_player").load("includes/home_archive.php", { 'v' : id } );
	}
	
	function webcast_interface(section, id, event) {
		if (section == 'current') {
			open_popup('../webcast/index.php?section=' + section + '&id=' + id, 'webcast_window', 'width=760,height=406,scrollbars=no,resizable=yes,location=no,menubar=no,status=no,toolbar=no,directories=no,personalbar=no');
		} else if (section == 'archive') {
			open_popup('../webcast/index.php?section=' + section + '&id=' + id + '&event=' + event, 'webcast_window', 'width=760,height=406,scrollbars=no,resizable=yes,location=no,menubar=no,status=no,toolbar=no,directories=no,personalbar=no');
		}
	}	
	
	//ver 1.1
	var popup_array = Array();
	function open_popup(url, popup_name, options) {
		var cur_popup = popup_array[popup_name];
		var is_popup_defined = (typeof(cur_popup) == 'object');
		var is_popup_open = (is_popup_defined)
			? !(cur_popup.closed)
			: false;
	
		if ( is_popup_defined && is_popup_open ) {
			cur_popup.document.write (' ');
			cur_popup.focus();
			cur_popup.location.href = url;
			cur_popup.focus();
		} else if ((is_popup_defined && !is_popup_open) || !is_popup_defined) {
			popup_array[popup_name] = window.open(url, popup_name, options);
		}
	}
	
	
var current_mp3_id = "";

function playMP3(id, mp3) {
	//change button display
	$("a.listenButton").css({'display':'block'});
	$("a.pauseButton").css({'display':'none'});
	$("a#listen_" + id).css({'display':'none'});
	$("a#pause_" + id).css({'display':'block'});
	
	//change status display
	$("div.listenStatus").css({'display':'none'});
	$("div#listen_status_" + id).css({'display':'block'});
	$("div#listen_status_" + id).html("Now Playing:");
	
	if (current_mp3_id == id) {
		//play mp3
		niftyplayer('mp3Player1').play();
	}
	else {
		//load and play mp3
		niftyplayer('mp3Player1').loadAndPlay('/media/mp3/AudioDL/' + mp3);
		current_mp3_id = id;
	}
}
function pauseMP3(id) {
	//change button display
	$("a#pause_" + id).css({'display':'none'});
	$("a#listen_" + id).css({'display':'block'});
	
	//change status display
	$("div.listenStatus").css({'display':'none'});
	$("div#listen_status_" + id).css({'display':'block'});
	$("div#listen_status_" + id).html("Paused:");	
	
	//pause mp3
	niftyplayer('mp3Player1').pause();
}	

function playHomeMP3(mp3) {
	
	//play mp3
	if (mp3=="") {
		niftyplayer('mp3Player1').play();
	}
	else {
		niftyplayer('mp3Player1').loadAndPlay('/media/homepage/' + mp3);	
	}
	
	//update label
	$("a#home_mp3_on").css({'display':'inline'});
	$("a#home_mp3_off").css({'display':'none'});	
	
}

function pauseHomeMP3() {
	
	//pause mp3
	niftyplayer('mp3Player1').pause();
	
	//update label
	$("a#home_mp3_on").css({'display':'none'});
	$("a#home_mp3_off").css({'display':'inline'});	
	
}

function switchDivs(div1, div2) {
		$("div#" + div1).css({'display':'none'});
		$("div#" + div2).css({'display':'block'});
}


//SHOPPING CART
function addProduct(id,current_quantity) {
	$("div#include_shell").load("/includes/shopping_cart.php?load=true&add=" + id);
}

function removeProduct(id,current_quantity) {
	$("div#include_shell").load("/includes/shopping_cart.php?load=true&remove=" + id);
}

function copyBillingInfo() {
	var status = $('#copy_billing_info').attr('checked');
	if (status==true) {
		//ON
		$("#ship_first_name").val($("#first_name").val());
		$("#ship_last_name").val($("#last_name").val());
		$("#ship_address").val($("#address").val());
		$("#ship_address2").val($("#address2").val());
		$("#ship_city").val($("#city").val());
		$("#ship_state").val($("#state").val());
		$("#ship_zip").val($("#zip").val());
		$("#ship_phone").val($("#phone").val());
		$("#ship_email").val($("#email").val());
	}
	else {
		//OFF
		if ( $("#ship_first_name").val() == $("#first_name").val() )   $("#ship_first_name").val('');
		if ( $("#ship_last_name").val() == $("#last_name").val() )   $("#ship_last_name").val('');
		if ( $("#ship_address").val() == $("#address").val() )   $("#ship_address").val('');
		if ( $("#ship_address2").val() == $("#address2").val() )   $("#ship_address2").val('');
		if ( $("#ship_city").val() == $("#city").val() )   $("#ship_city").val('');
		if ( $("#ship_state").val() == $("#state").val() )   $("#ship_state").val('');
		if ( $("#ship_zip").val() == $("#zip").val() )   $("#ship_zip").val('');
		if ( $("#ship_phone").val() == $("#phone").val() )   $("#ship_phone").val('');
		if ( $("#ship_email").val() == $("#email").val() )   $("#ship_email").val('');
	}
}

function processCheckout(step,nextstep) {

		function verify(data) {
			var data1 = data.substr(0,1);
			switch (data1) {
				case "1":
					//success
					loadStep(nextstep);
					break;
				case "^":
					//error w/ field highlighting
					alert("Oops, please make corrections to fields marked in red.");
					
					//clear existing errors
					$(".ticket_field").removeClass("field_error");
					
					//add field highlighting for fields w/ errors
					var error, i, field, temp;
					error = data.split(",");
					for(i=0; i<error.length; i++) {
						if (error[i]!="^") {
							field = error[i];
							field = field.replace("_"," ");
							field = field.replace("*","");
							field = field.replace("*","");
							$("[name=" + field + "]").addClass("field_error");
						}
					}
					scrollToStepWrapper();
					
					break;
				case "$":
					//successful transaction
					$("#step_wrapper").html('<br /><h2>Thank you!</h2>Your transaction has been completed successfully, and we have sent you a confirmation email.');
					scrollToStepWrapper();
					break;
				default:
					//error
					alert(data);	
			}	
		}

		$.post("process/checkout_step" + step + ".php", $("#frmCheckoutStep" + step).serialize(), function(data){ verify(data) } );	

}

function loadStep(step) {
	scrollToStepWrapper();
	var rand = Math.random();
	$("#step_wrapper").load("includes/checkout_step" + step + ".php?step=" + step + "&rand=" + rand);
}

function scrollToStepWrapper() {
	var destination = $("div.page_content").offset().top;
	$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );	
}


//eNetwork
function eNetworkSignup(type) {
	
		var div_shell = "";
	
		switch (type) {
			case "small":
				div_shell = "enetwork_signup_small";
				break;
			default:
				div_shell = "include_shell";
		}
	
		function updateFront(html) {
			$("div#" + div_shell).slideUp("fast", function() {
				$("div#" + div_shell).html(html + "<br><br>");
				$("div#" + div_shell).css({
					'border-width':'1px',
					'border-style':'solid',
					'border-color':'#d4d4d4',
					'background-color':'#fafbfb',
					'padding':'20px',
					'margin-top':'20px'
					});
				$("div#" + div_shell).slideDown("slow");
			});
		}
	
		function verify(data) {
			switch (data) {
				case "User has been added":
					msg = "<h2>Thank you!</h2>You have been added to Maranatha Chapel's eNetwork system!";
					updateFront(msg);
					break;
				case "User has been updated":
					msg = "<h2>Thank you!</h2>Your account has been updated.";
					updateFront(msg);
					break;
				default:
					msg = data;
					alert(msg);	
			}	
		}

		$.post("includes/enetwork/process_signup.php", $("#frmEnetworkSignup").serialize(), function(data){ verify(data) } );
}


//Photo Gallery
function loadPhoto(id,page,w,h) {
	
	$("div#photo").fadeOut("fast", function() {	
		$("div#photo").load("includes/gallery_photo.php?photo=" + id + "&p=" + page);									
		$("div#photo_wrapper").animate({
			height: h					   
		},"slow", function() {									
					$("div#photo").fadeIn("slow");																				  
		});
	});

}

function loadFirstPhoto(id,page,w,h) {
		$("div#photo_wrapper").animate({
			height: h					   
		},"slow");		
}


//Event Ticketing
function togglePartialPayment(event_id,minimum_deposit,actual_price) {
	
	var status = $("#partial_payment").css('display');
	
	if (status == "none") {
		//show
		$("#partial_payment").load("includes/store_tickets_partial_payments.php?event=" + event_id + "&minimum_deposit=" + minimum_deposit + "&actual_price=" + actual_price, function() {
			$("#partial_payment").slideDown("slow", function(){
			var destination = $("#partial_payment").offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );												 																				 
			});
		});	
	}
	else {
		//hide
		$("#partial_payment").slideUp("slow");
	}
	
}

function IsNumeric(sText) {
	
	   var ValidChars = "0123456789.";
	   var IsNumber=true;
	   var Char;
	
	 
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
		  { 
		  Char = sText.charAt(i); 
		  if (ValidChars.indexOf(Char) == -1) 
			 {
			 IsNumber = false;
			 }
		  }
	   return IsNumber;
	   
}	

function validatePartialAmount() {
	
	var error = "";	
	var custom_price = $("#custom_price").val().split("|");
	var amount = $("#partial_amount").val();
	var actual_price = $("#actual_price").val();

	var event_id = custom_price[0];
	var minimum_deposit = custom_price[1];
	
	//check for errors
	if (minimum_deposit!="") {
		minimum_deposit = parseFloat(minimum_deposit);
		if (amount < minimum_deposit) {
			error = "The minimum deposit for this event is $" + minimum_deposit	+ ".\n";
		}
	}	
	if (actual_price!="") {
		actual_price = parseFloat(actual_price);
		if (amount > actual_price) {
			error = "The amount you entered is more than the price of a ticket for this event. Please enter an amount less than $" + actual_price + ".\n";	
		}
	}
	if (!IsNumeric(amount))
		error = "The amount you entered is invalid. Please try again.\n";

	//process
	if (error!="") {
		//error
		alert(error);
		return false;
	}
	else {
		//sucess
		
		var answer = confirm("We will now add this ticket order to your shopping cart, with a price per ticket of $" + amount + " (the amount you entered).  After you complete your transaction, you will receive instructions for paying the remaining balance of your ticket order.  Do you want to continue?");
		
		if (answer) {
			//set #custom_price
			$("#user_generated_price").val(event_id + "|" + minimum_deposit + "|" + amount + "|" + actual_price);			
			
			//empty shopping cart
			//$.get("includes/shopping_cart_empty.php",{no_redirect:'true'});
			
			return true;
		}
		else {
			return false;
		}
		
	}
	
}
