/*====================================================================================================*/

(function ($) {
	$.fn.closeButton = function() {
		$(this).each(function () {
			$(this).prepend('<a title="Close" href="javascript:;" class="close-button">X</a>');
		});
		return this;
	}
})(jQuery);

/*====================================================================================================*/

$(document).ready(function () {

/*====================================================================================================*/

	var ajaxLoader = '<div class="ajax-loader ajax-loader-large"></div>';

/*====================================================================================================*/

	/*
		Add the 'selected' class to checked inputs parents
		This will work for multiple options
		Had to use live() to get this to work in ajax loaded modals
		the .selected class should be set without javascript as well
	 */
	$(":checkbox, :radio").live('change', function () {
		var name = $('input[name="' + $(this).attr('name') + '"]');
		$(name + ':not(:checked)').parent().removeClass('selected');
		$(name + ':checked').parent().addClass('selected');
	});
	$("input:checked").parent().addClass('selected');
	
	/*
		Multi-select options
	*/
	$('.multiselect .toggle :checkbox').change(function () {
		$checked = $(this).attr('checked');
		$(this).parents('.multiselect').find(':checkbox:not(:disabled)').attr('checked', $checked);
	});

/*====================================================================================================*/

	$('.message').closeButton().hide().fadeIn();

	$('.close-button').live('click', function () {
		$(this).parent().fadeTo(400, 0, function () {
			$(this).slideUp('fast', function () {
				$(this).remove();
			});
		});
	});

/*====================================================================================================*/

	// Open all PDF files and external links in a new tab
	$('a[href*=.pdf], a[href^=http], a[href^=/*:]')
	.not('[href^='+BASE_URL+']').click(function (e) {
		e.preventDefault();
		window.open(this.href);
	});

/*====================================================================================================*/

	$('.admin-editable').addClass('disabled');
	$('#edit_mode').click(function () {
		$('.admin-editable').toggleClass('disabled');
	});

/*====================================================================================================*/
});
/* end file */
