(function(d){var g={read:function(j){var n=j+"=";var k=document.cookie.split(";");for(var m=0;m<k.length;m++){var l=k[m];while(l.charAt(0)==" "){l=l.substring(1,l.length)}if(l.indexOf(n)==0){return l.substring(n.length,l.length)}}return null},create:function(i,n,m){if(m){var j=new Date();j.setTime(j.getTime()+(m*24*60*60*1000));var k="; expires="+j.toGMTString()}else{var k=""}try{document.cookie=i+"="+n+k+"; path=/"}catch(l){}},erase:function(i){this.create(i,"",-1)}};var h={appID:null,listLanguage:"",languageListNode:null,languagesList:null,nolist:false,tolang:null,callback:null};var c={$this:null,cookieName:"bhcTranslator"};function e(i){return i.nodeName.toLowerCase()=="input"&&(i.type.toLowerCase()=="text"||i.typetoLowerCase()=="button")}function a(j){try{function k(n,q,r){var o={};o.appid=h.appID;o.to=j;o.from=h.listLanguage;o.text=n;o.contentType="text/html";d.ajax({url:"http://api.microsofttranslator.com/V2/Ajax.svc/Translate",data:o,dataType:"jsonp",jsonp:"oncomplete",complete:function(s,p){},success:function(p,s){if(e(q)){d(q).val(p)}else{d(q).html(p)}if(q===r&&h.callback){h.callback()}},error:function(p,s,t){}})}var i=null;var l=null;c.$this.each(function(o,n){if(!n){return}i=d(n).attr("src_text");if(!i){return}k(i,n,c.$this.length-1===o?n:null)})}catch(m){alert(m.messsage)}}function b(){function j(m){var n=null;function l(){var p=[];function r(t){setupLanguageNamesList=function(w){var A=document.createElement("select");A.id="_supportedLanguagesList";function C(){var E=d("#_supportedLanguagesList option");E.sort(function(F,G){return F.text.localeCompare(G.text)});d("#_supportedLanguagesList").empty().append(E)}var z=[];for(var u=0;u<w.length;u++){z.push({value:p[u],text:w[u]})}for(var u=0;u<w.length;u++){var x=d(document.createElement("option"));x.text(z[u].text);x.val(z[u].value);A.appendChild(x.get(0))}d(A).bind("change",function(){var E=d("#_supportedLanguagesList").val();g.create(c.cookieName,E,365);a(E)});A.style.cssText="margin:0; padding:0;";var D=document.createElement("div");D.id="_translateElements";D.appendChild(A);if(h.languageListNode){D.style.cssText="position:relative;overflow:hidden;z-index:3;";h.languageListNode.style.visibility="visible"}else{h.languageListNode=document.body;D.style.cssText="top:8px;right:12px;position:absolute"}var B=h.languageListNode;B.appendChild(D);C();var y=g.read(c.cookieName);var v=y?y:h.listLanguage;d(A).find("option[value="+v+"]").attr("selected","selected");if(y){a(y)}else{if(h.callback){h.callback()}}};var s={appid:h.appID,locale:h.listLanguage,languageCodes:t};d.ajax({url:"http://api.microsofttranslator.com/V2/Ajax.svc/GetLanguageNames",data:s,dataType:"jsonp",jsonp:"oncomplete",complete:function(v,u){},success:function(u,v){setupLanguageNamesList(u)}})}formatLanguageCodes=function(s){p=s;for(var t=0;t<s.length;t++){q+=(q.length?",":"")+'"'+s[t]+'"'}return r("["+q+"]")};var q="";if(h.languagesList){formatLanguageCodes(h.languagesList)}else{var o={appid:h.appID};d.ajax({url:"http://api.microsofttranslator.com/V2/Ajax.svc/GetLanguagesForTranslate",data:o,dataType:"jsonp",jsonp:"oncomplete",complete:function(t,s){},success:function(s,t){formatLanguageCodes(s)}})}}function k(){try{var o=false;c.$this.each(function(s,r){src_text=d(r).attr("src_text");if(!h.listLanguage&&src_text.length>20){var q={appid:h.appID,text:src_text};d.ajax({url:"http://api.microsofttranslator.com/V2/Ajax.svc/Detect",data:q,dataType:"jsonp",jsonp:"oncomplete",complete:function(u,t){},success:function(t,u){if(o){return false}h.listLanguage=t;o=true;return l()}})}})}catch(p){throw (p)}}k()}function i(){try{c.$this.each(function(m,l){src_text=e(l)?d(l).val():d(l).html();d(l).attr("src_text",src_text)})}catch(k){throw (k)}}i();if(h.tolang){a(h.tolang)}else{if(h.nolist){if(h.callback){h.callback()}}else{j()}}}var f={init:function(i){c.$this=this;if(i){d.extend(h,i)}b();return this},destroy:function(){return this.each(function(){d(window).unbind(".translator")})}};d.fn.translator=function(i){if(f[i]){return f[i].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof i==="object"||!i){return f.init.apply(this,arguments)}else{d.error("Method "+i+" does not exist on jQuery.translator")}}}})(jQuery);
