/*
 * DTWM
 */
(function(a){function v(b,e){if(a.trim(e).length!==0){var c=function(){var d=a(this).attr("id").substr(a(this).attr("id").lastIndexOf("_")+1),f=a("#"+h+"img_"+d);a("#"+h+d).attr("data-source",1);f.removeClass("tr-icon-yellow").removeClass("tr-icon-green").addClass("tr-icon-yellow")};a("*[data-token='"+b+"'][data-hidden!='y']").html(e).each(c);a("*[data-token='"+b+"'][data-hidden='y']").attr("data-trans",e).each(c)}}function w(b,e){clearTimeout(p);i.push(b);n.push(e);v(b,e);p=setTimeout(function(){var c=
{ln0:t_jp.lang,sr0:o,translation_posted:"2",items:i.length},d;for(d=0;d<i.length;d+=1){c["tk"+d]=i[d];c["tr"+d]=n[d];q+=a("*[data-token='"+i[d]+"']").size()}a.ajax({type:"POST",url:t_jp.post_url,data:c,success:function(){var f=q/k*100;t_jp.progress&&a("#"+l).progressbar("value",f)}});n=[];i=[]},200)}function j(b,e){w(b,a("<div>"+a.trim(e)+"</div>").text());var c=(k-a("."+h+'[data-source=""]').size())/k*100;t_jp.progress&&a("#"+m).progressbar("value",c)}function x(b,e,c){var d="",f="";a(b).each(function(g){d+=
"&q="+encodeURIComponent(b[g])});if(e)f=t_jp.olang;a.ajax({url:"http://ajax.googleapis.com/ajax/services/language/translate?v=1.0"+d+"&langpair="+f+"%7C"+t_jp.lang,dataType:"jsonp",success:c})}function r(b,e,c){x(e,c,function(d){if(d.responseStatus>=200&&d.responseStatus<300)d.responseData.translatedText!==undefined?j(b[0],d.responseData.translatedText):a(d.responseData).each(function(f){this.responseStatus===200&&j(b[f],this.responseData.translatedText)});else d.responseStatus>=400&&!c&&r(b,e,true)})}
function y(b,e){var c="[";a(b).each(function(d){c+='"'+encodeURIComponent(b[d])+'",'});c=c.slice(0,-1)+"]";a.ajax({url:"http://api.microsofttranslator.com/V2/Ajax.svc/TranslateArray?appId="+t_jp.MSN_APPID+"&to="+t_jp.binglang+"&texts="+c,dataType:"jsonp",jsonp:"oncomplete",success:e})}function z(b,e){o=2;y(e,function(c){a(c).each(function(d){j(b[d],this.TranslatedText)})})}function A(b,e){a.getJSON(t_jp.post_url+"?tgp="+e+"&tgl="+t_jp.lang,function(c){c.sentences!==undefined&&c.sentences[0].trans&&
j(b,c.sentences[0].trans)})}function B(b,e){var c="";a(b).each(function(d){c+="&q="+encodeURIComponent(b[d])});a.ajax({url:"http://api.apertium.org/json/translate?"+c+"&langpair="+t_jp.olang+"%7C"+t_jp.lang+"&markUnknown=no",dataType:"jsonp",success:e})}function C(b,e){o=3;B(e,function(c){if(c.responseStatus>=200&&c.responseStatus<300)c.responseData.translatedText!==undefined?j(b[0],c.responseData.translatedText):a(c.responseData).each(function(d){this.responseStatus===200&&j(b[d],this.responseData.translatedText)})})}
function s(b,e){if(t_jp.msn&&t_jp.preferred==="2")z(b,e);else if(t_jp.apertium&&(t_jp.olang==="en"||t_jp.olang==="es"))C(b,e);else if(t_jp.tgp)e[0]&&A(b[0],e[0]);else r(b,e,false)}function t(){var b=[],e=0,c=[],d=[];if(t_jp.tgp)u=0;a("."+h+'[data-source=""]').each(function(){var f=a(this).attr("data-token"),g=a(this).attr("data-orig");if(g===undefined)g=a(this).html();if(b[g]!==1){b[g]=1;if(e+g.length>u){s(d,c);e=0;c=[];d=[]}e+=g.length;d.push(f);c.push(g)}});s(d,c)}var u=128,k,h=t_jp.prefix,m=h+
"pbar",l=m+"_s",o=1,q=0,p,i=[],n=[];t_jp.MSN_APPID="FACA8E2DF8DCCECE0DC311C6E57DA98EFEFA9BC6";t_jp.jQueryUI="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/";a(document).ready(function(){if(t_jp.msn){t_jp.binglang=t_jp.lang;if(t_jp.binglang==="zh")t_jp.binglang="zh-chs";else if(t_jp.binglang==="zh-tw")t_jp.binglang="zh-cht"}a("#"+h+"setdeflang").click(function(){a.get(t_jp.post_url+"?tr_cookie="+Math.random());a(this).hide("slow");return false});k=a("."+h+'[data-source=""]').size();a.ajaxSetup({cache:true});
if(k&&!t_jp.noauto&&(t_jp.google||t_jp.msn||t_jp.apertium||t_jp.tgp))if(t_jp.progress){var b=function(){a.xLazyLoader({js:t_jp.jQueryUI+"jquery-ui.min.js",css:t_jp.jQueryUI+"themes/"+t_jp.theme+"/jquery-ui.css",success:function(){a("#"+h+"credit").css({overflow:"auto"}).append('<div style="float: left;width: 90%;height: 10px" id="'+m+'"/><div style="margin-bottom:10px;float:left;width: 90%;height: 10px" id="'+l+'"/>');a("#"+m).progressbar({value:0});a("#"+l).progressbar({value:0});a("#"+l+" > div").css({background:"#28F828",
border:"#08A908 1px solid"});t()}})};typeof a.xLazyLoader==="function"?b():a.getScript(t_jp.plugin_url+"/js/lazy.js",b)}else t();t_jp.edit&&a.getScript(t_jp.plugin_url+"/js/transposhedit.js")})})(jQuery);

