;(function($){
    $.fn.extend({
	ourDialog: function(options) {
	    if (typeof options == "string"){
		if(options == "params") {
		    var elem = $(this).parents(".ui-dialog:first").find(".ui-dialog-content:first");
		    params = {};
		    elem.find("*:input").each(function() {
			params[$(this).attr("name")] = $(this).val();
		    });
		    return params;
		} else if(options == "destroy") {
		    var elem = $(this).parents(".ui-dialog:first").find(".windowbg");
		    this.dialog("destroy");
		    elem.remove();
		} else 
		    this.dialog(options);
	    } else {
		ao = options.autoOpen || true;
		co = options.close;
		options.autoOpen = false;
		options.close = function(e, o) {
		    co && co(e, o);
		    $(this).ourDialog("destroy");
		};
		this.dialog(options);
		dialog = this.parents(".ui-dialog:first").addClass("roundborder");
		dialog.css("overflow","visible").append('<div class="corner_tl"></div><div class="corner_tr"></div><div class="corner_bl"></div><div class="corner_br"></div>');
		container = dialog.children(".ui-dialog-container:first");
		title = container.children(".ui-dialog-titlebar:first").addClass("titlebg");
		content = container.children(".ui-dialog-content:first").addClass("windowbg");
		if(ao) this.dialog("open");
		return this;
	    }
	}
    });
    
    $.alert = function(str) {
	$("<center>"+str+"</center>").ourDialog({
	    modal: true,
	    height:100,
	    buttons: {"Ok": function() { $(this).ourDialog("destroy"); } }
	});
    };
})(jQuery);

