$().ready(function() {
	
	$('#email_calendar_form').jqm();
	$('#email_gallery_form').jqm();
	$('#join_form').jqm();
	//.jqmAddTrigger($('#email_calendar_link'));
	
	$('#email_calendar_link').click(function(){
		$('#email_calendar_form').jqmShow();
	});
	
	$('#email_gallery_link').click(function(){
		$('#email_gallery_form').jqmShow();
	});
	
	$('#join_form_link').click(function(){
		$('#join_form').jqmShow();
	});
	
	$('div#leftnav').jScrollPane();
	//$('div#maincontent').jScrollPane();
	//$('div#photo_gallery').jScrollPane();
	
	$('#print_link').click(function(){
		window.print();
	});
	
});

function handleEmailCalendar(calForm) {
	$('#email_calendar_submit').attr('disabled','disabled');
	theData = $(':input',calForm).serialize();
	
	$.ajax({
		data: theData,
		dataType: 'json',
		type: "POST",
		url: 'send_email_calendar.php',
		success: handleEmailSuccess,
		error: handleEmailFailure
	});
	
	return false;
}

function handleEmailGallery(calForm) {
	$('#email_gallery_submit').attr('disabled','disabled');
	theData = $(':input',calForm).serialize();
	
	$.ajax({
		data: theData,
		dataType: 'json',
		type: "POST",
		url: 'send_email_gallery.php',
		success: handleEmailSuccessGallery,
		error: handleEmailFailureGallery
	});
	
	return false;
}

function handleEmailSuccess(jResponse) {
	if (jResponse['error'] == 'false') {
		$('#success_message').html(jResponse['message']);
		$('#email_success').jqm().jqmShow();
		$('#email_calendar_form').jqmHide();
	} else {
		$('#error_message').html('<span class="error">Error:</span> '+jResponse['message']);
	}
	$('#email_calendar_submit').removeAttr('disabled');
}

function handleEmailFailure(oXMLRPC,sError,errorThrown) {
	//alert(sError+':'+errorThrown);
	$('#error_message').html('<span class="error">Error:</span> Sorry your e-mail could not be sent at this time, please try again later.');
	$('#email_calendar_submit').removeAttr('disabled');
}

function handleEmailSuccessGallery(jResponse) {
	if (jResponse['error'] == 'false') {
		$('#success_message').html(jResponse['message']);
		$('#email_success').jqm().jqmShow();
		$('#email_gallery_form').jqmHide();
	} else {
		$('#error_message').html('<span class="error">Error:</span> '+jResponse['message']);
	}
	$('#email_gallery_submit').removeAttr('disabled');
}

function handleEmailFailureGallery(oXMLRPC,sError,errorThrown) {
	//alert(sError+':'+errorThrown);
	$('#error_message').html('<span class="error">Error:</span> Sorry your e-mail could not be sent at this time, please try again later.');
	$('#email_gallery_submit').removeAttr('disabled');
}
