
	var ajaxOptions = {
		beforeSubmit: beforeAjaxSubmit,
		success: afterAjaxSubmit,
		dataType: 'json'
	};

	/**
	* ready()
	* Runs after all elements have been registered within the DOM.
	**/
	jQuery(document).ready(function(){
		$(this).bindLinks();

		// Hide all accordion sub-menu's and show selected sub menu's.
		$('.side-nav .head').next().hide();
		$('.side-nav .head-selected').next().show();
	});

	/**
	* ajaxLink()
	* Loads ajax content from the location specified in the href of the clicked link.
	* Once content is loaded, re-binds click events.
	**/
	jQuery.fn.ajaxLink = function(menu, element) {
		//alert(1);
		/*if ($(this).hasClass('head') && (menu !== true)) {
			return false;
		}*/
		//$('.loader').slideDown(250);
		$('#inside-content').load($(this).attr('href'), function() {
			//$('.loader').slideUp(250);
			$(this).bindLinks(menu, element); // Bind links for newly loaded content.
		});
		return false;
	};

	/**
	* menuLink()
	* Handles opening and closing or sub menu's for the accordion-like menu.
	**/
	jQuery.fn.menuLink = function() {
		if ($(this).next().is(':hidden')) {
			$(this).addClass('selected');
			$(this).ajaxLink(true);
		} else {
			$(this).removeClass('selected');
		}
		$(this).next().toggle(250);
		return false;
	}
	
	/**
	* menuLink()
	* Handles opening and closing of sub menu's for the accordion-like menu.
	**/
	jQuery.fn.deleteLink = function() {
		var check = confirm('Are you sure you want to delete the specified item?')
		if (check) {
			$('.loader').slideDown(250);
			var redirect = $(this).attr('rel');
			$.getJSON($(this).attr('href'), function(data) {
				if (data.success) {
					if ($('#dialog').is(':visible')) {
						$('#dialog').dialog('close');
					}

					$('#inside-content').load(redirect, function() {
						$('.loader').slideUp(250);
						$(this).bindLinks();
					});
				} else {
					$('.loader').slideUp(250);
					alert('There was an error while attempting to delete the specified item.\nPlease try again.');
				}
			});
		}
		return false;
	}

	/**
	* dialogLink()
	* Handles opening and closing of dialog boxes for adding/editing/viewing items.
	**/
	jQuery.fn.dialogLink = function() {
		var dialog = $('#dialog');
		var title = $(this).attr('title');
		var url = $(this).attr('href');
		var height = (($(this).attr('rev')) && ($(this).attr('rev') != '')) ? $(this).attr('rev') : 250;
		
		dialog.empty().dialog({
			minWidth: 500,
			minHeight: height,
			modal: true,
			title: title,
			open: function() {
				dialog.load(url);
			}
		});
		
		return false;
	}

	/**
	* triggerMessage()
	* When a session flash is displayed, this will automatically hide it after 5 seconds.
	**/
	jQuery.fn.triggerMessage = function() {
		$('#flashMessage').delay(5000).slideUp(250);
	}

	/**
	* bindLinks()
	* Unbinds and binds links when elements have been added to the DOM.
	**/
	jQuery.fn.bindLinks = function() {

		// Bind ajax links. Must be unbound and bound before accordion links.
		$('.ajax-link').unbind('click');
		$('.ajax-link').bind('click', function() {
			return $(this).ajaxLink();
		});

		// Bind accordion menu links
		$('.side-nav .head, .side-nav .head-selected').unbind('click');
		$('.side-nav .head, .side-nav .head-selected').bind('click', function() {
			return $(this).menuLink();
		});
		
		// Bind dialog links
		$('.dialog').unbind('click');
		$('.dialog').bind('click', function() {
			return $(this).dialogLink();
		});

		// Bind delete links.
		$('.delete-item').unbind('click');
		$('.delete-item').bind('click', function() {
			return $(this).deleteLink();
		});

	}

	// Called before submitting ajax form
	function beforeAjaxSubmit(formData, jqForm, options) {
		if (!$('#' + $(jqForm).attr('id')).validate().form()) {
			return false;
		}
		
		if ($('#dialog .submit')) {
			$('#dialog .submit').hide();
			$('#dialog .submit-loader').show();
		}
		
		
		return true;
	}

	// Called after submitting ajax form
	function afterAjaxSubmit(data) {
		var callback, message, message_class, message_icon;
		$('.overlay').hide();
		if (data.callback) {
			callback = data.callback;
			eval('$(this).' + callback + '(data)');
		} else if (data.success || data.error) {
			$.callbackMessage(data);
		}
	}


