function rekeyFields() {

var fields = ["exclusive", "title", "description", "files"];
var i = 1;

	$(".goalsBox").each(function(){
	
		$("input[name*=exclusive]", this).attr("name", "exclusive["+i+"]");
		$("input[name*=title]", this).attr("name", "title["+i+"]");
		$("textarea[name*=description]", this).attr("name", "description["+i+"]");
		$("input[name*=files]", this).attr("name", "files["+i+"]");
					
		i = i + 1;
	
	});
	
};


function addGoal() {

	$("#goalsContainer").append($("#goalsTemplate").html());
	$("#goalsContainer .goalsBox").slideDown();
	
	initiateListeners();

}
    
function initiateListeners() {
	$(".prependedCheckbox").unbind().click(function(){
		$(this).parent().toggleClass("active");
	});
	$(".goalsBox a.minusGoal").click(function(){ 
		$(this).parent().parent().slideUp(function(){
			$(this).remove();
		});
	});
	
}

function email() {

	$("#goalsTemplate").html("");
	$("#addButton").addClass("disabled");

	console.log($("#goalCreator").serialize());
	$("#goalCreator").submit();

}

$(function(){
    addGoal();
	});
