/*
 * jQuery Translate plugin 
 *
 * Version: 1.0.6
 *  
 * http://code.google.com/p/jquery-translate/
 *  
 * Copyright (c) 2008 Balázs Endrész (balazs.endresz@gmail.com)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) 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
 * 
 * The copyEvents plugin is needed for rebinding some element's event handlers:
 * http://plugins.jquery.com/project/copyEvents
 * 
 */
;(function($){function translate(t,from,to,callback,opt,p){p?'':p={};p.start?'':p.start=0;p.l?'':p.l=t.length;p.tf?'':p.tf='';p.end=p.start*1+opt.limit;p.ts=t.substring(p.start,p.end);var tt='';typeof p.divs=='undefined'?p.divs=0:'';var mymatch0=/<(?![^<]*>)/.exec(p.ts);if(mymatch0){var mymatch1=/<(?![^<]*>)/.exec(p.ts);if(mymatch1){var lastdot=mymatch1.index;tt=p.ts.substring(0,lastdot);}else{tt=p.ts}}else{var mymatch2=/>\s*$/.exec(p.ts);if(!mymatch2){var mymatch3=/[\.\?\!;:](?![^\.\?\!;:]*[\.\?\!;:])/.exec(p.ts);if(mymatch3){var lastdot=mymatch3.index+1;tt=p.ts.substring(0,lastdot);}else{tt=p.ts;}}else{tt=p.ts;}}
p.start=p.start+tt.length;var i=p.tf.length;while(p.tf.lastIndexOf('</div>',i)>-1){i=p.tf.lastIndexOf('</div>',i)-1;var subst=p.tf.substr(0,i);if(subst.match(/<div(>|( style=";))/gi)){var divst=subst.match(/<div(>|( style=";))/gi).length;}
if(subst.match(/<\/div>/gi)){var divcl=subst.match(/<\/div>/gi).length;}
if(typeof divst=='undefined'){divst=0;}
if(typeof divcl=='undefined'){divcl=0;}
if(divst==divcl+1){var divscompl=$(p.tf.substr(0,(i+7)));var divlen=divscompl.length;if(p.divs!=divlen){var each=divscompl.slice(p.divs,divlen);each.each(function(i){var k=p.divs+i;if(typeof p.finalarr=='undefined'){p.finalarr=[];}
var txteach=$.trim($(this).html());p.finalarr[k]=txteach;if(from.length<2&&p.detlang){from=p.detlang;}
if(p.fn===true){p.string?p.txtorig=[p.txtorig]:'';opt.each(k,txteach,p.txtorig[k],from,to,opt,p.num)}else{callback(k,p.jqt[k],txteach,p.txtorig[k],from,to,opt,p.num);}})
p.divs=divlen;}
break;}}
if(tt.length>0){google.language.translate(tt,from,to,function(result){if(result.error){return opt.error(result.error)}
p.tf=p.tf+result.translation;p.detlang=result.detectedSourceLanguage;var mm=/[\.\?\!;:]$/.exec(p.tf);if(mm){p.tf=p.tf+' '}
return translate(t,from,to,callback,opt,p);});p.num?p.num=p.num*1+1:p.num=1;}else{if(!p.tf){return;}
p.tf=p.tf.replace(/\s*$/,'')
if(from.length<2&&p.detlang){from=p.detlang;}
p.timeout?clearTimeout(p.timeout):'';if(p.fn===true){if(p.string){p.finalarr=p.finalarr[0];p.txtorig=p.txtorig[0];}
opt.complete(p.finalarr,p.txtorig,from,to,opt,p.num);}else{opt.complete(p.jq,$(p.jqt),p.finalarr,p.txtorig,from,to,opt,p.num)}}}
$.fn.translate=function(){var from;var to;var opt={};var a=arguments[0];var b=arguments[1];var c=arguments[2];if(typeof a=='undefined'||a.constructor==Object){return $.translate.w("Destination language is not set");}
if(!b&&!c){from='';to=a;}
if(!c&&b){if(b.constructor==Object){from='';to=a;opt=b;}else{from=a;to=b;}}
if(a.constructor==String&&b&&c){from=a;to=b;opt=c;}
var options={walk:true,returnAll:false,replace:true,translate:true,limit:500,rebind:true,data:false,setLangAttr:false,subject:true,not:'',comments:false,altAndVal:true,start:function(){},error:function(){},each:function(){},complete:function(){},onTimeout:function(){},timeout:0}
opt=$.extend(options,$.fn.translate.defaults,opt)
if(opt.rebind===true&&opt.replace===true){if(!$.isFunction($.event.copy)){$.translate.w("You have to include the copyEvents plugin to enable rebinding events on all elements: http://plugins.jquery.com/project/copyEvents");opt.rebind=false;}}
opt.start(this);var p={};p.txtorig=[];opt.timeout>0?p.timeout=setTimeout(function(){opt.onTimeout();},opt.timeout):'';var jq=this;var jqt=[];var tc='';if(opt.walk===true){jq=jq.add($(jq).find('*').not('script, '+opt.not))
if(opt.not.length){var omit=$(opt.not).get(0);var hasChildNode=false;omit?omit=omit.firstChild:omit=null;while(omit){if(omit.nodeType==1){hasChildNode=true;break;}
omit=omit.nextSibling;}
if(hasChildNode){jq=jq.not($(opt.not).find('*'))}}}
var jql=jq.length
for(var n=0;n<jql;n++){var trtext='';var hasTextNode=false;var hasChildNode=false;var el=jq[n];if(!el){continue;}
var e=$(el);if(opt.subject.constructor==String){trtext=e.attr(opt.subject)||'';}else{if(opt.altAndVal&&(el.tagName.toLowerCase()=='img'||el.tagName.toLowerCase()=='input')){if(el.tagName.toLowerCase()=='img'){trtext=e.attr('alt')||'';}else{var type=e.attr('type')||'';type=type.toLowerCase();if(type=='text'||type=='button'||type=='submit'){trtext=e.val()||'';}}}else{var cont=el.firstChild;opt.walk===true?'':hasChildNode=true;while(cont){if(cont.nodeType==1){hasChildNode=true;break;}
cont=cont.nextSibling;}
if(!hasChildNode){trtext=e.text();}else{opt.walk===true?'':hasTextNode=true;cont=el.firstChild;while(cont){if(cont.nodeType==3&&cont.nodeValue.match(/\S/)!==null){if(cont.nodeValue.match(/<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)>/)!==null){if(cont.nodeValue.match(/(\S+(?=.*<))|(>(?=.*\S+))/)!==null){hasTextNode=true;break;}}else{hasTextNode=true;break;}}
cont=cont.nextSibling;}
if(hasTextNode){trtext=e.html();jq=jq.not(e.find('*'));}else{trtext='';}}}}
if(!trtext){continue;}
jqt.push(el);tc=tc+'<div>'+trtext+'</div>';p.txtorig.push(trtext)}
if(!jqt){return this;}
opt.comments===false?tc.replace(/<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)>/g,''):'';p.jqt=jqt;p.jq=this
if(opt.translate!==false){translate(tc,from,to,function(i,el,tff,orig,from,to,opt,num){e=$(el)
if(opt.data===true){if(opt.subject.constructor==String){$.data(el,'translation.'+from+'.'+opt.subject,orig)
$.data(el,'translation.'+to+'.'+opt.subject,tff)}else{if(opt.altAndVal&&(el.tagName.toLowerCase()=='img'||el.tagName.toLowerCase()=='input')){if(el.tagName.toLowerCase()=='img'){$.data(el,'translation.'+from+'.'+'alt',orig)
$.data(el,'translation.'+to+'.'+'alt',tff)}else{var type=e.attr('type')||'';type=type.toLowerCase();if(type=='text'||type=='button'||type=='submit'){$.data(el,'translation.'+from+'.'+'value',orig)
$.data(el,'translation.'+to+'.'+'value',tff)}}}else{$.data(el,'translation.'+from+'.'+'html',orig)
$.data(el,'translation.'+to+'.'+'html',tff)}}}
opt.setLangAttr===true?e.attr('lang',to):'';opt.setLangAttr.constructor==String?e.attr(opt.setLangAttr,to):'';if(opt.replace===true){if(opt.subject.constructor==String){e.attr(opt.subject,tff)}else{from=='ar'?e.css('direction','ltr'):'';to=='ar'?e.css('direction','rtl'):'';if(e.css('text-align')==('right'||'left')){from=='ar'?e.css('text-align','right'):'';to=='ar'?e.css('text-align','right'):'';}
if(opt.altAndVal&&(el.tagName.toLowerCase()=='img'||el.tagName.toLowerCase()=='input')){if(el.tagName.toLowerCase()=='img'){e.attr('alt',tff)}else{var type=e.attr('type')||'';type=type.toLowerCase();if(type=='text'||type=='button'||type=='submit'){e.val(tff);}}}else{if(opt.rebind===true){var k=e.find('*').not('script').clone(true);var kl=k.length;e.html(tff);var h=e.find('*').not('script');for(var m=0;m<kl;m++){h.eq(m).copyEvents(k.get(m))}}else{e.html(tff);}}}}
opt.each(i,el,tff,orig,from,to,opt,num);},opt,p)}
if(opt.returnAll===true){return $(jqt);}else{return this;}}
$.translate=function(){var t=arguments[0];var from;var to;var opt={};var a=arguments[1];var b=arguments[2];var c=arguments[3];if(typeof a=='undefined'||a.constructor==Object){return $.translate.w("Destination language is not set");}
if(!b&&!c){from='';to=a;}
if(!c&&b){if(b.constructor==Object){from='';to=a;opt=b;}else{from=a;to=b;}}
if(a.constructor==String&&b&&c){from=a;to=b;opt=c;}
var options={limit:500,start:function(){},error:function(){},each:function(){},complete:function(){},onTimeout:function(){},timeout:0}
opt=$.extend(options,$.translate.defaults,opt)
var p={};opt.timeout>0?p.timeout=setTimeout(function(){opt.onTimeout();},opt.timeout):'';p.fn=true;p.txtorig=t;opt.start();if(t.constructor==String){t='<div>'+t+'</div>';p.string=true;}else{t='<div>'+t.join('</div><div>')+'</div>';p.string=false;}
translate(t,from,to,null,opt,p);}
function detect(t,opt,k,len,arr_langCode,arr_lang,arr_result){if(k===0){var arr_langCode=[];var arr_lang=[];var arr_result=[];}
var dttext=t[k].substring(0,opt.limit*1)
google.language.detect(dttext,function(result){if(!result.error){var language='unknown';for(l in google.language.Languages){if(google.language.Languages[l]==result.language){language=l;break;}}
opt.each(k,result.language,language,result)
arr_langCode.push(result.language);arr_lang.push(language);arr_result.push(result);if(k==len-1){return opt.complete(arr_langCode,arr_lang,arr_result);}else{k++;return detect(t,opt,k,len,arr_langCode,arr_lang,arr_result);}}else{return opt.error(result.error);}});}
$.language=function(t,opt){var options={start:function(){},each:function(){},complete:function(){},error:function(){},limit:500}
opt=$.extend(options,$.language.defaults,opt)
if(t.constructor==String){t=[t];}
opt.start();detect(t,opt,0,t.length);}
$.fn.language=function(opt){var options={start:function(){},each:function(){},complete:function(){},error:function(){},setLangAttr:true,subject:true,limit:500}
opt=$.extend(options,$.fn.language.defaults,opt)
opt.start(this);var len=this.length;var subject;var arr_e=[];var arr_langCode=[];var arr_lang=[];var arr_result=[];if(!opt.subject){return;}
opt.subject===true?subject=$(this).text():'';opt.subject.constructor==String?subject=$(this).attr(opt.subject):'';return this.each(function(i,e){var dttext=subject.substring(0,opt.limit*1)
google.language.detect(dttext,function(result){if(!result.error){var language='unknown';for(l in google.language.Languages){if(google.language.Languages[l]==result.language){language=l;break;}}
opt.setLangAttr===true?$(e).attr('lang',result.language):'';opt.setLangAttr.constructor==String?$(e).attr(opt.setLangAttr,result.language):'';opt.each(i,e,result.language,language,result)
arr_e.push(e);arr_langCode.push(result.language);arr_lang.push(language);arr_result.push(result);if(i==len-1){opt.complete(arr_e,arr_langCode,arr_lang,arr_result)}}else{opt.error(result.error);}});})}
$.translate.langLoaded=function(){}
$.translate.loadLang=function(){google.load("language","1",{"callback":$.translate.langLoaded});}
$.translate.initLoader=function(key){if(typeof google!='undefined'&&google.language.translate){return}
key?key='key='+key:key='';var script=document.createElement("script");script.src="http://www.google.com/jsapi?"+key+"&callback=$.translate.loadLang";script.type="text/javascript";document.getElementsByTagName("head")[0].appendChild(script);}
$.translate.w=function(m){if(typeof console!='undefined'){console.warn(m)}}
$.translate.initLoader()})(jQuery);