/*
 jQuery UI Modal Dialogs - Alert and Confirm 0.1
 dialogs.js
 Colton Provias
 December 30, 2009
 http://ColtonProvias.com
*/

(function($) {
	$.extend({
		confirm: function(options) {
			/*
			 Confirm dialog for jQuery UI.  Accepts the following options:
				title - The title of the dialog
				text - The text within the dialog
				text_true - Text for the true button
				text_false - Text for the false button
				ontrue - callback for true response
				onfalse - callback for false response.
				onclose - callback for dialog close.
			*/
			
			if (!options) var options = {};
			
			// Define the buttons
			var buttons = {};
			buttons[(options.text_false)?options.text_false:"Cancel"] = function() {
				$('#confirm-dialog').dialog('close');
				if (typeof options.onfalse == 'function') options.onfalse();
			};
			buttons[(options.text_true)?options.text_true:"OK"] = function() {
				$('#confirm-dialog').dialog('close');
				if (typeof options.ontrue == 'function') options.ontrue();
			}
			
			// Create the dialog in the DOM
			$('body').append('<div id="confirm-dialog"><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>' + (options.text?options.text:"Are you sure?") + '</div>');
			
			// jQuery UI dialog
			$('#confirm-dialog').dialog({
				bgiframe: true,
				height: (options.height) ? options.height : 150,
				width: (options.width) ? options.width : 300,
				title: (options.title) ? options.title : "Confirm",
				modal: true,
				stack: false,
				draggable: true,
				closeOnEscape: true,
				buttons: buttons,
				close: function() {
					$('#confirm-dialog').remove();
					if (typeof options.onclose == 'function') options.onclose();
				}
			})
		},
		alert: function(options) {
			/*
			 Alert dialog for jQuery UI.  Accepts the following options:
				title - The title of the dialog
				text - The text within the dialog
				button - The text on the button
				onclose - Callback for when the window is closed
			*/
			
			if (!options) var options = {};
			
			// Define the buttons
			var buttons = {};
			buttons[(options.button)?options.buttons:"OK"] = function() {
				$('#alert-dialog').dialog('close');
			}
			
			// Create the dialog in the DOM
			$('body').append('<div id="alert-dialog"><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>' + (options.text?options.text:"Velociraptor Attack") + '</div>');
			
			// jQuery UI dialog
			$('#alert-dialog').dialog({
				bgiframe: true,
				height: (options.height) ? options.height : 150,
				width: (options.width) ? options.width : 300,
				title: (options.title) ? options.title : "Alert",
				modal: true,
				stack: false,
				draggable: true,
				closeOnEscape: true,
				buttons: buttons,
				close: function() {
					$('#alert-dialog').remove();
					if (typeof options.onclose == 'function') options.onclose();
				}
			})
		}
	})
})(jQuery);
