jQuery(document).ready(function($) {
	
	var section	= $('body').attr('id');
	
	var nextHomepageBanner = function() {
		var count = $('#heros li').length;
		var index = $('#heros li.active').index() + 1;
		
		if ((index) == count) {
			index = 0;
		}
		
		setHomepageBanner(index);
	};
	
	var setHomepageBanner = function(index) {
		$active = $('#heros li').eq(index);
		$hero = $active.children('div.hero').clone();
		$hero.addClass('active'); //.css('top', '240px');
		$('#heros div.active').replaceWith($hero);
		/*
		$hero.animate({
			top:		0
		}, 5000);
		$('#heros div.active').after($hero).animate({
			top:		'-240px'
		}, function() {
			$(this).remove();
		});
		*/
		
		$active.siblings().removeClass('active').find('.hoverArrow').remove().end().end().addClass('active').each(function() {
			if ($(this).find('.hoverArrow').length == 0) {
				$(this).append('<div class="hoverArrow"></div>');
			}
		});
	};
	
	var $simple_search = $('#keywords');
	var default_search = $simple_search.val();
	$simple_search.focus(function() {
		if ($(this).val() == default_search) {
			$(this).val('');
		}
	}).blur(function() {
		if ($(this).val() == '') {
			$(this).val(default_search);
		}
	});
	
	if (section == 'home') {
		
		var interval = setInterval(nextHomepageBanner, 8000);
		
		// Change banner image on click
		$('#heros li a').click(function() {
			var $li = $(this).parent();
			
			if (! $li.hasClass('active')) {
				setHomepageBanner($li.index());
				clearInterval(interval);
			}
			
			return false;
		});
		
		// Add little green arrow
		$('#heros li.active').append('<div class="hoverArrow"></div>');
	}
	
	if ($('body').hasClass('resources')) {
		$(window).load(function() {
			$('li.two').each(function() {
				var myHeight = $(this).height();
				var urHeight = $(this).prev('li.one').height();
				if (myHeight > urHeight) {
					$(this).prev('li.one').height(myHeight+'px');
				} else {
					$(this).height(urHeight+'px');
				}
			});
		});
	}
	
});






// CREDITS:
// Based on Body Mass calculator script by by John Scott (johnscott03@yahoo.com)
// Visit JavaScript Kit (http://javascriptkit.com) for script
// Adapted by the SBC of Virginia (http://www.sbcv.org) Media Team (media@sbcv.org)
 
function ClearForm(form){
 
    form.offering.value = "";
    form.church_cp.value = "";
    form.total_cp.value = "";
    form.my_comment.value = "";
 
}
 
// These functions perform the necessary calculations to determine the dollar amounts based on information the user inputs.
// The variable "offering" is the dollar amount the user inputs.
// The variable "church_cp" is the percentage the user inputs.
 
function total_cp(offering, church_cp) {
 
          totalcp=offering*eval(church_cp/100); 
 
// In order for the computer to read church_cp as a percentage, it is divided by 100.
// The resulting number is multiplied by the offering amount, and the result of that calculation is stored in the "totalcp" variable.
 
          return totalcp;
 
}
 
function sbc_cp(offering, church_cp) {
 
          sbccp=0.505*eval(offering*eval(church_cp/100));
 
// Here, (and also in the functions below) the operation above is again used, but it is further multiplied by the percentage that has been designated by the convention.
 
// Note that these percentages must ALL be relative to the TOTAL CP budget.
// For example, if your convention gives 50% to the SBC, the number to multiply by would be "0.5".
// If 50% of that went on to the IMB, the number used for the IMB calculation would be "0.25", rather than "0.5".
// This is because 50% of 50% is 25%. 
// The number used would be the IMB percentage relative to the whole, rather than relative to the percentage designated for SBC.
 
          return sbccp;
}
 
function imb_cp(offering, church_cp) {
 
          imbcp=0.2525*eval(offering*eval(church_cp/100));
          return imbcp;
}
 
function namb_cp(offering, church_cp) {
 
          nambcp=0.11615*eval(offering*eval(church_cp/100));
          return nambcp;
}
 
function sem_cp(offering, church_cp) {
 
          semcp=0.1111*eval(offering*eval(church_cp/100));
          return semcp;
}
 
function erlc_cp(offering, church_cp) {
 
          erlccp=0.0101*eval(offering*eval(church_cp/100));
          return erlccp;
}
 
function fac_cp(offering, church_cp) {
 
          faccp=0.01515*eval(offering*eval(church_cp/100));
          return faccp;
}
 
// Now begin the SBC of Virginia specific percentages.
 
function sbcv_cp(offering, church_cp) {
 
          sbcvcp=0.495*eval(offering*eval(church_cp/100));
          return sbcvcp;
}
 
function mul_cp(offering, church_cp) {
 
          mulcp=0.24255*eval(offering*eval(church_cp/100));
          return mulcp;
}
 
function mat_cp(offering, church_cp) {
 
          matcp=0.198*eval(offering*eval(church_cp/100));
          return matcp;
}
 
function mob_cp(offering, church_cp) {
 
          mobcp=0.05445*eval(offering*eval(church_cp/100));
          return mobcp;
}
 
function checkform(form) {
 
       if (form.offering.value==null||form.offering.value.length==0 || form.church_cp.value==null||form.church_cp.value.length==0){
            alert("\nPlease complete the form first");
            return false;
       }
 
// This function ensures that the numbers that the user inputs are valid and able to be calculated.
// Sorry, our computer doesn't know how to multiply in greek.
 
       return true;
 
}
 
function computeform(form) {
 
       if (checkform(form)) {
 
       yourtotalcp=Math.round(total_cp(form.offering.value, form.church_cp.value)*100)/100;
       form.total_cp.value='$'+yourtotalcp.toFixed(2);
	   
	   yoursbccp=Math.round(sbc_cp(form.offering.value, form.church_cp.value)*100)/100;
       form.sbc_cp.value='$'+yoursbccp.toFixed(2);
	   
	   yourimbcp=Math.round(imb_cp(form.offering.value, form.church_cp.value)*100)/100;
       form.imb_cp.value='$'+yourimbcp.toFixed(2);
	   
	   yournambcp=Math.round(namb_cp(form.offering.value, form.church_cp.value)*100)/100;
       form.namb_cp.value='$'+yournambcp.toFixed(2);
	   
	   yoursemcp=Math.round(sem_cp(form.offering.value, form.church_cp.value)*100)/100;
       form.sem_cp.value='$'+yoursemcp.toFixed(2);
	   
	   yourerlccp=Math.round(erlc_cp(form.offering.value, form.church_cp.value)*100)/100;
       form.erlc_cp.value='$'+yourerlccp.toFixed(2);
	   
	   yourfaccp=Math.round(fac_cp(form.offering.value, form.church_cp.value)*100)/100;
       form.fac_cp.value='$'+yourfaccp.toFixed(2);
	   
	   yoursbcvcp=Math.round(sbcv_cp(form.offering.value, form.church_cp.value)*100)/100;
       form.sbcv_cp.value='$'+yoursbcvcp.toFixed(2);
	   
	   yourmulcp=Math.round(mul_cp(form.offering.value, form.church_cp.value)*100)/100;
       form.mul_cp.value='$'+yourmulcp.toFixed(2);
	   
	   yourmatcp=Math.round(mat_cp(form.offering.value, form.church_cp.value)*100)/100;
       form.mat_cp.value='$'+yourmatcp.toFixed(2);
	   
	   yourmobcp=Math.round(mob_cp(form.offering.value, form.church_cp.value)*100)/100;
       form.mob_cp.value='$'+yourmobcp.toFixed(2);
 
       }
 
// This function rounds off all of the numbers to the nearest cent. 
// Without it, we'd have a lot of odd fractions floating around.
 
       return;
}
