$(document).ready(function(){

	// Homepage rotation
	$('#home-content .content').cycle({timeout:12000});
	
	//Enable external links
	$('a[href^="http"]').attr('target','_blank');
	
	//Setup form field with default value
	$('div#header form input[type=text]').attr('value', function(){
		var title = $(this).attr('title');
		return title;
	}).focus(function(){
		if( $(this).val() != '' && $(this).val() == $(this).attr('title'))
			$(this).val('');
	}).blur(function(){
		if( $(this).val() == '')
			var value = $(this).attr('title');
			$(this).attr('value', value);
	});
	
	// donate form
	  if ($('form#donate'.length)) {
	    $('#Other').click(function() { $('#amountCustom').attr('checked','checked'); });
	    $('input[name=amount]:radio').not('#amountCustom').click(function() {
	      $('#Other').val('');
	    });
	    $('#period').change(function() {
	      if ($(this).val()) {
	        $('#recurring_term').removeAttr('disabled').val('5');
	        $('.recurrentOpts').show();
	      } else {
	        $('#recurring_term').attr('disabled','disabled').val('');
	        $('.recurrentOpts').hide();
	      }
	    });
	    $('.recurrentOpts').hide();

	    $('#period,#recurring_term,input[name=amount]').change(function() {
	      var total = $("input[name=amount]:checked").val();
	      if (total == 'Other') { total = $('#Other').val(); }
	      $('#totalAmount strong').text( '$' + total * $('#recurring_term').val() );
	    });
	    $('#donate').validate({
	      submitHandler: function(form) {
	        $('#SubmDonation').val('Sending...').attr('disabled','disabled');
	        form.submit();
	      }
	    });
	  }
	
});
