Cufon.replace('#navigation a');
Cufon.replace('.cufon');
Cufon.replace('.home-article h4');
Cufon.replace('.list-article h4');
Cufon.replace('.section-head');
Cufon.replace('.sub-main-content h2');
Cufon.replace('.modal h3');
Cufon.replace('#home-features-tabs > div');


$(document).ready(function() {

	$(".serve-export-link a").click(function(event){
		window.location = $(this).attr("href");
		return false;
	});


	$(".serve-single-opp").click(function(event){
		if ($(this).children('.serve-single-detail').is(':hidden')){
			$('.serve-single-detail').slideUp();
			$(this).css('height','auto');
			$(this).children('.serve-single-detail').slideToggle();
		}
		else {$(this).children('.serve-single-detail').slideUp();}
		return false;
	});
	
	
	$("#dim-screen").click(function(event){
		$("#dim-screen").fadeOut();
		$(".modal").fadeOut();
		$(".serve-form-error").fadeOut();
	});
	
	$(".close-modal-link").click(function(event){
		$("#dim-screen").fadeOut();
		$(".modal").fadeOut();
		$(".serve-form-error").fadeOut();
		return false;
	});
	
	
//*****************************************************
// Serve App form processing
//
// ****************************************************

	$(".serve-single-opp:not(.filled) .serve-single-button").click(function(event){
		$("#op-id").val($(this).attr("id"));
		$("#serve-here-form strong").html($(this).siblings("h5").children("a").html());
		$("#serve-here-form").fadeIn();
		$("#dim-screen").fadeIn();
		return false;
	});



	var formOptions = { 
	        beforeSubmit:	validateServeForm,
	        success:		serveFormResponse,
	        clearForm:		true
	        };

	$('#serve-form').ajaxForm(formOptions);
	
//*****************************************************
// Home Page Event Popups
//
// ****************************************************

	$('.home-event').hover(function() {
		$(this).children('.home-event-popup').stop(true, true).fadeIn();
	}, function() {
		$(this).children('.home-event-popup').stop(true, true).fadeOut();
	});


	
//*****************************************************
// Welcome / Last Sunday tabs on the home page
//
// ****************************************************

	$("#home-tab-welcome").click(function(event){
	  	if ($("#home-feature-welcome:hidden")){
	  		$("#home-feature-sunday").fadeOut('slow');
	  		$("#home-feature-welcome").fadeIn('slow');
	  		$(this).addClass('active');
	  		$("#home-tab-sunday").removeClass('active');
	  	}
  	});
  	
  	$("#home-tab-sunday").click(function(event){
  		if ($("#home-feature-sunday:hidden")){
	  		$("#home-feature-welcome").fadeOut('slow');
	  		$("#home-feature-sunday").fadeIn('slow');
	  		$(this).addClass('active');
	  		$("#home-tab-welcome").removeClass('active');
  		}
  	});
  
  
  	if ($("#home-tab-welcome").hasClass('active')) {
  		$("#home-feature-sunday").fadeOut('slow');
  		$("#home-feature-welcome").fadeIn('slow');
  	}
  	else {
  		$("#home-feature-welcome").fadeOut('slow');
  		$("#home-feature-sunday").fadeIn('slow');
  	}
  
}); //***** End of document.ready listeners *****/



function validateServeForm(){
	if ($("#name").val()=='' 
			|| $("#phone").val()=='' 
			|| $("#email").val()==''
			|| $("#name").val()=='Your Name'
			|| $("#phone").val()=='Home Phone'
			|| $("#email").val()=='Email'
		) {
		$(".serve-form-error").fadeIn();
		return false;
	}
	else { return true; }
}

function serveFormResponse(responseText){
	$("#serve-here-form p").html(responseText);
	$("#serve-here-form form").hide();
}


function slideSwitch() {

	if ( $('#home-billboard-container').children().size() == 1 ) { return false; }

	var $active = $('#home-billboard-container div.current');
	
	var $next = $active.next();
	if ( $next.length == 0 ) $next = $('#home-billboard-container div:first');
	
	$next.css({'zindex':'9','opacity':'1.0'});
	
	$active.css('zindex','10');
	
	$active.animate(
		{opacity: 0.0}, 2500, function() {
	    	$active.removeClass('current');
	    	$next.addClass('current');
	});    
}

setInterval( "slideSwitch()", 8000 );

// Delay for home page slideshow
//$(function() {
//	alert('slides')
    //setInterval( "slideSwitch()", 8000 );
//});

