(function($,undefined){
	$.widget("ui.mw",{
		options:{
			title:false
			,width:200
			,height:false
			,background:false
			,sourceId:false
			,text:''
			,autoHide:false
			,notClosable:false
		},
		_create:function(){
			var self = this;
			self.main = self.element;
			self.main.hide();
			self.bg = $('<div>').addClass('ui_mw ui_mw_bg').appendTo(self.main);
			self.vertal = $('<div class="ui_mw_va"><table><tr><td style="width:50%;"></td><td content="true" class="ui_mw_va_content"></td><td style="width:50%;"></td></tr></table></div>').appendTo(self.main);
			self.content = $('<div>').addClass('ui_mw ui_mw_form').css('width',self.options.width+'px').appendTo(self.vertal.find('td[content]'));
			if(self.options.background){
				self.vertal.find('td[content]').css('background',self.options.background);
			}
			if(self.options.height){
				self.content.css('height',self.options.height+'px');
			}
			//self.content = $('<div>').addClass('ui_mw ui_mw_form').css('width',self.options.width+'px').appendTo($('<div>').addClass('ui_mw_va').appendTo(self.main));
			if (!self.options.notClosable) {
				self.closeButton = $('<a>').addClass('ui_mw_close').html('&times;').appendTo(self.content);
				$([]).add(self.vertal.find('td').not('[content]')).add(self.bg).add(self.closeButton).click(function(){self.main.animate({opacity:"hide"},"slow");});
			}
			if(self.options.title){
				self.title = $('<h3>').addClass('ui_mw_title').text(self.options.title).appendTo(self.content);
			}
			self.text = $('<p>').text(self.options.text);
			if(self.options.sourceId){
				self.text = $('#'+self.options.sourceId);
			}
			self.text.appendTo(self.content);
		},
		show:function(str,stretchable){
			var self = this;
			if(typeof stretchable != 'undefined'){
				self.content.css('width','');
			}else{
				self.content.css('width',self.options.width+'px');
			}
			if(str && !self.options.sourceId){
				self.text.html(str);
			}
			self.main.show();
			if(self.options.autoHide){
				setTimeout(function(){
					self.hide();
				},self.options.autoHide);
			}
		},
		hide:function(){
			var self = this;
			self.main.animate({opacity:"hide"},"slow");
		}
	});
	$.extend($.ui.mw,{
		version: "1.0"
	});
})(jQuery);

