/*!
 * jQuery.dialog  0.87
 *
 * Copyright 2010, Hudong.com
 * Dual licensed under the MIT and GPL licenses.
 * author: panxuepeng
 * blog: http://dushii.blog.163.com
 * $Date: 2008-08-31 $
 * $Last: 2010-08-02 $
 */
(function(e){function q(){var a=e._dialog;if(a){a.scrollTop=e(document).scrollTop();a.scrollLeft=e(document).scrollLeft();a.windowHeight=e(window).height();a.windowWidth=e(window).width();a.bodyPosition=e(document).find("body").css("position");a.bodyWidth=e(document).find("body").width();a.bodyLeft=e(document).find("body").position().left;if(!a.bodyLeft&&a.windowWidth>a.bodyWidth)a.bodyLeft=(a.windowWidth-a.bodyWidth)/2}}function t(){var a=0,c=0;e._dialog.init();q();e(window).bind("resize",function(){c&&
clearTimeout(c);c=setTimeout(function(){q();var b=e._dialog,d;for(id in b.list)if(b.isShow(id)){d=b.options[id];b.show(id);d.overlay&&b.setOverlay(id)}},200);return false});e(window).bind("scroll",function(){var b=e._dialog;a&&clearTimeout(a);a=setTimeout(function(){b.scrollTop=e(document).scrollTop();for(id in b.options){var d=b.options[id],g=b.getPosition(d.id),f=b.list[id];f.stop();if(d.minScrollTop){d.minScrollTop>b.scrollTop?f.css({visibility:"hidden"}):f.show().css({left:g.left,top:g.top,visibility:"visible"});
return}e.IE6&&d.fixed&&b.isShow(id)&&f.show().animate({left:g.left,top:g.top},200)}},200);return false})}var s=navigator.userAgent;e.IE=e.browser.msie;e.Firefox=/Firefox/i.test(s);e.IE6=function(){if(/MSIE [7891]\d?/.test(s))return false;if(/MSIE [56]/.test(s))return true;return false}();e(document).ready(function(){t()});e._dialog={version:0.87,list:{},isOpen:[],isClose:[],options:{},parts:{},fn_clockScroll:[],skins:{},keys:{},config:{lastid:"",id:"default",offsetClick:{},zIndex:2010,effect_time_up:500,
effect_time_down:500,effect_time_fade:200,base:".",htmlImgLoading:"",imgLoading:"indicator.gif",imgClose:"close.jpg",imgTitleBg:"bg_box_hand.gif"},defaults:{id:"default",key:"",skin:"default",move:true,overlay:true,model:"default",zIndex:2010,title:"",content:"",type:"",url:"",callback:null,callbackTimeout:500,position:"middle",offsetX:0,offsetY:0,fixed:false,effects:"",autoClose:0,width:350,height:200,fixedWidth:0,minScrollTop:0,onOk:null,onCancel:null,onClose:null,textOk:"\u786e\u5b9a",textCancel:"\u53d6\u6d88",
closeImg:true,resetTime:100,styleDialog:{},styleTitle:{},styleContent:{},styleBtn:{},styleOk:{},styleCancel:{},styleOverlay:{opacity:0.3},valign:""},init:function(){this.config.htmlImgLoading='<img src="'+this.config.base+"/"+this.config.imgLoading+'"/>';var a="div.hudong_dialog {border:1px solid #8C8C8C;background-color:#FFFFFF;overflow:hidden;}\t\t\t\n div.hudong_dialog h2.title{margin:0;height:22px;background:url("+this.config.base+"/"+this.config.imgTitleBg+");\t\t\t\tborder-bottom:1px solid #E0E0E0;padding:3px 5px;font-weight:bold;font-size:14px;overflow:hidden;-moz-user-select:none;line-height:22px;}\t\t\t\n div.hudong_dialog .close{display:block;float:right;cursor:pointer;width:16px;height:16px;margin:0;\t\t\t\ttop:5px;right:5px;position:absolute;background:url("+
this.config.base+"/"+this.config.imgClose+");}\t\t\t\n div.hudong_dialog div.content{padding:5px;text-align:center;background-color:#FFFFFF;position:relative;}\t\t\t\n div.hudong_dialog div.button{text-align:center;height:25px;padding:4px 10px 2px;}\t\t\t\n div.hudong_dialog div.button input{text-align:center;margin-right:10px;}\t\t\t\n div.hudong_overlay{z-index:2001;cursor:default;background-color:#ffffff;\t\t\t\twidth:100%;height:100%;top:0px;left:0px;position:absolute;margin:0 auto;}";a+="div.bluebox h2.title{background:none;background-color:#009DF0;color:#FFFFFF;font-size:14px;}\t\t\t\n div.bluebox .close{top:5px;right:5px;}\t\t\t\n div.bluebox div.button{background-color:#E8E8E8;}";
a+="div.noborder {border:0;background-color:transparent;}\n div.noborder .close{top:10px;right:10px;}";e("style#hudong_dialog_style").size()==0&&e("head").append('<style id="hudong_dialog_style">'+a+"</style>")},open:function(a){function c(g,f){var h;for(var j in g){h=typeof f[j];if(h=="undefined")f[j]=g[j];else h=="object"&&c(g[j],f[j])}}var b=this;if(document.getElementsByTagName("body").length==0){e(document).ready(function(){b.open(a)});return false}if(typeof a!="object"){alert('arguments must be a object, like {id:"id", title:"title"}.');
return false}var d=b.config.id=a.id;if(typeof d!="string"&&typeof d!="number"){alert("the type of id must be string or number.");return false}c(b.defaults,a);if(typeof a.position=="object"||a.height>b.windowHeight)a.fixed=false;if(typeof a.fixed=="string")a.fixed=a.fixed.toLowerCase();a.effects=/up|down|fade/i.test(a.effects)?a.effects.toLowerCase():"";if(!a.type&&a.content)if(/^[\w\/:&?,=-]+\.(jpg|gif|png)$/i.test(a.content)){a.type="img";a.url=a.content}else if(/^[\w\/:&?,=-]+\.html?$/i.test(a.content)){a.type=
"url";a.url=a.content}b.options[d]=a;a.overlay&&b.setOverlay(d);if(a.model.indexOf("alone")>-1)for(i in b.list)i!=d&&b.options[i]&&b.options[i].model.indexOf("together")<0&&b.close(i);b.build(a);a.isLoad=1;return b},setContent:function(a,c){this.list[a]||alert("dialog "+a+" is not exist.");this.parts[a].content.html(c);return this},reset:function(a,c){var b=this;c=c||100;setTimeout(function(){b.resize(a);var d=b.list[a],g=b.getPosition(a),f=b.options[a];if(f.resetTime>0)d.animate({top:g.top,left:g.left},
f.resetTime);else f.resetTime==0&&d.css({top:g.top,left:g.left})},c)},setOptions:function(a){function c(l,k){typeof a[k]!="undefined"&&l.css(a[k])}var b=a.id,d="",g="",f=this,h=f.list[b];d=f.parts[b];if(a.type=="url"){g=a.url;if(f.config.url==g){f.show(b);return f}f.config.url=g;f.setContent(b,f.config.htmlImgLoading);e.get(g,function(l,k){if(!f.isClose[b])if(k=="success"){f.setContent(b,l);f.reset(b);e.IE&&f.reset(b,200);e.isFunction(a.callback)&&a.callback(h)}else f.setContent(b,"Loading failure!")})}else if(a.type==
"img"){g=a.url;if(f.config.url==g){f.show(b);return f}f.config.url=g;f.setContent(b,f.config.htmlImgLoading);d=f.getPosition(b);h.css({top:d.top,left:d.left,opacity:""});var j=new Image;j.onload=function(){if(!f.isClose[b]){f.setContent(b,'<img src="'+g+'" width="'+(j.width>950?950:j.width)+'" />');f.reset(b);e.IE&&f.reset(b,200);e.isFunction(a.callback)&&a.callback(h)}};j.onerror=function(){f.setContent(b,a.error)};j.src=g;f.parts[b].content.dblclick(function(){e.dialog.close(b)})}else if(a.type==
"iframe"){d="<iframe id='"+b+"_iframe' name='"+b+"_iframe' border='0' width='"+(a.width-20)+"' height='"+(a.height-50)+"' frameborder='no'  marginwidth='0' marginheight='0' scrolling='no' allowtransparency='yes'></iframe>";f.setContent(b,d);f.reset(b);e("#"+b+"_iframe").load(function(){e.isFunction(a.callback)&&setTimeout(function(){a.callback(h)},a.callbackTimeout)}).attr("src",a.url)}else if(a.type=="selector"){if(d=e(a.url||a.content).html()){f.setContent(b,d);f.reset(b)}e.isFunction(a.callback)&&
setTimeout(function(){a.callback(h)},a.callbackTimeout)}else{if(a.type!="customize")a.valign=="center"?f.setContent(b,'<table width="100%" height="'+(a.height-60)+'"><tr><td valign="center">'+a.content+"</td></tr></table>"):f.setContent(b,a.content);f.reset(b);!a.type&&e.isFunction(a.callback)&&setTimeout(function(){a.callback(h)},a.callbackTimeout)}d=f.parts[b];a.title?d.title.show():d.title.hide();a.move&&d.title.css("cursor","move");a.type!="customize"&&a.width&&h.width(a.width);a.closeImg?d.close.show().unbind("click").click(function(){var l=
e(this).parent().attr("id").replace("dialog_","");e.dialog.close(l)}):d.close.hide();if(e.isFunction(a.onOk)||e.isFunction(a.onCancel)){d.button.show();e.isFunction(a.onOk)?d.ok.show():d.ok.hide();e.isFunction(a.onCancel)?d.cancel.show():d.cancel.hide();e.isFunction(a.onOk)&&d.ok.unbind("click").click(function(){a.onOk(h)});e.isFunction(a.onCancel)&&d.cancel.unbind("click").click(function(){a.onCancel(h)})}else d.button.hide();c(d.content,"styleContent");c(d.title,"styleTitle");c(d.button,"styleBtn");
c(d.ok,"styleOk");c(d.cancel,"styleCancel");c(h,"styleDialog");f.show(b);return f},resize:function(a){var c=this.list[a],b=this.parts[a];a=this.options[a];if(a.type!="customize"){var d,g,f=0,h=b.content.children("div,img,table,iframe").eq(0),j=parseInt(b.content.css("paddingTop"))+parseInt(b.content.css("paddingBottom"))+5;d=parseInt(b.content.css("paddingLeft"))+parseInt(b.content.css("paddingRight"));c.css({height:""});e.IE6||b.content.css({height:""});if(a.onOk||a.onCancel)f+=b.button.outerHeight();
if(a.title)f+=b.title.outerHeight();d=h.size()?h.outerWidth()+d:b.content.outerWidth();g=b.content.outerHeight();a.height&&g<a.height-f-j&&b.content.height(a.height-f-j);if(a.width&&a.width>d||!h.css("width")){d=a.width;b.content.width(a.width-parseInt(b.title.css("paddingTop"))*2)}a.fixedWidth||c.css({width:d+"px"});g>this.windowHeight&&c.css("top",this.scrollTop)}},show:function(a){if(!a)a=this.config.id;var c=this.list[a],b=this.options[a],d,g=function(){c.css({opacity:""})};d=this.getPosition(a);
this.setPosition(a,d);if(b.minScrollTop)b.minScrollTop>this.scrollTop&&c.css({visibility:"hidden"});else{if(b.effects&&typeof b.isLoad=="undefined"){var f=d.top,h=c.height();c.stop();switch(b.effects){case "down":c.css({left:d.left,top:-1000,display:"block",opacity:0.1}).animate({top:f,opacity:1},this.config.effect_time_down,g);break;case "up":c.css({left:d.left,top:f+h,display:"block",opacity:0.1}).animate({top:f,opacity:1},this.config.effect_time_up,g);break;case "fade":c.css({left:d.left,top:d.top,
display:"block",opacity:0.1}).animate({opacity:1},this.config.effect_time_fade,g);break}}else if(b.effects){c=this.list[a];c.stop().css({display:"block"}).animate({top:d.top,left:d.left,opacity:1},200,g)}else c.css({display:"block",top:d.top,left:d.left,opacity:""});this.config.zIndex+=1;c.css({zIndex:this.config.zIndex})}this.isOpen[a]=1;this.isClose[a]=0;return this},autoClose:function(a){var c=this.options[a];c.clockAutoClose&&clearTimeout(c.clockAutoClose);c.clockAutoClose=setTimeout(function(){e.dialog.close(a)},
c.autoClose);return false},build:function(a){var c=this,b=a.id,d=c.list[b],g;g="dialog_"+b;var f=0;c.config.zIndex++;if(d){f=1;g=c.parts[b];g.title.html(a.title)}else{f=0;d=e("#"+g);var h=a.fixed&&!e.IE6?"fixed":"absolute";if(d.size()){d.css({position:h}).attr("customize","1");a.skin&&d.addClass(a.skin);a.type="customize"}else{h='<div class="hudong_dialog '+a.skin+'" id="'+g+'" style="position:'+h+';">';h+='<h2 class="title">'+a.title+"</h2>";h+='<div class="content"></div>';h+='<div class="button">';
h+='<input type="button" class="ok" name="ok" value="'+a.textOk+'"/>';h+='<input type="button" class="cancel" name="cancel" value="'+a.textCancel+'"/>';h+='</div><img class="close"></img></div>';e("body").append(h);d=e("#"+g)}c.list[b]=d;g=c.parts[b]={title:d.children("h2.title"),close:d.children("img.close"),content:d.children("div.content"),button:d.children("div.button"),ok:d.find("input.ok"),cancel:d.find("input.cancel")};if(!g.title)g.title=d.find("[name='dialog_title']");if(!g.close)g.close=
d.find("[name='dialog_close']")}d.css("zIndex",c.config.zIndex++);if(a.key&&c.keys[b]==a.key)if(c.isShow(b))e.dialog.close(b);else{c.show(b);e.isFunction(a.callback)&&setTimeout(function(){a.callback(d)},a.callbackTimeout)}else{c.setOptions(a);c.keys[b]=a.key?a.key:"";if(a.autoClose){a.autoClose=parseInt(a.autoClose);a.autoClose=isNaN(a.autoClose)?2E3:a.autoClose;c.autoClose(a.id);a.title&&d.unbind("mouseover").mouseover(function(){clearTimeout(a.clockAutoClose)}).unbind("mouseleave").mouseleave(function(){var j=
e(this).attr("id").replace("dialog_","");c.autoClose(j)})}if(!f){d.unbind("click").click(function(){var j,l;j=e(this).attr("id").replace("dialog_","");l=e.dialog.get(j);if(c.config.id!=j){c.config.lastid=c.config.id;c.config.id=j;c.config.zIndex+=1;l.css({opacity:"",zIndex:c.config.zIndex})}});if(g.title.length){a.move&&g.title.unbind("mousedown").mousedown(function(j){var l,k;l=e(this).parents(".hudong_dialog").attr("id").replace("dialog_","");k=e.dialog.get(l);c.config.zIndex+=1;k.css({zIndex:c.config.zIndex});
var m=k.offset();c.config.offsetClick={width:j.pageX-m.left,height:j.pageY-m.top,left:k.css("left"),top:k.css("top")};var o=function(n){c.move(n,l);return false},p=function(){return false};e(document).mousemove(o).bind("selectstart",p);e(document).one("mouseup",function(n){var r=c.config.offsetClick;r={left:r.left,top:r.top};if(n.clientY<0||n.clientX<2||n.clientX>e(document).width()||n.clientY>e(window).height())k.css(r);e(document).unbind("mousemove",o).unbind("selectstart",p);return false});return false});
a.title&&a.model.indexOf("mini")>-1&&g.title.unbind("dblclick").bind("dblclick",function(){var j=e(this).parents(".hudong_dialog").attr("id").replace("dialog_","");c.parts[j].content.toggle();return false});g.title.unbind("selectstart").bind("selectstart",function(){return false})}return this}}},close:function(a){function c(){d.stop().css({top:-1999,opacity:"",display:"none"});b.isOpen[a]=0;b.isClose[a]=1;b.hideOverlay()}a||(a=this.list.length-1);if(typeof this.list[a]!="undefined"){var b=this,d=
b.list[a],g=b.options[a],f=d.height(),h=b.getPosition(a);if(d&&b.isShow(a)){b.fn_clockScroll[g.id]&&e(window).unbind("scroll",b.fn_clockScroll[g.id]);g.clockAutoClose&&clearTimeout(g.clockAutoClose);d.unbind("mouseleave").stop();var j={duration:200,complete:c};switch(g.effects){case "down":d.animate({top:-1999,opacity:0.1},j);break;case "up":d.animate({top:h.top+f+100,opacity:0.1},j);break;case "fade":d.animate({opacity:0.1},j);break;default:c()}}else d&&c();if(d)if(g.effects||e.IE6)setTimeout(function(){c()},
500)}},isShow:function(a){if(this.isClose[a])return false;if(this.isOpen[a])return true},move:function(a,c){var b=this.list[c];c=this.options[c];var d=this.config.offsetClick,g=a.pageX-d.width;a=a.pageY-d.height;this.bodyLeft=this.bodyLeft||e("body").position().left;if(c.fixed)e.IE6||(a-=this.scrollTop);else g=parseInt(g-this.bodyLeft);b.css({left:g,top:a});return false},setPosition:function(a,c){var b=this.list[a],d=this.options[a];c=c||this.getPosition(a);if(typeof c=="object")/up|down/i.test(d.effects)||
b.css(c);a=b.find(":text").filter(":visible");a.length&&a.eq(0).focus()},getPosition:function(a){var c=0,b=0,d=this.list[a];a=this.options[a];var g=this.windowWidth,f=this.windowHeight,h=this.scrollTop,j=this.scrollLeft,l=d.outerHeight();d=d.outerWidth();a.position=a.position||"middle";switch(a.position){case "center":case "middle":case "c":case "m":c=(g-d)/2;b=(f-l)/2;break;case "rb":case "br":case "rightBottom":case "bottomRight":c=g-d-4;b=f-l-3;break;case "rt":case "tr":case "rightTop":case "topRight":c=
g-d-4;b=1;break;case "lt":case "tl":case "leftTop":case "topLeft":b=c=0;break;case "ct":case "tc":case "centerTop":case "topCenter":c=(g-d)/2;b=0;break;case "cb":case "bc":case "centerBottom":case "bottomCenter":c=(g-d)/2;b=f-l;break;case "lb":case "bl":case "leftBottom":case "bottomLeft":c=0;b=f-l-3;break;default:if(typeof a.position!="object")break;c=e(a.position);if(!e.IE&&c.find("img").length>0)c=c.find("img");var k=c.offset(),m=c.outerHeight();c=c.outerWidth();var o,p,n;o=k.left-j+c;p=g+j-k.left;
b=k.top-h+m;n=f+h-k.top;c=p>d&&o>d?p>o?k.left-3:k.left+c-d+3:p>d?k.left-3:o>d?k.left+c-d+3:j+(g-d)/2;b=n>l?m<50?k.top+m:k.top:b>l?m<50?k.top-l:k.top-l+m:h+(f-l)/2;b=b>h?b:h;b=f+h>k.top+m?b:f+h-l}if(typeof a.position!="object"&&(!a.fixed||e.IE6)){c+=j;b+=h}this.bodyLeft||q();if(!a.fixed&&this.bodyPosition=="relative")c-=this.bodyLeft;else if(a.fixed&&e.IE6)c-=this.bodyLeft;c+=a.offsetX;b+=a.offsetY;b=b>0?b:0;c=c>0?c:0;return{left:c,top:b}},hideOverlay:function(){for(id in this.options)if(this.options[id].overlay&&
this.isShow(id))return false;e("div.hudong_overlay").hide()},setOverlay:function(a){var c="hudong_overlay"+a,b=e(document).height(),d="100%",g=0;a=this.options[a];var f=e("div#"+c);if(f.length>0)f.show();else{e("body").append('<div class="hudong_overlay" id="'+c+'"></div>');f=e("div#"+c)}this.bodyLeft||q();if(this.bodyPosition=="relative"){d=this.windowWidth;g=-this.bodyLeft}a.styleOverlay&&f.css(a.styleOverlay);f.css({left:g,width:d,height:b,zIndex:this.config.zIndex});return this}};e.dialog=function(a){e._dialog.open(a)};
e.extend(e.dialog,{box:function(a,c,b,d,g){this.open(a,c,b,d,g,{valign:"center",styleOverlay:{backgroundColor:"#FFFFFF"}})},get:function(a){var c=e._dialog.list[a];if(c)return c;else alert("\u63d0\u793a\uff1aid\u4e3a"+a+"\u7684dialog\u4e0d\u5b58\u5728\u3002")},options:function(a){return e._dialog.options[a]},open:function(a,c,b,d,g,f){a={id:a,title:c,position:d,callback:g,width:350,height:200};if(f&&typeof f=="object")for(var h in f)a[h]=f[h];if(b.substr(0,4)=="url:"){a.type="url";a.url=b.substr(4)}else if(b.substr(0,
4)=="img:"){a.type="img";a.url=b.substr(4)}else if(b.substr(0,7)=="iframe:"){a.type="iframe";a.url=b.substr(7)}else if(b.substr(0,9)=="selector:"){a.type="selector";a.content=b.substr(9)}else a.content=b;e._dialog.open(a)},tip:function(a,c,b,d,g){c=c||"\u63d0\u793a";b=b||3E4;d=d||"default";e._dialog.open({id:"jquery_dialog_tip",title:c,position:"c",skin:d,content:a,valign:"center",width:320,height:200,autoClose:b,onOk:g,styleContent:{verticalAlign:"center"},styleBtn:{},offsetY:-80})},alert:function(a,
c,b,d){this.tip(a,c,b,d,function(){e._dialog.close(id)})},addSkin:function(a){a=a.replace(/{base}/i,e._dialog.config.base);e("head").append("<style>"+a+"</style>")},close:function(a){var c=e._dialog.options[a];if(typeof c=="undefined")alert("\u63d0\u793a\uff1aid="+a+" \u7684dialog\u4e0d\u5b58\u5728\uff01");else{e.isFunction(c.onClose)&&c.onClose();e._dialog.close(a)}},resize:function(a){e._dialog.resize(a)},show:function(a){e._dialog.show(a)},ok:function(a){e._dialog.close(a)},exist:function(a){return e._dialog.list[a]},
setConfig:function(a,c,b){if(!a)return this;b=b||"config";if(typeof a=="string"&&c!==null)e._dialog[b][a]=c;else typeof a=="object"&&e.extend(e._dialog[b],a);return this},content:function(a,c){if(c){e._dialog.setContent(a,c);e._dialog.resize(a)}else return(a=this.get(a))?a.find("div.content").html():""},remove:function(a){this.get(a).remove();e._dialog.list[a]=null;e._dialog.options[a]=null},setDefaults:function(a,c){return this.setConfig(a,c,"defaults")}});/^http:\/\/(\w+\.){1,2}hudong\.com/i.test(location.href)&&
e.dialog.setConfig("base","http://www.huimg.cn/lib/dialog")})(jQuery);

