// Dependency: jquery-1.2.6.js, jquery-ui-1.6.js

Dialog = function(options){	
	var that = this;
	
  this.defaults = {
  	id: "alertDialog",
		width: 300,
		height: 120,
		title: "Information",
  	message: "&nbsp;",
  	autoOpen: false,
  	autoClose: false,
  	modal: true,
  	opacity: '0.85',
  	backgroundColor: '#F2F2F2',
  	cssClass: "myDialog",
  	buttons: {}};
  
  // "Private" Methods
	var _create = function(){
		jQuery('body').append('<div id="'+that.id+'"></div>');
		jQuery("#"+that.id).dialog({autoOpen: that.autoOpen, bgiframe: true, width: that.width, height: that.height, modal: that.modal, closeOnEscape: false, draggable: false, overlay: {opacity: that.opacity, backgroundColor: that.backgroundColor}, resizable: false, title: that.title});
		that.update();
  };
  
  // Public Methods  
  this.show = function(){
  	jQuery('#'+this.id).dialog('open');
		if(this.autoClose)
			jQuery('#'+this.id).animate({left:"+=0"},2000,function(){jQuery('#'+this.id).dialog('close');});
  };
  
  this.hide = function() {jQuery('#'+this.id).dialog('close');};
  
  this.reDraw = function(){
  	if(jQuery('#'+this.id).dialog('isOpen'))
  	{
  		this.hide();
  		this.show();
  	}
  };
  
  this.update = function(updatedParams){
  	jQuery.extend(this, updatedParams);
  	
  	jQuery('#'+this.id).addClass(this.cssClass);
		jQuery("#"+this.id).data("modal.dialog",this.modal).data("overlay.dialog",{opacity: this.opacity, backgroundColor: this.backgroundColor});
		jQuery("#"+this.id).html('<div class="dialogMessage" id="'+this.id+'_dialogMessage">'+jQuery('#comment_form_div').html()+'</div>');
		jQuery('#ui-dialog-title-'+this.id).html('<span>'+this.title+'</span>');
		jQuery("#"+this.id).data("width.dialog", this.width).data("height.dialog", this.height);  
		jQuery("#"+this.id).data("buttons.dialog", this.buttons );
		this.reDraw();
  };
  
  // Constructor
	for(var property in this.defaults) this[property] = this.defaults[property];
	jQuery.extend(this, options);
	_create();
}
