_.Module.define({path:"common/component/image_water",requires:["common/component/image_water/water_flash","common/component/image_water/water_html5"],sub:{initial:function(a){this.options=$.extend({},a);this.EVENTS=["onProgressListen","onComplete","onError"];this._initUploadUrl();this._initFlash()},merge:function(a){if(!a){throw new Error("merge\u65b9\u6cd5\u5fc5\u987b\u6709\u53c2\u6570");return false}a.text.content=$.tb.subByte(a.text.content,40,"");$.extend(this.options,a);this._start()},_initUploadUrl:function(c){var a=this;if(this.options.uploadUrl){c&&c.apply(a);return}var b=$.ajax({url:"http://tieba.baidu.com/dc/common/imgtbs",dataType:"json"});b.done(function(d){if(Number(d.no)===0){a.options.uploadUrl="http://upload.tieba.baidu.com/upload/pic?tbs="+d.data.tbs;c&&c.apply(a)}else{c&&a._error()}}).fail(function(){c&&a._error()})},_start:function(){this._initUploadUrl(this._startImageWater)},_startImageWater:function(){var a=navigator.userAgent.toLowerCase().match(/chrome\/([\d]+)/);if(this._html5Visible()){this.imageWater=this.use("common/component/image_water/water_html5",this.options)}else{this.options.flashUrl=this.flashUrl;this.imageWater=this.use("common/component/image_water/water_flash",this.options)}this._generateCallBack();this.imageWater.merge()},_generateCallBack:function(){var b=this;for(var c=0;c<this.EVENTS.length;c++){var a=this.EVENTS[c];this.imageWater.bind(a,(function(d){return function(g,f){b.trigger(d,f||g)}})(a))}},_initFlash:function(){if(!this._html5Visible()){var a=$("<div>").appendTo(document.body).css({position:"absolute",width:"1px",height:"1px",overflow:"hidden",left:1,bottom:1});this.flashUrl="/tb/static-common/img/imagewater/imagewater.swf?v=1.0.6";var d="flashImageWater"+(+(new Date()));var b='<object id="'+d+'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+1+'" height="'+1+'"><param name="allowScriptAccess" value="always" /><param value="transparent" name="wmode"><param name="flashvars" value="'+this.flashVars+'" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+this.flashUrl+'" /></object>';var c='<object id="'+d+'" type="application/x-shockwave-flash" data="'+this.flashUrl+'" width="'+1+'" height="'+1+'"><param name="allowScriptAccess" value="always" /><param value="transparent" name="wmode"><param name="flashvars" value="'+this.flashVars+'" /></object>';if(navigator.appName.indexOf("Microsoft")!=-1){a.html(b)}else{a.html(c)}}},_html5Visible:function(){var a=navigator.userAgent.toLowerCase().match(/chrome\/([\d]+)/);if(((a&&parseInt(a[1])>=21)||$.browser.mozilla)&&!this.options.isFlash){return true}return false},_error:function(a){a=$.extend({percent:0,errorCode:400,errorMessage:"\u5408\u6210\u9519\u8bef",response:null},a||{});this.trigger("onError",a)}}});