var Common = {};	
	Common.Dialog = function(config){
		for(var key in config){
			this[key] = config[key];
		}
		this.init();
		
	};
	Common.Dialog.prototype = {
		height:310,
		width: 404,
		dlgClassName: "dialog",
		title: undefined,	///如果给值，建立title，并且为title显示的内容{value:'', cls:''}
		closeIcon: true,
		addContent: true,
		buttons: undefined,	//{[{value:'',event:'close'}],[{value:''}]}
		dialogShadow: true,  //如果为true，则有遮蔽层，
		init: function(){
			this.createDialog();
		},
		
		createDialog: function(){
			this.dialog = $("<div></div>")
							.addClass(this.dlgClassName)
							.css({width:this.width + "px", /*height:this.height + "px",*/ display:"none"})
							.appendTo("body");
			
			
			if(this.title == undefined){
				//this.othersH -= 24;
			}else{
				this.dialog.append(this.addTitle());
			}
			
			if(this.addContent){
				this.dlgContent = $("<div></div>").addClass("dlg_content")
									.css("height",this.height)
									.appendTo(this.dialog);
			}
			
			if(this.buttons != undefined){
				this.dialog.append(this.addButtons());
			}
			
			if(this.dialogShadow){
				this.dlgShadow = $("<div></div>")
									.addClass("dlg_shadow")
									.css({display:"none",zIndex:"3333",height:document.documentElement.scrollHeight +　"px"})
									.appendTo("body");
				this.dialog.css("zIndex","4444");
			}
			
			//this.show();
		},
		
		setHtml: function(html){
			this.dlgContent.html(html);
		},
		
		load : function(arguments){
			this.dlgContent.load(arguments);
	    },
		
		/**
		 * arguments{url data callback}
		 */
		wrapLoad: function(arguments){
	        this.dialog.load(arguments)
		},
		
		show: function(){
			var xy = this.showScrollAt();
			this.dialog.css({display:"",left:xy[0] + "px",top:xy[1] + "px"});
			if(this.dialogShadow){
				this.dlgShadow.css("display","");
			}


		},
		
		showScrollAt: function(){
			var D = document.documentElement;
			var l = (D.clientWidth - this.width)/2;
			var t =  (D.clientHeight - this.height)/2 + D.scrollTop;
			return [l,t];
		},
		
		addTitle: function(){
			this.title.cls = this.title.cls ? this.title.cls: "dlg_title";
			var dlgTitleWrap = $("<div></div>")
								.addClass("dlg_titleWrap")
								.append("<div class="+this.title.cls+">"+this.title.value+"</div>")
	
			if(this.closeIcon){
				var _this = this;
				$("<div></div>")
					.addClass("dlg_closeIcon")
					.appendTo(dlgTitleWrap)
					.click(function(){
						_this.close();
					});
			}
			return dlgTitleWrap;
		},
		
		addButtons: function(){
			var _this = this;
			var dlgBtns = $("<div></div>")
							.addClass("dlg_btnsWrap");
			$(this.buttons).each(function(){
				var btn = $("<a></a>")
							.html(this.value)
							.addClass("dlg_btns")
							.appendTo(dlgBtns);
				if(this.event){
					var event = this.event;
					btn.click(function(){
						_this.initEvent(event);
					})
				}
			});
			return dlgBtns;
		},
		
		initEvent: function(eventName){
			if(eventName == "close"){
				this.close();
			}
			jQuery.event.trigger(eventName);
		},
		
		close: function(){
			if(this.dialogShadow){
				this.dlgShadow.remove();
			}
			this.dialog.remove();
		}
	};
