function initDonateAndSend(showForm) {
	
	initPostCardPopUp(showForm);
	initMultipleEmails();
	initOtherAmount();
	
}

function initOtherAmount() {
	var freeformDiv = $('#freeformAmount');
	var freeformInput = $('input.freeform_amount');
	freeformDiv.hide();
	$('input[name=preselect_amount]:radio').click(function() {
		var isOtherRadio = $(this).attr('value') == -1;
		if (isOtherRadio)
			freeformDiv.show();
		else
			freeformDiv.hide();
	});			
	
	//trigger currently selected radio
	var selectedRadio = $('input[name=preselect_amount]:radio:checked');
	selectedRadio.click();
}

function initMultipleEmails() {
	
	//add button
	$('#add_another_holder').html("<a id=\"add_another_friend\" href=\"#\">+ Add another friend</a>");
				
	//get fields
	var toEmail = $('#recipients .fieldInput');
	var toName = $('#recipients .fieldEmailInput');
	
	//hide all except the first
	toEmail.not(':first').hide();
	toName.not(':first').hide();
	var numDisplayedEmails = 1;
	var totalAvailableEmails = toEmail.length;
	
	//enable "add" button
	$('#add_another_friend').click(function(){
		toEmail.eq(numDisplayedEmails).show();
		toName.eq(numDisplayedEmails).show();
		numDisplayedEmails++;
		$("#recipients").attr({ scrollTop: $("#recipients").attr("scrollHeight") });
		if (numDisplayedEmails == totalAvailableEmails)
			$(this).hide();
		//enableCustomScrollBars();
		return false;
	});
	
	//find the email or name field furthest down the list which has been filled in
	var lastFilledEmailIndex = 0;
	var lastFilledNameIndex = 0;
	for (var i=0; i<totalAvailableEmails; i++)
	{
		if (toEmail.eq(i).attr('value') != "")
			lastFilledEmailIndex = i;
		if (toName.eq(i).attr('value') != "")
			lastFilledNameIndex = i;
	}
	var lastFilledField = Math.max(lastFilledEmailIndex, lastFilledNameIndex);
	
	//simulate enough clicks to open up enough email fields
	for (var i=0; i<lastFilledField; i++)
		$('#add_another_friend').click();
}

function initPostCardPopUp(showForm) {
	var postcardForm = $('#form');
	var postCardMessage = $(".imageCardNumber");
	postcardForm.hide();
	postcardForm.addClass('popup');
	$('#content').css('position', 'relative'); //set this in css?
	$('#preview').click(function() {
		if (postcardForm.is(':visible')) {
			postcardForm.hide();
			postCardMessage.show();
		}
		else {
			postcardForm.show(); 
			postCardMessage.hide();
		}
		return false;
	});
	if (showForm)
		$('#preview').click();
}

/*function enableCustomScrollBars()
{
	$('#recipients').jScrollPane(
			{
				showArrows:true, 
				scrollbarWidth: 10,
				reinitialiseOnImageLoad: true
			});			
};*/
