var Trager = {
	
	slide_num : Number = 0,
	slide_int : Number,
	slide_total : Number = 5,
	slide_z : Number = 100,
	
	default_email : String,
	
	init : function()
	{
		$(document).pngFix();
		
		if($('a.bb').size()) Trager.slide_int = setInterval('Trager.change_slide()',3500);
		
		Trager.check_other_amount();
		$('#one_time_contribution').bind('change',Trager.check_other_amount);
		
		$('a.expand').bind('click', Trager.expand_content);
		
		Trager.default_email = $('#ea').val();
		$('#ea').bind('click', Trager.clear_email)
				.bind('blur', Trager.check_email);
	},
	
	expand_content : function()
	{
		var id = $(this).attr('rel');
		$('#short_'+id).toggle();
		$('#long_'+id).toggle();
		return false;
	},
	
	clear_email : function()
	{
		var val = $(this).val();
		if(val==Trager.default_email)
		{
			$(this).val('');
		}
	},
	
	check_email : function()
	{
		var val = $(this).val();
		if(!val)
		{
			$(this).val(Trager.default_email);
		}
		
		// alert(val);
	},
	
	check_other_amount : function()
	{
		// check other amount
		var one_time_contribution = $('#one_time_contribution');
		var other_amount = $('#other_amount');
		
		if(one_time_contribution.val()!='other')
		{
			other_amount.parents('div.form').hide();
		}
		else
		{
			other_amount.parents('div.form').show();
		}
	},
	
	change_slide : function()
	{
		// if(window.console) window.console.log('ds');
		var slide = $('a.bb:first-child');
		slide.hide();
		$('#billboard').append(slide);
		slide.fadeIn(1500);
	},

	validate_form : function(form)
	{
		if(!form) form = document.forms[0];
		var submit_it = true;
		var email_pattern = new RegExp(/[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i);

		$(form).find(".REQUIRED").each(function(req)
		{
			if(($(this).attr('type')!='checkbox' && this.value == '') || 
				($(this).attr('type')=='checkbox' && !this.checked)) 
			{
				$(this).parents("div.form").addClass('error');
				submit_it = false;
			}
			else
			{
				$(this).parents("div.form").removeClass('error');
			}			
		});
		if( !submit_it ) 
		{
			$('#error_message').html('Please review the highlighted, required fields and resubmit.').fadeIn(250);
			$.scrollTo('#error_message', 800, {easing:'easeInOutCubic'});
		}
		return submit_it;
	}
}

$(document).ready(function() {
	Trager.init();
});
