
$('document').ready (
	function () {		
		var newCampaignButton = $('#new-campaign-button.button-wrapper');
		newCampaignButton.click(function () {
			var pane = $('#add-campaign-pane td > div');
			pane.animate({ height: 'toggle' }, 1000, 'easeinout');

			if (newCampaignButton.html () == '<img src="/img/admin-icon-add.gif" alt="">Add new campaign')
				newCampaignButton.html('<img src="/img/admin-icon-cancel.gif" alt="" />Cancel');
			else
				newCampaignButton.html('<img src="/img/admin-icon-add.gif" alt="" />Add new campaign');
		});
		
		$('.edit-campaign-button').click(function () {
			
			var obj = $(this).parent ().parent ().next ().children ().eq (0).children ().eq (0);
			resetPanes (obj);
			obj.animate({ height: 'toggle' }, 1000, 'easeinout');
		});
		
		var newUpdateButton = $('#new-update-button.button-wrapper');
		newUpdateButton.click(function () {
			var pane = $('#add-update-pane td > div');
			pane.animate({ height: 'toggle' }, 1000, 'easeinout');

			if (newUpdateButton.html () == '<img src="/img/admin-icon-add.gif" alt="">Add new update')
				newUpdateButton.html('<img src="/img/admin-icon-cancel.gif" alt="" />Cancel');
			else
				newUpdateButton.html('<img src="/img/admin-icon-add.gif" alt="" />Add new update');
		});
		
		var newSiteUpdateButton = $('#add-siteupdate-button.button-wrapper');
		newSiteUpdateButton.click(function () {
			var pane = $('#add-siteupdate-pane td > div');
			pane.animate({ height: 'toggle' }, 1000, 'easeinout');

			if (newSiteUpdateButton.html () == '<img src="/img/admin-icon-add.gif" alt="">Add news update')
				newSiteUpdateButton.html('<img src="/img/admin-icon-cancel.gif" alt="" />Cancel');
			else
				newSiteUpdateButton.html('<img src="/img/admin-icon-add.gif" alt="" />Add news update');
		});
});

function resetPanes (exclude)
{
	$('.hidden-pane-content').each (function () {
		var obj = $(this);
			
		if (obj.css ('display') != 'none' && obj.get (0) != exclude.get (0)) {
			$(this).animate({ height: 'toggle'}, 1000, 'easeinout');
		}
	});
	
	// Make sure the 'Add Campaign' button is right
	var newCampaignButton = $('#new-campaign-button.button-wrapper');
	var newCampaignPane = $ ('#add-campaign-pane td > div');
	if (newCampaignPane.css ('display') == 'none')
		newCampaignButton.html('<img src="/img/admin-icon-add.gif" alt="" />Add new campaign');
	else 
		newCampaignButton.html('<img src="/img/admin-icon-cancel.gif" alt="" />Cancel');
}