//jQuery Translate plugin and related components


/*
 * jQuery nodesContainingText plugin
 * Version: 1.1.2
 * http://code.google.com/p/jquery-translate/
 * Copyright (c) 2009 Balazs Endresz (balazs.endresz@gmail.com)
 * Dual licensed under the MIT and GPL licenses.
 */
(function(b){function a(){}a.prototype={init:function(e,d){this.textArray=[];this.elements=[];this.options=d;this.jquery=e;this.n=-1;if(d.async===true){d.async=2}if(d.not){e=e.not(d.not);e=e.add(e.find("*").not(d.not)).not(b(d.not).find("*"))}else{e=e.add(e.find("*"))}this.jq=e;this.jql=this.jq.length;return this.process()},process:function(){this.n++;var i=this,d=this.options,p="",h=false,g=false,f=this.jq[this.n],k,m,j;if(this.n===this.jql){j=this.jquery.pushStack(this.elements,"nodesContainingText");d.complete.call(j,j,this.textArray);if(d.returnAll===false&&d.walk===false){return this.jquery}return j}if(!f){return this.process()}k=b(f);var n=f.nodeName.toUpperCase(),l=n==="INPUT"&&b.attr(f,"type").toLowerCase();if(({SCRIPT:1,NOSCRIPT:1,STYLE:1,OBJECT:1,IFRAME:1})[n]){return this.process()
}if(typeof d.subject==="string"){p=k.attr(d.subject)}else{if(d.altAndVal&&(n==="IMG"||l==="image")){p=k.attr("alt")}else{if(d.altAndVal&&({text:1,button:1,submit:1})[l]){p=k.val()}else{if(n==="TEXTAREA"){p=k.val()}else{m=f.firstChild;if(d.walk!==true){g=true}else{while(m){if(m.nodeType==1){g=true;break}m=m.nextSibling}}if(!g){p=k.text()}else{if(d.walk!==true){h=true}m=f.firstChild;while(m){if(m.nodeType==3&&m.nodeValue.match(/\S/)!==null){if(m.nodeValue.match(/<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)>/)!==null){if(m.nodeValue.match(/(\S+(?=.*<))|(>(?=.*\S+))/)!==null){h=true;break}}else{h=true;break}}m=m.nextSibling}if(h){p=k.html();p=d.stripScripts?p.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi,""):p;this.jq=this.jq.not(k.find("*"))}}}}}}if(!p){return this.process()}this.elements.push(f);this.textArray.push(p);d.each.call(f,this.elements.length-1,f,p);if(d.async){setTimeout(function(){i.process()},d.async);return this.jquery}else{return this.process()}}};var c={not:"",async:false,each:function(){},complete:function(){},comments:false,returnAll:true,walk:true,altAndVal:false,subject:true,stripScripts:true};
b.fn.nodesContainingText=function(d){d=b.extend({},c,b.fn.nodesContainingText.defaults,d);return new a().init(this,d)};b.fn.nodesContainingText.defaults=c})(jQuery);
/*
 * jQuery Translate plugin
 * Version: null
 * http://code.google.com/p/jquery-translate/
 * Copyright (c) 2009 Balazs Endresz (balazs.endresz@gmail.com)
 * Dual licensed under the MIT and GPL licenses.
 * This plugin uses the 'Google AJAX Language API' (http://code.google.com/apis/ajaxlanguage/)
 * You can read the terms of use at http://code.google.com/apis/ajaxlanguage/terms.html
 */
(function(d){function q(){}var e=true,h=false,f,w="".replace,y=String,l=Function,v=Object,o,m,g,r={},c,k=[],a,i={from:"",to:"",start:q,error:q,each:q,complete:q,onTimeout:q,timeout:0,stripComments:e,stripWhitespace:e,stripScripts:e,separators:/\.\?\!;:/,limit:1750,walk:e,returnAll:h,replace:e,rebind:e,data:e,setLangAttr:h,subject:e,not:"",altAndVal:e,async:h,toggle:h,fromOriginal:e,parallel:false,trim:true,alwaysReplace:false};function s(){d.translate.GL=o=google.language;d.translate.GLL=m=o.Languages;u()}function x(C,B){m={};for(var A=0;A<C.length;A++){m[B[A].toUpperCase()]=C[A]
}d.translate.GLL=m;u()}function u(){g=d.translate.toLanguageCode;d.each(m,function(B,C){r[C.toUpperCase()]=B});d.translate.isReady=e;var A;while((A=k.shift())){A()}}function j(C,B){var A={};d.each(C,function(D,E){if(B(E,D)===e){A[D]=E}});return A}function z(B,C,A){return function(){return B.apply(C===e?arguments[0]:C,A||arguments)}}function t(A){return A!==f}function p(B,E,D){var A,F={},C=d.grep(B,t);d.each(E,function(G,H){var I=d.grep(H[0],function(K,J){return t(C[J])&&C[J].constructor===K}).length;if(I===C.length&&I===H[0].length&&(A=e)){d.each(H[1],function(J,K){F[K]=C[J]});return h}});if(!A){throw D}return F}function n(D,C){var A=p(D,d.translate.overload,"jQuery.translate: Invalid arguments"),B=A.options||{};delete A.options;B=d.extend({},i,C,d.extend(B,A));if(B.fromOriginal){B.toggle=e}if(B.toggle){B.data=e}if(B.async===e){B.async=2}if(B.alwaysReplace===true){B.toggle=false;B.fromOriginal=false}return B}function b(){this.extend(d.translate);delete this.defaults;delete this.fn}b.prototype={version:"null",_init:function(C,F){var E=F.separators.source||F.separators,B=this.isString=typeof C==="string",A=0,D;
d.each(["stripComments","stripScripts","stripWhitespace"],function(H,G){var I=d.translate[G];if(F[G]){C=B?I(C):d.map(C,I)}});this.rawSource="<div>"+(B?C:C.join("</div><div>"))+"</div>";this._m3=new RegExp("["+E+"](?![^"+E+"]*["+E+"])");this.options=F;this.from=F.from=g(F.from)||"";this.to=F.to=g(F.to)||"";this.source=C;this.rawTranslation="";this.translation=[];this.i=0;this.stopped=h;this.elements=F.nodes;this._i=-1;this.rawSources=[];while(e){D=this.truncate(this.rawSource.substr(A),F.limit);if(!D){break}this.rawSources.push(D);A+=D.length}this.queue=new Array(this.rawSources.length);this.done=0;F.start.call(this,C,F.from,F.to,F);if(F.timeout){this.timeout=setTimeout(z(F.onTimeout,this,[C,F.from,F.to,F]),F.timeout)}(F.toggle&&F.nodes)?(F.textNodes?this._toggleTextNodes():this._toggle()):this._process()},_process:function(){if(this.stopped){return}var A=this.options,H=this.rawTranslation.length,L,M,J,I;var K=this;while((L=this.rawTranslation.lastIndexOf("</div>",H))>-1){H=L-1;M=this.rawTranslation.substr(0,H+1);
J=M.match(/<div[> ]/gi);I=M.match(/<\/div>/gi);J=J?J.length:0;I=I?I.length:0;if(J!==I+1){continue}var D=d(this.rawTranslation.substr(0,H+7)),F=D.length,E=this.i;if(E===F){break}D.slice(E,F).each(z(function(P,S){if(this.stopped){return h}var O=d(S).html(),R=A.trim?d.trim(O):O,Q=E+P,T=this.source,U=!this.from&&this.detectedSourceLanguage||this.from;this.translation[Q]=R;this.isString?this.translation=R:T=this.source[Q];A.each.call(this,Q,R,T,U,this.to,A);this.i++},this));break}if(this.rawSources.length-1==this._i){this._complete()}var C=z(this._translate,this);if(A.parallel){if(this._i<0){if(!A.parallel){d.each(this.rawSources,C)}else{var G=0,B=this.rawSources.length;function N(){C();if(G++<B){setTimeout(N,A.parallel)}}N()}}}else{C()}},_translate:function(){this._i++;var A=this._i,B=this.rawSourceSub=this.rawSources[A];if(!B){return}if(!a){o.translate(B,this.from,this.to,z(function(C){if(C.error){return this.options.error.call(this,C.error,this.rawSourceSub,this.from,this.to,this.options)
}this.queue[A]=C.translation||this.rawSourceSub;this.detectedSourceLanguage=C.detectedSourceLanguage;this._check()},this))}else{d.ajax({url:"http://api.microsofttranslator.com/V2/Ajax.svc/Translate",dataType:"jsonp",jsonp:"oncomplete",crossDomain:true,context:this,data:{appId:a,form:this.from,to:this.to,contentType:"text/html",text:B}}).success(function(D,C){this.queue[A]=D||this.rawSourceSub;this._check()})}},_check:function(){if(!this.options.parallel){this.rawTranslation+=this.queue[this._i];this._process();return}var A=0;jQuery.each(this.queue,function(C,D){if(D!=f){A=C}else{return false}});if((A>this.done)||(A===this.queue.length-1)){for(var B=0;B<=A;B++){this.rawTranslation+=this.queue[B]}this._process()}this.done=A},_complete:function(){clearTimeout(this.timeout);this.options.complete.call(this,this.translation,this.source,!this.from&&this.detectedSourceLanguage||this.from,this.to,this.options)},stop:function(){if(this.stopped){return this}this.stopped=e;this.options.error.call(this,{message:"stopped"});
return this}};d.translate=function(C,A){if(C==f){return new b()}if(d.isFunction(C)){return d.translate.ready(C,A)}var D=new b();var B=[].slice.call(arguments,0);B.shift();return d.translate.ready(z(D._init,D,[C,n(B,d.translate.defaults)]),h,D)};d.translate.fn=d.translate.prototype=b.prototype;d.translate.fn.extend=d.translate.extend=d.extend;d.translate.extend({_bind:z,_filter:j,_validate:p,_getOpt:n,_defaults:i,defaults:d.extend({},i),capitalize:function(A){return A.charAt(0).toUpperCase()+A.substr(1).toLowerCase()},truncate:function(G,B){var C,J,H,F,E,I,A=encodeURIComponent(G);for(C=0;C<10;C++){try{I=decodeURIComponent(A.substr(0,B-C))}catch(D){continue}if(I){break}}return(!(J=/<(?![^<]*>)/.exec(I)))?((!(H=/>\s*$/.exec(I)))?((F=this._m3.exec(I))?((E=/>(?![^>]*<)/.exec(I))?(F.index>E.index?I.substring(0,F.index+1):I.substring(0,E.index+1)):I.substring(0,F.index+1)):I):I):I.substring(0,J.index)},getLanguages:function(H,G){if(H==f||(G==f&&!H)){return m}var E={},D=typeof H,C=G?d.translate.getLanguages(H):m,I=(D==="object"||D==="function")?H:G;
if(I){if(I.call){E=j(C,I)}else{for(var F=0,B=I.length,A;F<B;F++){A=d.translate.toLanguage(I[F]);if(C[A]!=f){E[A]=C[A]}}}}else{E=j(m,o.isTranslatable)}return E},toLanguage:function(B,D){var C=B.toUpperCase();var A=r[C]||(m[C]?C:f)||r[(d.translate.languageCodeMap[B.toLowerCase()]||"").toUpperCase()];return A==f?f:D==="lowercase"?A.toLowerCase():D==="capitalize"?d.translate.capitalize(A):A},toLanguageCode:function(A){return m[A]||m[d.translate.toLanguage(A)]||d.translate.languageCodeMap[A.toLowerCase()]},same:function(B,A){return B===A||g(B)===g(A)},isTranslatable:function(A){return o?o.isTranslatable(g(A)):!!g(A)},languageCodeMap:{pt:"pt-PT","pt-br":"pt-PT",he:"iw",zlm:"ms","zh-hans":"zh-CN","zh-hant":"zh-TW"},isRtl:{ar:e,iw:e,fa:e,ur:e,yi:e},getBranding:function(){return d(o.getBranding.apply(o,arguments))},load:function(B,A){c=e;if(!B||(B.length<40)){function C(){google.load("language",A||"1",{callback:s})}if(typeof google!=="undefined"&&google.load){C()}else{d.getScript(((document.location.protocol=="https:")?"https://":"http://")+"www.google.com/jsapi"+(B?"?key="+B:""),C)
}}else{a=B;d.ajax({url:"http://api.microsofttranslator.com/V2/Ajax.svc/GetLanguagesForTranslate",dataType:"jsonp",jsonp:"oncomplete",crossDomain:true,context:this,data:{appId:a}}).success(function(E,D){d.ajax({url:"http://api.microsofttranslator.com/V2/Ajax.svc/GetLanguageNames",dataType:"jsonp",jsonp:"oncomplete",crossDomain:true,context:this,data:{appId:a,locale:"en",languageCodes:'["'+E.join('", "')+'"]'}}).success(function(G,F){x(E,G)})})}return d.translate},ready:function(A,C,B){d.translate.isReady?A():k.push(A);if(!c&&!C){d.translate.load()}return B||d.translate},isReady:h,overload:[[[],[]],[[y,y,v],["from","to","options"]],[[y,v],["to","options"]],[[v],["options"]],[[y,y],["from","to"]],[[y],["to"]],[[y,y,l],["from","to","complete"]],[[y,l],["to","complete"]]],stripScripts:z(w,e,[/<script[^>]*>([\s\S]*?)<\/script>/gi,""]),stripWhitespace:z(w,e,[/\s\s+/g," "]),stripComments:z(w,e,[/<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)>/g,""])})})(jQuery);

(function(g){var f=true,a={text:f,button:f,submit:f},b={SCRIPT:f,NOSCRIPT:f,STYLE:f,OBJECT:f,IFRAME:f},e=g([]);e.length=1;function d(i){while(i&&i.nodeType!=9){i=i.parentNode}return i}function c(j,i){var k=j.css("text-align");j.css("direction",i);if(k==="right"){j.css("text-align","left")}if(k==="left"){j.css("text-align","right")}}function h(j,k){var l=j.nodeName.toUpperCase(),i=l==="INPUT"&&g.attr(j,"type").toLowerCase();k=k||{altAndVal:f,subject:f};return typeof k.subject==="string"?k.subject:k.altAndVal&&(l==="IMG"||i==="image")?"alt":k.altAndVal&&a[i]?"$val":l==="TEXTAREA"?"$val":"$html"}g.translate.fn._toggle=function(){var j=this.options,k=j.to,i;this.elements.each(g.translate._bind(function(l,m){this.i=l;var o=g(m),n=g.translate.getData(o,k,j);if(!n){return !(i=f)}this.translation.push(n);j.each.call(this,l,m,n,this.source[l],this.from,k,j)
},this));!i?this._complete():this._process()};g.translate.extend({_getType:h,each:function(k,m,j,l,q,p,n){e[0]=m;g.translate.setData(e,p,j,q,l,n);g.translate.replace(e,j,p,n);g.translate.setLangAttr(e,p,n)},getData:function(k,m,l){var i=k[0]||k,j=g.data(i,"translation");return j&&j[m]&&j[m][h(i,l)]},setData:function(l,n,q,p,r,i){if(i&&!i.data){return}var j=l[0]||l,m=h(j,i),k=g.data(j,"translation");k=k||g.data(j,"translation",{});(k[p]=k[p]||{})[m]=r;(k[n]=k[n]||{})[m]=q},replace:function(m,u,s,k){if(k&&!k.replace){return}if(k&&typeof k.subject==="string"){return m.attr(k.subject,u)}var l=m[0]||m,q=l.nodeName.toUpperCase(),p=q==="INPUT"&&g.attr(l,"type").toLowerCase(),n=g.translate.isRtl,j=g.data(l,"lang");if(!k.alwaysReplace){if(j===s){return}}if(n[s]!==n[j||k&&k.from]){if(n[s]){c(m,"rtl")}else{if(m.css("direction")==="rtl"){c(m,"ltr")}}}if((!k||k.altAndVal)&&(q==="IMG"||p==="image")){m.attr("alt",u)}else{if(q==="TEXTAREA"||(!k||k.altAndVal)&&a[p]){m.val(u)}else{if(!k||k.rebind){this.doc=this.doc||d(l);
var i=m.find("*").not("script"),r=g(this.doc.createElement("div")).html(u);g.translate.copyEvents(i,r.find("*"));m.html(r.contents())}else{m.html(u)}}}g.data(l,"lang",s)},setLangAttr:function(i,k,j){if(!j||j.setLangAttr){i.attr((!j||j.setLangAttr===f)?"lang":j.setLangAttr,k)}},copyEvents:function(j,i){i.each(function(l,o){var p=j[l];if(!o||!p){return false}if(b[p.nodeName.toUpperCase()]){return f}var k=g.data(p,"events");if(!k){return f}for(var n in k){for(var m in k[n]){g.event.add(o,n,k[n][m],k[n][m].data)}}})}});g.fn.translate=function(j,i,m){var k=g.translate._getOpt(arguments,g.fn.translate.defaults),l=g.extend({},g.translate._defaults,g.fn.translate.defaults,k,{complete:function(o,n){g.translate(function(){var r=g.translate.toLanguageCode(k.from);if(k.fromOriginal){o.each(function(s,t){e[0]=t;var u=g.translate.getData(e,r,k);if(!u){return true}n[s]=u})}var q=k.each;function p(s){return function(){[].unshift.call(arguments,this.elements);s.apply(this,arguments)}}k.nodes=o;k.start=p(k.start);
k.onTimeout=p(k.onTimeout);k.complete=p(k.complete);k.each=function(t){var s=arguments;if(arguments.length!==7){[].splice.call(s,1,0,this.elements[t])}this.each.apply(this,s);q.apply(this,s)};g.translate(n,k)})},each:function(){}});if(this.nodesContainingText){return this.nodesContainingText(l)}k.nodes=this;g.translate(g.map(this,function(n){return g(n).html()||g(n).val()}),k);return this};g.fn.translate.defaults=g.extend({},g.translate._defaults)})(jQuery);
