		
		
		$(function() {
			if(!$.dialog){
				$.extend({
					dialog : function(){
						var _dialogIndex = 0;
						var _dialogWithFocus = null;
						
						function createDialogContentWrap(){
							_dialogIndex++;
							var dialogContent = $('<div></div>').attr('id', 'dialog_'+_dialogIndex);
							$(document).append(dialogContent);
							return dialogContent;
						}
						function launchDialog(type, title, target, callback, options){
							if(callback == null){callback = function(){};}
							if(options == null){options = {};}

							var dialogOptions = {
								preInit: function(){
									/* preInit added to jQuery.ui file by Steff on the "ui.dialog" widget. comment in the file is DATADIAL MOD */
									$(this).data('originalParent',$(this).parent());
								},
								close: function(event, ui){
									$(this).dialog('destroy');
									$(this).data('originalParent').append(this);
									if($(this).attr('type')!='local'){
										$(this).remove();
									}
								},
								focus: function(event, ui){
									$.dialog.current = this;
								},
								open: function(event, ui){
									$.dialog.current.callback = callback;
									$.dialog.current.close = function(){
										$(this).dialog('close');
									};
								},
								modal:true,
								resizable: false
							};
							$.extend(dialogOptions, options);

							var dialogContentWrap = null;
							
							switch(type){
								case 'ajax':
									dialogContentWrap = createDialogContentWrap();
									dialogContentWrap.load(target);
									break;
								case 'framed':
									dialogContentWrap = createDialogContentWrap();
									dialogContentWrap.mouseenter(function(){
										$.dialog.current = this;				   
									});
									dialogContentWrap.append('<iframe style="width:99%; height:99%;" frameborder="0" src="'+target+'"></iframe>');
									break;
								case 'local':
									dialogContentWrap = $(target);
									break;
							}
							dialogContentWrap.attr('type', type);

							return dialogContentWrap.dialog(dialogOptions).dialog('option' , 'title', title).dialog('open');
						}
						
						return {
							current: _dialogWithFocus,
							launch: function(title, url, callback, options){
								return launchDialog('ajax', title, url, callback, options);
							},
							launchLocal: function(title, contentElem, callback, options){
								return launchDialog('local', title, contentElem, callback, options);
							},
							launchFramed: function(title, url, callback, options){
								return launchDialog('framed', title, url, callback, options);
							},
							alert: function(text, title){
								if(title == null){title = 'Message';}
								
								var dialog = createDialogContentWrap();
								return dialog.attr('title', title)
									.html(text)
									.dialog({
										resizable: false,
										modal : true,
										buttons:	{
											OK: function(){
												$(this).dialog('close');
											}
										}
									});
							},
							confirm: function(text, callback, title){
								if(title == null){title = 'Are you sure?';}
								if(callback == null){callback = function(){};}
								var dialog = createDialogContentWrap();
								return dialog.attr('title', title)
									.html(text)
									.dialog({
										resizable: false,
										modal : true,
										buttons:	{
											Cancel: function(){
												$(this).dialog('close');
											},
											OK: function(){
												callback();
												$(this).dialog('close');
											}
										},
										width:350
									});
								
							}
						}	
					}()
				});
			}
		});
