$(document).ready(function(){
	init();
	
	$("#aaas .pledgetopackform .formsubmit").click(function() {		
		var place = 		$("input#uktux-uktux").val().indexOf("@",1);
		var point = 		$("input#uktux-uktux").val().indexOf(".",place+1);
		var email = 		$("input#uktux-uktux").val();
		var name = 		$("input#name").val();
		
		if( $("input#Contact") ){ 			var contact = 		$("input#Contact").val(); }
		if( $("input#Address") ){ 			var address = 		$("input#Address").val(); }
		if( $("input#State") ){ 				var state = 			$("#aaas .pledgetopackform #State option:selected").text(); }
		if( $("input#City") ){ 					var city = 				$("input#City").val(); }
		if( $("input#Zip") ){ 					var zip = 				$("input#Zip").val(); }
		if( $("input#BoxesPledged") ){ 	var pledge = 		$("input#BoxesPledged").val(); }
		if( $("input#FormSource") ){ 		var source = 		$("input#FormSource").val(); }
		if( $("input#Phone") ){ 				var phone = 			$("input#Phone").val(); }
		if( $("#eventdesc") ){ 					var eventdesc = 	$("#eventdesc").val(); }


		if (email == "") {
     		alert('Email address is required');
      		$("input#uktux-uktux").focus();
      		return false;
    	}else if (name == "") {
        	alert('name field required');
      		$("input#name").focus();
      		return false;
    	}else{
    		if((place > -1) && (email.length >2) && (point > 1) && (name.value != "")){
    			var dataString; 
    			
    			if( source == "Pledge To Pack" ){
    				dataString = 'name='+ name + '&email=' + email + '&contact=' + contact + '&address=' + address + 
    				 '&city=' + city + '&state=' + state + '&zip=' + zip +  '&source=' + source + '&pledge=' + pledge;
    				 
    			}
    			else if ( source == "Give Back" ){
    				dataString = 'name='+ name + '&email=' + email + 
    				 '&city=' + city + '&state=' + state +  '&source=' + source + '&phone=' + phone + '&event=' + eventdesc;			
    			}
    			else{
    				dataString = 'name=' + name + '&email=' + email;
    			}	
				$.ajax({
					type: "POST",
					url: "script/register.php",
					data: dataString,
					success: function() {
						var thisid = $("#aaas .pledgetopackform").attr("id");
						var thisForm = document.getElementById(thisid);
						thisForm.method = "post";
						thisForm.action = "http://globalthinking.createsend.com/t/y/s/uktux/"
						thisForm.submit();
				
		     		}
		     	});
    			return false;
		
			}else{
				alert( "Please enter a valid e-mail address." );
				return false;
    		}	
		}

	
	} );
});

function init(){
	$('li.supporter:gt(3)').css({"display":"none"});

	var autoTime = 5000;
	var currentset = 1;
	
	setInterval(function(){
		currentset++;
		
		if( currentset == 2 ){
			$('li.supporter').slice(0, 4).fadeOut("slow", function(){
				$('li.supporter').slice(4, 8).fadeIn("slow");
			}, 2000 );		
		}
		
		if( currentset == 3 ){
			$('li.supporter').slice(4, 8).fadeOut("slow", function(){
				$('li.supporter').slice(8, 12).fadeIn("slow");
			}, 2000 );		
		}
		
		if( currentset == 4 ){
			
			$('li.supporter').slice(8, 12).fadeOut("slow", function(){
				$('li.supporter').slice(0, 4).fadeIn("slow");
			}, 2000 );	
			currentset = 1;	
		}
		
	}, 8000);
}




