(function(a){
  a.alerts={
	verticalOffset:-75,
	horizontalOffset:0,
	repositionOnResize:true,
	overlayOpacity:0.35,
	overlayColor:"#000",
	draggable:true,
	okButton:"&nbsp;\u786e\u5b9a&nbsp;",
	cancelButton:"&nbsp;\u53d6\u6d88&nbsp;",
	dialogClass:null,
    // Public methods
	alert:function(b,c,d){
		if(c==null){c="\u63d0\u793a"}
		a.alerts._show(c,b,null,"alert",function(e){if(d){d(e)}},null,null,null,null,null)
	},
	confirm:function(b,c,d){
		if(c==null){c="\u8bf7\u786e\u8ba4"}
		a.alerts._show(c,b,null,"confirm",function(e){if(d){d(e)}},null,null,null,null,null)
	},
	submit:function(c,url,d){
		if(c==null){c="\u63D0\u793A"}
		 var surl = url+"&format=json&jsoncallback=?";
	     var b="\u6B63\u5728\u5904\u7406\u4E2D\uFF0C\u8BF7\u7A0D\u5019...";
		 a.alerts._show(c,b,null,null,null,null,null,null,null,null);
         var status = 1;
		 //setTimeout(function(){
	     a.getJSON(surl, function(data){
	   	    var status = data.status;
            if (status == 1)
	     	{
				a.alerts._show(c,data.text,null,"clue",function(e){if(d){d(e)}},null,null,null,null,null);
	    	}
	    	else
	    	{
				a.alerts._show(c,"<img align='absmiddle' src='http://img.nubb.com/fantasy_nba09/images/wrong.gif' /> "+data.text,null,"clue",null,null,null,null,null,null);
            }
		 //},2000);
	     });
	},
    block:function(b){
	     var c="\u63D0\u793A";

         if(b==null) b="\u6B63\u5728\u5904\u7406\u4E2D\uFF0C\u8BF7\u7A0D\u5019";
       a.alerts._show(c,b+"....",null,null,null,null,null,null,null,null);
	},
    unblock:function(b,d){
        if(b==null){
          a.alerts._hide();
        }else{
          var c="\u63D0\u793A";
		  a.alerts._show(c,b,null,"clue",function(e){if(d){d(e)}},null,null,null,null,null);
        }
    },
    prompt:function(t,b,c,d,e){
		if(d==null){d="\u8bf7\u586b\u5199"}
		a.alerts._show(d,b,c,"prompt",function(f){if(e){e(f)}},null,null,null,null,t)
	},
	openBox:function(f,g,b,c,e,d,i){
		if(g==null){g="\u63d0\u793a"}
		a.alerts._show(g,f,null,"openBox",function(h){if(i){i(h)}},b,c,e,d,null)
	},
    boxConfirm:function(f,g,b,c,d,i){
	    if(g==null){g="\u63d0\u793a"}
		a.alerts._show(g,f,null,"boxConfirm",function(h){if(i){i(h)}},b,c,d,null,null)
	},  
    overAlert:function(c,b){
		a.alerts._overShow(c,b)
	},

	//private methods
	_overShow:function(d,c){
		if(c==null){c=3000}
		var b=c+600;
		a("body").append('<div id="over_container" style="display:none"><div id="over_message"></div></div>');
		a("#over_message").text(d).html(a("#over_message").text().replace(/\n/g,"<br />"));
		if(a.alerts.dialogClass){
			a("#over_container").addClass(a.alerts.dialogClass)
		}
		var e=(a.browser.msie&&parseInt(a.browser.version)<=6)?"absolute":"fixed";
		a("#over_container").css({position:e,zIndex:99999,width:350,padding:0,margin:0}).show("fast");
		a("#over_container").css({
			minWidth:a("#over_container").outerWidth(),
			maxWidth:a("#over_container").outerWidth()});
		a.alerts._overReposition();
		setTimeout(function(){a("#over_container").hide("fast")},c);
		setTimeout(function(){a("#over_container").remove()},b)
	},

	_overReposition:function(){
			var c=4;
			var b=((a(window).width()/2)-(a("#over_container").outerWidth()/2))+a.alerts.horizontalOffset;
			if(c<0){c=0}
			if(b<0){b=0}
			if(a.browser.msie&&parseInt(a.browser.version)<=6){c=c+a(window).scrollTop()}
			if(a.browser.msie&&parseInt(a.browser.version)<=6){b=b-175}
			a("#over_container").css({top:c+"px",left:b+"px"});
			a("#popup_overlay").height(a(document).height())
	},

	_show:function(j,b,k,g,m,l,c,f,n,t){
		a.alerts._hide();
		a.alerts._overlay("show");
		a("body").append('<div id="popup_container" style="display:none">'+
			             '<div id="popup_bd">'+
			             '<h1 id="popup_h1">'+
			             '<div id="popup_title"></div>'+
			             '<span id="popup_close"></span>'+
			             '</h1>'+
			             '<div id="popup_content">'+
			             '<div id="popup_message"></div></div></div>');
		if(a.alerts.dialogClass){a("#popup_container").addClass(a.alerts.dialogClass)}
		var i=(a.browser.msie&&parseInt(a.browser.version)<=6)?"absolute":"fixed";
		a("#popup_container").css({position:i,zIndex:99999,padding:0,margin:0}).fadeIn("fast");
		a("#popup_title").text(j);
		a("#popup_content").addClass(g);
		if(g!="openBox" && g!="boxConfirm"){
			a("#popup_message").text(b).html(a("#popup_message").text().replace(/\n/g,"<br />"))
		}
		a("#popup_container").css({});
		a.alerts._reposition();
		a.alerts._maintainPosition(true);
		switch(g){
			case"clue":
                a("#popup_message").after('<div id="popup_panel"><input type="button" id="popup_return" /></div>');
				a("#popup_return").click(function(){
					a.alerts._hide();
					if(m){ m(true);}
				});
				a("#popup_return").focus().keypress(function(h){
					if(h.keyCode==13||h.keyCode==27){a("#popup_return").trigger("click")}
				});
				break;

			case"alert":
				a("#popup_message").after('<div id="popup_panel"><input type="button" id="popup_ok" /></div>');
				a("#popup_ok").click(function(){
					a.alerts._hide();
					if(m){m(true)}
				});
				a("#popup_ok").focus().keypress(function(h){
					if(h.keyCode==13||h.keyCode==27){a("#popup_ok").trigger("click")}
				});
				break;

			case"confirm":
				a("#popup_message").after('<div id="popup_panel"><input type="button" id="popup_ok" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button"  id="popup_cancel" /></div>');
				a("#popup_ok").click(function(){
					a.alerts._hide();
					if(m){m(true)}
				});
				a("#popup_cancel").click(function(){
					a.alerts._hide();
					if(m){m(false)}
				});
				a("#popup_ok").focus();
				a("#popup_ok, #popup_cancel").keypress(function(h){
					if(h.keyCode==13){a("#popup_ok").trigger("click")}
					if(h.keyCode==27){a("#popup_cancel").trigger("click")}
				});
				break;

			case"prompt":
                if(t==null){t="text"};
                a("#popup_message").append('<br /><input type="'+t+'" size="30" id="popup_prompt" />').after('<div id="popup_panel"><input type="button" id="popup_ok" /> <input type="button" id="popup_cancel" /></div>');
				a("#popup_prompt").width(a("#popup_message").width()-10);
				a("#popup_ok").click(function(){
					var e=a("#popup_prompt").val();
					a.alerts._hide();
					if(m){m(e)}
				});
				a("#popup_cancel").click(function(){
					a.alerts._hide();
					if(m){m(null)}
				});
				a("#popup_prompt, #popup_ok, #popup_cancel").keypress(function(h){
					if(h.keyCode==13){a("#popup_ok").trigger("click")}
					if(h.keyCode==27){a("#popup_cancel").trigger("click")}
				});
				if(k){a("#popup_prompt").val(k)}
				a("#popup_prompt").focus().select();
				break;

			case"openBox":
				a("#popup_message").append(a(b).html());
				if(l){a("#popup_container").css({width:l+"px"})}
				if(c){a("#popup_container").css({height:c+"px"});
				a("#popup_message").css({height:(c-48)+"px"})}
				a.alerts._reposition();
				if(f){
					a(f).click(function(){
					  a.alerts._hide();
					  if(m){m(true)}
				    })
				}
				if(n){
					a(n).click(function(){
					  a.alerts._hide();
					  return false;
					  if(m){m(false)}
					})
				}
				break;

            case"boxConfirm":
				a("#popup_message").append(a(b).html());
                if(l){a("#popup_container").css({width:l+"px"})}
				if(c){
					a("#popup_container").css({height:c+"px"});
				    a("#popup_message").css({height:(c-48)+"px"})
				}
				a("#popup_message").after('<div id="popup_panel"><input type="button" id="popup_ok" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button"  id="popup_cancel" /></div>');
                a("#popup_ok").click(function(){
					if(f){f(true)}
                    a.alerts._hide();
					if(m){m(true)}
				});
				a("#popup_cancel").click(function(){
					if(f){f(false)}
                    a.alerts._hide();
					if(m){m(false)}
				});
				a("#popup_ok").focus();
				a("#popup_ok, #popup_cancel").keypress(function(h){
					if(h.keyCode==13){a("#popup_ok").trigger("click")}
					if(h.keyCode==27){a("#popup_cancel").trigger("click")}
				});
				a.alerts._reposition();
				break;
        }
		if(g!=null && g!="clue"){
		   a("#popup_close").click(function(){
		    	a.alerts._hide();
			    if(m){m(false)}
		   });
		}
		if(a.alerts.draggable){
			try{
				a("#popup_container").draggable({handle:a("#popup_title")});
				a("#popup_title").css({cursor:"move"})
			}catch(d){}
		}
	},

	_hide:function(){
			a("#popup_container").remove();
			a.alerts._overlay("hide");
			a.alerts._maintainPosition(false)
	},
	
	_overlay:function(b){
		switch(b){
			case"show":
				a.alerts._overlay("hide");
			    a("BODY").append('<div id="popup_overlay"></div>');
				a("#popup_overlay").css({
					position:"absolute",
					zIndex:99998,
					top:"0px",
					left:"0px",
					width:"100%",
					height:a(document).height(),
					background:a.alerts.overlayColor,
					opacity:a.alerts.overlayOpacity});
                    //盖住ie6的选择框
                    a("#popup_overlay").bgiframe();
                break;
			case"hide":
				a("#popup_overlay").remove();
			    break;
		}
	},
		
	_reposition:function(){
		var c=((a(window).height()/2)-(a("#popup_container").height()/2))+a.alerts.verticalOffset;
		var b=((a(window).width()/2)-(a("#popup_container").width()/2))+a.alerts.horizontalOffset;
		if(c<0){c=0}
		if(b<0){b=0}
		if(a.browser.msie&&parseInt(a.browser.version)<=6){c=c+a(window).scrollTop()}
		a("#popup_container").css({top:c+"px",left:b+"px"});
		a("#popup_overlay").height(a(document).height())
	},
	
	_maintainPosition:function(b){
		if(a.alerts.repositionOnResize){
			switch(b){
				case true:a(window).bind("resize",a.alerts._reposition);break;
				case false:a(window).unbind("resize",a.alerts._reposition);break
			}
		}
	}
}; //--a.alerts

a.fn.bgIframe = a.fn.bgiframe = function(s) {
	// This is only for IE6
	if ( a.browser.msie && /6.0/.test(navigator.userAgent) ) {
		s = a.extend({
			top     : 'auto', // auto == .currentStyle.borderTopWidth
			left    : 'auto', // auto == .currentStyle.borderLeftWidth
			width   : 'auto', // auto == offsetWidth
			height  : 'auto', // auto == offsetHeight
			opacity : true,
			src     : 'javascript:false;'
		}, s || {});
		var prop = function(n){return n&&n.constructor==Number?n+'px':n;},
		    html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
		               'style="display:block;position:absolute;z-index:-1;'+
			               (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
					       'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
					       'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
					       'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
					       'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
					'"/>';
		return this.each(function() {
			if ( a('> iframe.bgiframe', this).length == 0 )
				this.insertBefore( document.createElement(html), this.firstChild );
		});
	}
	return this;
};//bgIframe
    
nuAlert=function(c,b,d){a.alerts.alert(b,c,d)};
nuConfirm=function(c,b,d){a.alerts.confirm(b,c,d)};
nuPrompt=function(t,b,c,d,e){a.alerts.prompt(t,b,c,d,e)};
nuBox=function(f,g,b,c,e,d,i){a.alerts.openBox(f,g,b,c,e,d,i)};
nuBoxConfirm=function(f,g,b,c,d,i){a.alerts.boxConfirm(f,g,b,c,d,i)};
nuOverAlert=function(c,b){a.alerts.overAlert(c,b)};
nuSubmit=function(title, url,callback){a.alerts.submit(title,url,callback)};
nuBlockUI=function(message){a.alerts.block(message)};
nuUnblockUI=function(message,callback){a.alerts.unblock(message,callback)};
})(jQuery);
