/* LiveWhale Website Effects */
/* Requires jQuery */

$(function() { // on DOM ready
	if ($('#callout_showmore').length) {
		$('#callout_showmore').attr('href','#').toggle(function() { // reset the link to an anchor and on click
			$('#callout').animate({width:630,marginLeft:-360}); // slide the callout out
			return false; // and cancel the anchor click
		},function() { // or
			$('#callout').animate({width:330,marginLeft:-60}); // slide the callout out
			return false; // and cancel the anchor click
		});
		$('#callout form').live('submit',function() {
			var form = $(this);
			form.css('opacity','0.5').find('input').attr('disabled');
			$.post('?',form.serialize(),function(response) {
				var results = $(response).find('#callout_more');
				if(results.find('form').length) { // if there's still a form
					results.find('p').eq(0).addClass('error');
					$('#callout_more').html(results.html()); // it's an error!		
				} else { // if success
					$('#callout_showmore').click();
					results.find('a').attr('id','callout_showmore');
					$('#callout_start').html(results.html());
				}
			});
			return false;
		});
	};
	if ($('#simple_click').length) {
		$('#simple_click').click(function() { // alias the edit page link
			$('#lw_pages_edit_link').click();
			return false;
		});
		$('#lw_pages_edit_link').click(function() {
			$('#lw_pages_editor_save_publish').unbind('click').click('click',function() {
				alert('Of course we\'re not going to save that!');
				livewhale.pages_editor.cancelEditing();
				return false;
			});
			$('#lw_pages_editor_save_draft').unbind('click').click('click',function() {
				alert('Of course we\'re not going to save that!');
				livewhale.pages_editor.cancelEditing();
				return false;
			});
		});
	};
});
