// Options set for simple modal.

var modalOptions = {
	'opacity':20,
	'overlayCss':{backgroundColor:'#000'},
	'autoResize':true,
	'overlayClose':true,
	'onClose': function (dialog) {
		dialog.data.fadeOut('fast', function() {
			dialog.overlay.fadeOut('fast', function() {
				$.modal.close();
			});
		});
	}
}

// Set up AJAX
function modal(url, data, width, height) {
	if (data==null) data={};
	$('#modal').css('width',(width)? width+'px':''); // Set / reset width
	$('#modal').css('height',(height)? height+'px':''); // Set / reset height
	$.post(url, data, modalResponse);
} // End function modal()

// Modal for non-ajax pages
function div_modal(divID, width) {
	if (width) $('#modal').css('width', width+'px');
	modalResponse($('#'+divID).html());
}

// Process response
function modalResponse(data) {
	if (data) {
		// Close existing modal, if any
		$.modal.close();

		// Set up new modal
		$('#modal-content').html(data);
		$('#modal').modal(modalOptions);
	}
} // End function modalResponse()

// Close modal window
function closeModal() {
	$.modal.close();
} // End function closeModal()
