var PRE="/";var CONFIG={ajax:{getContextDict:PRE+"contextdict/show",addContextDictsWord:PRE+"contextdict/addword",changeContextWordTran:PRE+"contextdict/settranslate",delContextDictWord:PRE+"contextdict/delword",getContentStartPage:PRE+"content/getstartpage",getContentPage:PRE+"content/getpage",editContentText:PRE+"content/edittext",setContentRating:PRE+"content/rate",getWordsByTime:PRE+"userdict/list",getWordsAlphabetical:PRE+"userdict/list",getWordArticle:PRE+"userdict/show",editWordArticle:PRE+"userdict/edit",setContentBookmark:PRE+"content/setbookmark",setPageLearned:PRE+"content/setpagelearned",getAllThemes:PRE+"content/getallthemes",addNewContentTheme:PRE+"content/addtheme",delContentTheme:PRE+"content/deltheme",addContentComment:PRE+"content/addcomment",delContentComment:PRE+"content/delcomment",getContentComments:PRE+"content/getcomments",getWordTranslation:PRE+"contextdict/gettranslates",delTranslate:PRE+"contextdict/deltranslate",getTrainingData:PRE+"training/gettraining{ind}",setTrainingWin:PRE+"training/wintraining",setTrainingLoose:PRE+"training/losetraining",getWordsStats:PRE+"training/getwordsstat",getSearchResults:PRE+"search/results",setWordState:PRE+"userdict/changewordsstate",deleteWordState:PRE+"userdict/delwords",addWordToDict:PRE+"userdict/addword",getHint:PRE+"hint",hideHint:PRE+"hint/hide",showHint:PRE+"hint/show",setGrammarRuleState:PRE+"grammar/setrulelearned",getDialog:PRE+"dialog/getdialog",auth:PRE+"profile/auth",resendActivation:PRE+"profile/resendactivation",checkPaymentItem:PRE+"meatballs/paymentcheck",requestPaymentItem:PRE+"meatballs/paymentrequest",getMeatballsLog:PRE+"meatballs/log",sendInvitationEmail:PRE+"profile/sendInvite",getJournal:PRE+"dailyprogress",feedChoice:PRE+"meatballs/feed",setUiPreference:PRE+"api/setpreference",getUiPreference:PRE+"api/getpreference",groupDelChild:PRE+"group/delchild",serviceUnavailable:PRE+"service-unavailable-dialog.html",nextLevel:PRE+"next-level.html",youHaveBonusActivation:PRE+"you-have-bonus-activation.html",noHaveMeatballs:PRE+"no-have-meatballs.html",dailyBonus:PRE+"daily-bonus.html"},contentUrl:PRE+"content/show/{id}",searchByWordUrl:PRE+"search/index?word={word}",voiceFlashTmpl:'<object id="sound" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="23" height="22" align="middle"><param name="FlashVars" value="&id={id}&autoload={autoload}"></param><param name="allowscriptaccess" value="sameDomain"></param><param name="wmode" value="opaque"></param><param name="allowFullScreen" value="false"></param><param name="movie" value="http://static.lingualeo.ru/sound.swf"></param><param name="quality" value="high"></param><embed flashvars="&id={id}&autoload={autoload}" src="http://static.lingualeo.ru/sound.swf" quality="high" bgcolor="#ffffff" width="23" height="22" name="sound" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" wmode="opaque"></embed></object>'};var LANG={translationBox:{translationHint:"Кликните на слове в тексте или выделите текст мышкой.",translationInProgress:"Идет перевод...",translationError:"Ошибка перевода."},wordsList:{editTranslationHint:"Введите свой вариант перевода для ",emptyListHint:"Это&nbsp;&mdash; ваш контекстный словарь.\n\nКликайте по&nbsp;незнакомым словам в&nbsp;тексте и выбирайте перевод к&nbsp;ним.\n\nВы можете изменять перевод слов, добавлять свой, а также удалять слова из&nbsp;списка.\n\nЧтобы перевести целую фразу и добавить её сюда, выделите текст мышкой и нажмите на кнопку под контекстным словарем."},words:{states:{"0":"Слова нет в вашем личном словаре","1":"На первой тренировке","2":"На второй тренировке","3":"На третьей тренировке","4":"Освоено","5":"Выявлено/освоено","6":"Без перевода. Рекомендуется добавить перевод"},stateError:"(ошибка получения статуса слова)"}};(function(a){a.browserTest=function(e,g){var f="unknown",d="X",b=function(k,j){for(var c=0;c<j.length;c=c+1){k=k.replace(j[c][0],j[c][1])}return k},h=function(l,k,j,n){var m={name:b((k.exec(l)||[f,f])[1],j)};m[m.name]=true;m.version=(n.exec(l)||[d,d,d,d])[3];if(m.name.match(/safari/)&&m.version>400){m.version="2.0"}if(m.name==="presto"){m.version=(a.browser.version>9.27)?"futhark":"linear_b"}m.versionNumber=parseFloat(m.version,10)||0;m.versionX=(m.version!==d)?(m.version+"").substr(0,1):d;m.className=m.name+m.versionX;return m};e=(e.match(/Opera|Navigator|Minefield|KHTML|Chrome/)?b(e,[[/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/,""],["Chrome Safari","Chrome"],["KHTML","Konqueror"],["Minefield","Firefox"],["Navigator","Netscape"]]):e).toLowerCase();a.browser=a.extend((!g)?a.browser:{},h(e,/(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/,[],/(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/));a.layout=h(e,/(gecko|konqueror|msie|opera|webkit)/,[["konqueror","khtml"],["msie","trident"],["opera","presto"]],/(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/);a.os={name:(/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase())||[f])[0].replace("sunos","solaris")};if(!g){a("html").addClass([a.os.name,a.browser.name,a.browser.className,a.layout.name,a.layout.className].join(" "))}};a.browserTest(navigator.userAgent)})(jQuery);jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h<k.length;h++){var c=jQuery.trim(k[h]);if(c.substring(0,b.length+1)==(b+"=")){d=decodeURIComponent(c.substring(b.length+1));break}}}return d}};(function($){function toIntegersAtLease(n){return n<10?"0"+n:n}Date.prototype.toJSON=function(date){return this.getUTCFullYear()+"-"+toIntegersAtLease(this.getUTCMonth())+"-"+toIntegersAtLease(this.getUTCDate())};var escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};$.quoteString=function(string){if(escapeable.test(string)){return'"'+string.replace(escapeable,function(a){var c=meta[a];if(typeof c==="string"){return c}c=a.charCodeAt();return"\\u00"+Math.floor(c/16).toString(16)+(c%16).toString(16)})+'"'}return'"'+string+'"'};$.toJSON=function(o,compact){var type=typeof(o);if(type=="undefined"){return"undefined"}else{if(type=="number"||type=="boolean"){return o+""}else{if(o===null){return"null"}}}if(type=="string"){return $.quoteString(o)}if(type=="object"&&typeof o.toJSON=="function"){return o.toJSON(compact)}if(type!="function"&&typeof(o.length)=="number"){var ret=[];for(var i=0;i<o.length;i++){ret.push($.toJSON(o[i],compact))}if(compact){return"["+ret.join(",")+"]"}else{return"["+ret.join(", ")+"]"}}if(type=="function"){throw new TypeError("Unable to convert object of type 'function' to json.")}var ret=[];for(var k in o){var name;type=typeof(k);if(type=="number"){name='"'+k+'"'}else{if(type=="string"){name=$.quoteString(k)}else{continue}}var val=$.toJSON(o[k],compact);if(typeof(val)!="string"){continue}if(compact){ret.push(name+":"+val)}else{ret.push(name+": "+val)}}return"{"+ret.join(", ")+"}"};$.compactJSON=function(o){return $.toJSON(o,true)};$.evalJSON=function(src){return eval("("+src+")")};$.secureEvalJSON=function(src){var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,"@");filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]");filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,"");if(/^[\],:{}\s]*$/.test(filtered)){return eval("("+src+")")}else{throw new SyntaxError("Error parsing JSON, source is not valid.")}}})(jQuery);(function(b){b.dimensions={version:"1.2"};b.each(["Height","Width"],function(d,c){b.fn["inner"+c]=function(){if(!this[0]){return}var f=c=="Height"?"Top":"Left",e=c=="Height"?"Bottom":"Right";return this.is(":visible")?this[0]["client"+c]:a(this,c.toLowerCase())+a(this,"padding"+f)+a(this,"padding"+e)};b.fn["outer"+c]=function(f){if(!this[0]){return}var h=c=="Height"?"Top":"Left",e=c=="Height"?"Bottom":"Right";f=b.extend({margin:false},f||{});var g=this.is(":visible")?this[0]["offset"+c]:a(this,c.toLowerCase())+a(this,"border"+h+"Width")+a(this,"border"+e+"Width")+a(this,"padding"+h)+a(this,"padding"+e);return g+(f.margin?(a(this,"margin"+h)+a(this,"margin"+e)):0)}});b.each(["Left","Top"],function(d,c){b.fn["scroll"+c]=function(e){if(!this[0]){return}return e!=undefined?this.each(function(){this==window||this==document?window.scrollTo(c=="Left"?e:b(window)["scrollLeft"](),c=="Top"?e:b(window)["scrollTop"]()):this["scroll"+c]=e}):this[0]==window||this[0]==document?self[(c=="Left"?"pageXOffset":"pageYOffset")]||b.boxModel&&document.documentElement["scroll"+c]||document.body["scroll"+c]:this[0]["scroll"+c]}});b.fn.extend({position:function(){var h=0,g=0,f=this[0],i,c,e,d;if(f){e=this.offsetParent();i=this.offset();c=e.offset();i.top-=a(f,"marginTop");i.left-=a(f,"marginLeft");c.top+=a(e,"borderTopWidth");c.left+=a(e,"borderLeftWidth");d={top:i.top-c.top,left:i.left-c.left}}return d},offsetParent:function(){var c=this[0].offsetParent;while(c&&(!/^body|html$/i.test(c.tagName)&&b.css(c,"position")=="static")){c=c.offsetParent}return b(c)}});function a(c,d){return parseInt(b.curCSS(c.jquery?c[0]:c,d,true))||0}})(jQuery);jQuery.fn.openDictionaryLink=function(b){var a;var c=this.attr("href").replace(/#/,"");switch(c){case"multitran":a="http://multitran.ru/c/m.exe?CL=1&l1=1&s={word}";break;case"google":a="http://www.google.com/dictionary?source=translation&hl=en&q={word}&langpair=en|ru";break;case"lingvo":a="http://lingvo.abbyyonline.com/ru/en-ru/{word}";break;case"dictionary":a="http://dictionary.reference.com/browse/{word}";break;case"thefreedictionary":a="http://www.thefreedictionary.com/{word}";break}if(a){window.open(a.formatStr({word:b}),"dictionaryWindow","scrollbars,resizable,status,width=900,height=600")}return this};jQuery.fn.wrapWordsToLinks=function(){function a(b){if(b.nodeType==3){jQuery(b).replaceWith(b.data.replace(/([\w-']+)/gi,function(d,c){if(c.toLocaleLowerCase()=="watch"){return c}return isNaN(parseInt(c))?'<a href="#">'+c+"</a>":c}))}else{if(b.nodeType==1&&b.childNodes&&!/(script|style)/i.test(b.tagName)){jQuery(b).contents().each(function(){a(this)})}}}return this.each(function(){a(this)})};jQuery.fn.highlightSentences=function(){function a(b){if(b.nodeType==3){var c=jQuery("<div></div>").text(b.data).html();jQuery(b).replaceWith(c.replace(/(.*?[.;!?])/g,"<span>$1</span>"))}else{if(b.nodeType==1&&b.childNodes&&!/(script|style)/i.test(b.tagName)){jQuery(b).contents().each(function(){a(this)})}}}return this.each(function(){a(this)})};(function(){var a=false,b=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;this.Class=function(){};Class.extend=function(g){var f=this.prototype;a=true;var e=new this();a=false;for(var d in g){e[d]=typeof g[d]=="function"&&typeof f[d]=="function"&&b.test(g[d])?(function(h,i){return function(){var k=this._super;this._super=f[h];var j=i.apply(this,arguments);this._super=k;return j}})(d,g[d]):g[d]}function c(){if(!a&&this.init){this.init.apply(this,arguments)}}c.prototype=e;c.constructor=c;c.extend=arguments.callee;return c}})();String.prototype.formatStr=function(a){var c=this;for(var b in a){c=c.replace(new RegExp("{"+b+"}","g"),a[b])}return c};String.prototype.wrapWordIntoTag=function(c,a){var b=new RegExp("([^\\w]|^)("+c+")([^\\w]|$)","gi");return this.replace(b,"<"+a+">$1$2$3</"+a+">")};String.prototype.htmlen=function(b){var a=this.replace(/&[^#]/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");return b?a:a.replace(/"/g,"&quot;")};String.prototype.removeHtmlTags=function(){return this.replace(/<.*?>/g,"")};String.prototype.lineFeedsToBr=function(){return this.replace(/\n/g,"<br/>")};String.prototype.validateEmail=function(){return/^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(this)};if(!String.prototype.trim){String.prototype.trim=function(){return(this||"").replace(/^\s+|\s+$/g,"")}}Function.prototype.bind=function(b){if(arguments.length<2&&arguments[0]==undefined){return this}var a=this;return function(){return a.apply(b,arguments)}};var TScrollbar=Class.extend({$:null,isVisible:false,scrollPaneHeight:0,timer:null,init:function(a){if($.browser.opera){$(a.scrollbarLocator).remove();return}this.$=this.createDOM(a);this.assignEvents();this.timer=setInterval(this.proceedTimer.bind(this),100);$(window).bind("resize",this.proceedTimer.bind(this))},createDOM:function(a){return{content:$(a.contentLocator),bar:$(a.scrollbarLocator),roller:$(a.scrollbarLocator).find("div")}},destroy:function(){clearInterval(this.timer);this.$.content.unbind("scroll",this.onScrollHandler);this.onScrollHandler=null;this.$=null},assignEvents:function(){var a=this;var b=this.$.roller;this.onScrollHandler=this.updateRollerPos.bind(this);this.$.content.bind("scroll",this.onScrollHandler);b.hover(function(){a.mouseovered=1;a.enlargeRoller()},function(){a.mouseovered=0;if(!a.dragging){a.delargeRoller()}}).draggable({axis:"y",containment:"parent",drag:function(){a.proceedRollerMoved()},start:function(){a.dragging=1},stop:function(){a.dragging=0;if(!a.mouseovered){a.delargeRoller()}}}).mousedown(function(c){c.stopPropagation()});this.$.bar.parent().mousedown(this.proceedScrollbarClick.bind(this)).hover(function(){$(this).addClass("active")},function(){$(this).removeClass("active")})},proceedRollerMoved:function(){var b=parseInt(this.$.roller.css("top"));var a=b/(this.$.bar.height()-this.$.roller.height());this.setContentScrollPos(Math.ceil((this.$.content.get(0).scrollHeight-this.$.content.get(0).offsetHeight)*a))},proceedScrollbarClick:function(a){this.moveRollerToPosY(a.pageY-$(a.target).offset().top-parseInt(this.$.roller.height()/2),true)},moveRollerToPosY:function(b,a){if(b<0){b=0}else{if(b+this.$.roller.height()>this.$.bar.height()){b=this.$.bar.height()-this.$.roller.height()}}if(a){this.$.roller.animate({top:b},{duration:100,step:this.proceedRollerMoved.bind(this),complete:this.proceedRollerMoved.bind(this)})}else{this.$.roller.css("top",b);this.proceedRollerMoved()}},enlargeRoller:function(){this.$.roller.animate({left:-5,width:14},{duration:100})},delargeRoller:function(){this.$.roller.animate({left:-3,width:10},{duration:100})},update:function(){var d=this.$.content.get(0);var a=d.scrollHeight;var b=d.offsetHeight;if(a<=b){this.isVisible=false;this.$.bar.parent().hide()}else{this.isVisible=true;this.$.bar.parent().show();var c=(b/a)*this.$.bar.height();if(c>200){c=200}else{if(c<15){c=15}}this.$.roller.height(c);this.updateRollerPos()}},setContentScrollPos:function(a){this.$.content.get(0).scrollTop=a},updateRollerPos:function(){if(this.isVisible){var b=this.$.content.get(0).scrollHeight;var c=this.$.content.get(0).clientHeight;var a=this.$.content.get(0).scrollTop/(b-c);this.$.roller.css("top",(this.$.bar.height()-this.$.roller.height())*a)}},proceedTimer:function(){if(this.$.content.get(0).clientHeight!=this.lastHeight||this.$.content.get(0).scrollHeight!=this.lastContentHeight){this.lastHeight=this.$.content.get(0).clientHeight;this.lastContentHeight=this.$.content.get(0).scrollHeight;this.update()}}});var TAjaxRequest=Class.extend({pool:{},showAlertsForUnfinishedRequests:true,unauthRequests:[],saveUnAuthRequests:true,currentServerHash:null,onAuthRequired:null,onServiceUnavailable:null,onServerUpdated:null,init:function(b){this.currentServerHash=b;if(this.showAlertsForUnfinishedRequests){var a=this;$(window).bind("beforeunload",function(){return a.proceedDocumentUnload()})}},post:function(b,a,c){return this.sendRequest("POST",b,a,c)},get:function(b,a,c){return this.sendRequest("GET",b,a,c)},sendRequest:function(g,d,c,f){var b=this;var a=this.addItemToPool(f);d.params=d.params||{};if(typeof d.params=="string"){d.params+="&_hash="+this.currentServerHash}else{d.params._hash=this.currentServerHash}var e={url:d.url,type:g,data:d.params,timeout:c,cache:d.cache?d.cache:false,processData:d.processData?d.processData:true,success:function(i){b.removeItemFromPool(a);if(d.plainTextResponse){d.onSuccess(i)}else{var h=(typeof i!="object")?{error_msg:"Неверный формат данных от сервера.",error_code:-1}:h=i;if(h.error_code!=-1){if(h._hash!=b.currentServerHash){if(b.onServerUpdated){b.onServerUpdated()}delete d;return}if(h.error_msg){if(d.onError){d.onError(h.error_msg,h)}}else{setMeatballsCount(h);if(d.onSuccess){d.onSuccess(h)}}if(d.onComplete){d.onComplete(h)}}else{if(i.indexOf("$SERVICE_UNAVAILABLE$")>-1){if(b.onServiceUnavailable){b.onServiceUnavailable()}}else{if(d.onError){d.onError(h.error_msg,h)}if(d.onComplete){d.onComplete(h)}}}}delete d},error:function(i,h){b.removeItemFromPool(a);if(i.status!=401){if(d.onServerError){d.onServerError(h)}if(d.onComplete){d.onComplete(null)}delete d}},complete:function(h){if(h.status==401&&b.saveUnAuthRequests){b.unauthRequests.push({method:g,data:d,timeout:c,abortMsg:f});if(b.onAuthRequired){b.onAuthRequired()}}}};return $.ajax(e)},reSendUnauthorizedRequests:function(){var a=this.unauthRequests;this.clearUnauthorizedRequests();for(var b in a){this.sendRequest(a[b].method,a[b].data,a[b].timeout,a[b].abortMsg)}},clearUnauthorizedRequests:function(){this.unauthRequests=[]},addItemToPool:function(a){if(a){var b=Utils.generateUniqID();this.pool[b]=a;return b}else{return null}},removeItemFromPool:function(b){if(b in this.pool){var a=this.pool[b];delete this.pool[b];return a}else{return null}},getFirstItemInPool:function(){for(var a in this.pool){return this.pool[a]}return null},proceedDocumentUnload:function(){if(this.getFirstItemInPool()){return this.getFirstItemInPool()+"\nЕсли вы уйдете со страницы сейчас, некоторые данные могут быть утеряны."}}});var ServCommTraining={getTrainingData:function(a,c){var b={url:CONFIG.ajax.getTrainingData.formatStr({ind:a+1}),params:{},onSuccess:function(d){if(c){c(d)}}};Ajax.post(b,30000,null)},sendWordCorrectAnswer:function(d,c,a,e){var b={url:CONFIG.ajax.setTrainingWin,params:{training_index:a+1,question_id:d,answer_id:c},onSuccess:function(f){if(e){e(f)}}};Ajax.post(b,30000,null)},sendWordIncorrectAnswer:function(d,c,a){var b={url:CONFIG.ajax.setTrainingLoose,params:{training_index:a+1,question_id:d,answer_id:c}};Ajax.post(b,30000,null)},getWordsStatistics:function(b){var a={url:CONFIG.ajax.getWordsStats,params:{},onSuccess:function(c){if(!c.training1){c.training1=0}if(!c.training2){c.training2=0}if(!c.training3){c.training3=0}if(b){b(c)}}};Ajax.post(a,30000,null)}};var TCustomCollection=Class.extend({init:function(){this.collection=[]},free:function(){this.clearCollection();this.collection=null},clearCollection:function(){this.enumCollection(function(a){if(a.free){a.free()}});this.collection=[]},getCollectionCount:function(){return this.collection.length},getObjectIndexInCollection:function(a){var b=this.collection.length;while(--b>=0){if(this.collection[b]==a){return b}}return -1},enumCollection:function(c){for(var b=0,a=this.collection.length;b<a;b++){if(c(this.collection[b],b)===false){return}}},addToCollection:function(a){if(!(a instanceof Array)){a=[a]}var b=this;$(a).each(function(){if(b.getObjectIndexInCollection(this)==-1){b.collection.push(this)}})},removeFromCollection:function(a){if(!(a instanceof Array)){a=[a]}var b=this;$(a).each(function(){var c=b.getObjectIndexInCollection(this);if(c!=-1){b.collection.splice(c,1)}})},sortCollection:function(a){this.collection.sort(a)},getItemsCount:function(){return this.collection.length},getLastObjectInCollection:function(){return this.collection.length?this.collection[this.collection.length-1]:null}});var TQuickSearchField=Class.extend({$:null,onChange:null,init:function(a,b){this.$={};this.defaultText=b;this.createDOM(a);this.$.elem.val(b)},createDOM:function(a){var b=this;this.$.elem=$(a).keyup(function(c){b.proceedKeyUp(c);if($(this).val().trim()){$(this).attr("changed",1)}else{$(this).removeAttr("changed")}}).focus(function(){if(!$(this).attr("changed")){$(this).val("").removeClass("inactive")}this.select()}).blur(function(){if(!$(this).attr("changed")){$(this).val(b.defaultText).addClass("inactive")}})},free:function(){this.$=null},getFieldElement:function(){return this.$.elem},proceedKeyUp:function(b){if(b.keyCode==27){this.$.elem.val("")}var a=this.$.elem.val().trim().toLocaleLowerCase();if(this.onChange){this.onChange(a)}}});var TTranslator=Class.extend({init:function(){},free:function(){},translateContextWord:function(b,c){var a={url:CONFIG.ajax.getWordTranslation,params:{contextdict_id:b},onSuccess:function(d){if(c){c(d.translate||[],!d.translate)}},onError:function(){if(c){c([],true)}}};Ajax.get(a,30000,null)},translateWordById:function(b,c){var a={url:CONFIG.ajax.getWordTranslation,params:{word_id:b},onSuccess:function(d){if(c){c({translations:d.translate||[],isKnownWord:d.knownWord,wordId:d.word_id,isError:!d.translate})}},onError:function(){if(c){c({translate:[],isError:true})}}};Ajax.get(a,30000,null)},translateWordByText:function(b,c){var a={url:CONFIG.ajax.getWordTranslation,params:{word:b},onSuccess:function(d){if(c){c({translations:d.translate||[],isKnownWord:d.knownWord,wordId:d.word_id,isError:!d.translate})}},onError:function(){if(c){c({translate:[],isError:true})}}};Ajax.get(a,30000,null)}});var TGoogleTranslator=Class.extend({init:function(){},free:function(){},translate:function(a,c,b){if(window.google){google.language.translate(a,b?"ru":"en",b?"en":"ru",function(d){if(c){c(d)}})}else{if(c){c({error:true})}}}});var TTranslationBox=Class.extend({$:{},originalText:null,translatedText:null,onButtonClick:null,init:function(a,c){var b=this;this.$.elem=$(a);this.$.btn=$(c).css("opacity",0.5).click(function(){return b.proceedButtonClick()})},free:function(){this.$=null},setTranslation:function(c,a){this.originalText=c;this.translatedText=a;var b=c.length>100?c.substr(0,100)+"...":c;this.$.elem.html("<b>"+b+"</b><hr/>"+a).attr("title",a);this.setButonVisibility(c&&(c.length<=50)&&a)},setHint:function(a){this.originalText=null;this.translatedText=null;this.setButonVisibility(false);this.$.elem.empty().append($("<i></i>").text(a))},setButonVisibility:function(a){if(a){this.$.btn.css("opacity",1).attr("active",1)}else{this.$.btn.css("opacity",0.1).attr("active",0)}},proceedButtonClick:function(){if(this.$.btn.attr("active")==1){if(this.onButtonClick&&this.originalText&&this.translatedText){this.onButtonClick(this.originalText,this.translatedText)}}return false}});var TWordsList=TCustomCollection.extend({$:null,isAnimated:true,onAddItem:null,onDeleteItem:null,onEditItem:null,onSelectItem:null,onScroll:null,onBeforeShowTranslationsList:null,onAfterShowTranslationsList:null,onRequireItemTranslationsList:null,init:function(a,b){this._super();this.$=this.createDOM(a);this.assignEvents();this.createItems(b)},free:function(){this._super();this.$=null},createDOM:function(a){return{elem:$(a)}},assignEvents:function(){var a=this;this.$.elem.bind("scroll",function(){if(a.onScroll){a.onScroll(this.scrollTop)}})},getRootElement:function(){return this.$.elem},isItemExist:function(b){var a;b=b.toLocaleLowerCase().trim();this.enumCollection(function(c){if(c.originalText.toLocaleLowerCase()==b){a=c;return false}});return a},getItemById:function(b){var a;this.enumCollection(function(c){if(c.id==b){a=c;return false}});return a},createItems:function(b){this.clearItems();if(b){var a=this;$(b).each(function(){a.addItem({id:this.id,originalText:this.word,translatedText:this.tword,stateId:this.stateId,context:this.context})})}},clearItems:function(){this.clearCollection();this.getRootElement().empty()},addItem:function(a,c){this.removeHintMessage();var b=new TWordsListItem({id:a.id,originalText:a.originalText,translatedText:a.translatedText,context:a.context||null,data:a.data});b.onDelete=this.proceedDeleteItem.bind(this);b.onEdit=this.proceedEditItem.bind(this);b.onSelect=this.proceedSelectItem.bind(this);b.onBeforeShowTranslationsList=this.proceedBeforeShowTranslationsMenu.bind(this);b.onAfterShowTranslationsList=this.proceedAfterShowTranslationsMenu.bind(this);b.onRequireTranslationsList=this.proceedRequireItemTranslationsList.bind(this);if(this.onAddItem){this.onAddItem(b,a.context)}this.addToCollection(b);this.getRootElement().append(this.isAnimated?b.getRootElement().fadeIn("normal"):b.getRootElement());if(c){this.scrollToBottom()}return b},scrollToBottom:function(){this.getRootElement().get(0).scrollTop=99999},moveItemToBottom:function(b){if(this.getLastObjectInCollection()==b){return b}else{this.removeFromCollection(b);var a=this.addItem({id:b.id,originalText:b.originalText,translatedText:b.translatedText,context:b.context,data:b.data},true);b.removeItemElement();return a}},requireItemTranslation:function(b,a){if(b.getTranslationsList()){a(b.getTranslationsList())}else{if(this.onRequireItemTranslationsList){this.onRequireItemTranslationsList(b,a)}}},getItemsCount:function(){return this.getCollectionCount()},setHintMessage:function(a){this.$.hint=$('<p class="hint"></p>').html(a.lineFeedsToBr()).appendTo(this.$.elem)},removeHintMessage:function(){if(this.$.hint){this.$.hint.remove();this.$.hint=null}},setAnimationEnabled:function(a){this.isAnimated=a},hideAllTranslationMenus:function(){this.enumCollection(function(a){a.hideTranslationMenu()})},proceedDeleteItem:function(a){a.disableItem();this.removeFromCollection(a);if(this.onDeleteItem){this.onDeleteItem(a)}},proceedEditItem:function(a){if(this.onEditItem){this.onEditItem(a)}},proceedSelectItem:function(a){this.enumCollection(function(b){if(b!=a&&b.isSelected()){b.switchSelectedState(false);return false}});if(this.onSelectItem){this.onSelectItem(a,this)}},proceedBeforeShowTranslationsMenu:function(a){this.hideAllTranslationMenus()},proceedAfterShowTranslationsMenu:function(d){var c=this.getRootElement();var b=c.get(0).scrollTop+c.height();var a=d.getRootElement().get(0).offsetTop;var e=d.getTranslationsListElement().height();if(a+e>b){c.animate({scrollTop:a},200)}},proceedRequireItemTranslationsList:function(b,a){this.requireItemTranslation(b,a)}});var TWordsListItem=Class.extend({SHOW_STATE_ICON:false,itemTmpl:'<div class="item c2"><a href="#" class="del c2" title="Убрать из списка">X</a><a href="#" class="word" title="Клик &mdash; открыть словарную статью" target="_blank">{word}</a>&nbsp;&ndash; <a href="#" class="tran c2" title="Клик &mdash; изменить перевод"></a></div>',$:null,id:null,state:null,context:null,translations:null,data:null,isDisabled:false,onDelete:null,onEdit:null,onSelect:null,onBeforeShowTranslationsList:null,onRequireTranslationsList:null,init:function(a){this.id=a.id;this.state=a.stateId;this.originalText=a.originalText?a.originalText.trim():"";this.context=a.context;this.data=a.data;this.setTranslation(a.translatedText);this.$=this.createDOM();if(this.SHOW_STATE_ICON){this.createDOM_stateIcon()}this.assignEvents()},getRootElement:function(){return this.$.elem},free:function(){this.$=null;this.id=null},createDOM:function(){var b=$(this.itemTmpl.formatStr({word:this.originalText.htmlen()}));b.find("a.word").attr("href","/userdict#/"+escape(this.originalText));var a=b.find("a.tran").html(this.translatedText?this.translatedText.htmlen():"<i>(нет перевода)</i>");return{elem:b,editElem:a}},createDOM_stateIcon:function(){this.$.stateIcon=$('<span class="ws-icon"></span>').addClass("state-"+this.state).attr("title",LANG.words.states[this.state]||LANG.words.stateError).appendTo(this.$.elem)},assignEvents:function(){var a=this;this.$.elem.hover(function(){$(this).addClass("active")},function(){$(this).removeClass("active")}).click(function(){a.proceedClick()});this.$.elem.find("a.del").click(function(){a.deleteItem();return false}).hover(function(){a.getRootElement().addClass("deleting")},function(){a.getRootElement().removeClass("deleting")});if(this.$.editElem){this.$.editElem.click(function(){a.proceedEditTranslation();return false})}},proceedEditTranslation:function(){if(!this.isDisabled){this.showTranslationsList()}},setState:function(a){if(this.$.stateIcon){this.$.stateIcon.removeClass("state-"+this.state).addClass("state-"+a)}this.state=a},deleteItem:function(a){if(this.onDelete){this.onDelete(this)}this.removeItemElement(a)},removeItemElement:function(b){if(b){this.getRootElement().remove();this.free()}else{var a=this;this.getRootElement().fadeOut("fast",function(){a.getRootElement().remove();a.free()})}},enableItem:function(){this.isDisabled=false;this.getRootElement().removeClass("disabled").css("opacity",1)},disableItem:function(){this.isDisabled=true;this.getRootElement().addClass("disabled").css("opacity",0.4)},switchSelectedState:function(a){if(a){this.getRootElement().addClass("selected")}else{this.getRootElement().removeClass("selected")}},isSelected:function(){return this.getRootElement().hasClass("selected")},setTranslation:function(b){var a=b?b.trim():null;if(a!=this.translatedText){this.translatedText=a;if(this.$){this.$.editElem.html(this.translatedText?this.translatedText.htmlen():"(нет перевода)")}return true}return false},setTranslationsList:function(a){if(a instanceof Array){this.translations=a}},getTranslationsList:function(){return this.translations},getTranslationsListElement:function(){return this.TransList?this.TransList.getRootElement():null},showTranslationsList:function(){if(this.TransList){this.TransList.free();this.TransList=null}var a=this;if(!this.getTranslationsList()){if(this.onRequireTranslationsList){this.onRequireTranslationsList(this,function(b){a.setTranslationsList(b);a.showTranslationsList()})}}else{if(this.onBeforeShowTranslationsList){this.onBeforeShowTranslationsList(this)}this.TransList=new TWordsListTranslationMenu(this);this.TransList.onSelect=function(b){a.hideTranslationMenu();a.editTranslation(b)};if(this.onAfterShowTranslationsList){this.onAfterShowTranslationsList(this)}}},hideTranslationMenu:function(){if(this.TransList){this.TransList.free();this.TransList=null}},editTranslation:function(a){if(this.setTranslation(a)){if(this.onEdit){this.onEdit(this)}}},proceedClick:function(){this.switchSelectedState(true);if(this.onSelect){this.onSelect(this)}}});var TWordsListTranslationMenu=Class.extend({$:null,item:null,onSelect:null,firstItemTmpl:'<li class="original"><b class="word">{word}</b> &ndash; <span class="tran collapse">{tran}</span></li>',addItemTmpl:'<li class="add"><a href="#" class="c3">{text}</a></li>',hintItemTmpl:'<li class="hint">{text}</li>',linksItemTmpl:'<li class="dicts"><span>Словари:</span><a href="#google" class="icon-dict google" title="Google"></a><a href="#multitran" class="icon-dict multitran" title="Multitran"></a><a href="#lingvo" class="icon-dict lingvo" title="Abbyy Lingvo"></a><a href="#dictionary" class="icon-dict dictionary" title="Dictionary.com"></a><a href="#thefreedictionary" class="icon-dict thefreedictionary" title="TheFreeDictionary.com"></a></li>',itemTmpl:'<li class="opt"><i>{votes}</i><a href="#" class="c3">{tran}</a></li>',init:function(a){this.item=a;this.$=this.createDOM();this.assignEvents()},free:function(){this.getRootElement().remove();this.$=null;this.item=null},getRootElement:function(){return this.$.elem},createDOM:function(){var b=this;var d=this.item.getTranslationsList();var e=$('<ul class="popup-menu c3"></ul>');e.append($(this.firstItemTmpl.formatStr({word:this.item.originalText.htmlen(),tran:this.item.translatedText?this.item.translatedText.htmlen():""})));if(d.length){var g=this.item.translatedText?this.item.translatedText.toLocaleLowerCase():null;for(var c in d){var f=(d[c].value.toLocaleLowerCase()==g)?"selected":"";var a=$(this.itemTmpl.formatStr({tran:d[c].value.htmlen(),votes:d[c].votes}));a.attr("tran_id",d[c].id).find("a").attr("tran",d[c].value);e.append(a.addClass(f))}}else{e.append($(this.hintItemTmpl.formatStr({text:"(нет переводов)"})))}e.append(this.addItemTmpl.formatStr({text:d.length?"Изменить перевод...":"Добавить перевод..."}));e.append(this.linksItemTmpl.formatStr({word:this.item.originalText})).find(".dicts a").click(function(){$(this).openDictionaryLink(b.item.originalText)});return{elem:e.appendTo(this.item.getRootElement())}},assignEvents:function(){var a=this;this.getRootElement().find(".opt a").click(function(){a.proceedSetTranslation($(this).attr("tran"));return false}).end().find(".original:eq(0)").click(function(){a.proceedSetTranslation(a.item.translatedText);return false}).end().find(".add:eq(0) a").click(function(){a.proceedAddTranslation();return false})},proceedAddTranslation:function(){var a=prompt(LANG.wordsList.editTranslationHint+'"'+this.item.originalText+'"',this.item.translatedText||"");if(a!==null){this.proceedSetTranslation(a)}},proceedSetTranslation:function(a){if(this.onSelect){this.onSelect(a)}}});var TTextContainer=Class.extend({$:{},originalText:null,curActiveSentence:null,sentenceTranslatePause:400,sentenceTranslateTimer:null,onSentenceTranslate:null,onSentenceMouseOver:null,onSentenceMouseOut:null,onSentenceClick:null,onClickWord:null,onSaveText:null,onSetSelection:null,cache:[],init:function(a,b){this.$.elem=$(a);this.$.btnEdit=$(b);this.initEvents();this.updateText(this.$.elem.html().replace(/\n/g,"").replace(/<br\/?>/g,"\n"))},getMainElement:function(){return this.$.elem},initEvents:function(){var a=this;this.$.elem.click(function(b){return a.proceedContainerClick(b)}).mouseup(function(){return a.proceedContainerMouseUp()});this.$.btnEdit.click(function(){return a.proceedButtonClick()})},updateText:function(f,a,d){var b;var e;if(d&&(a in this.cache)){e=this.$.elem.html(this.cache[a]).find("span")}else{b=f.replace(/(([\d]{0,}.+?)([.!?;]\s?|\r?\n|$))/g,"<span>$2</span>$3").replace(/\r?\n/g,"<br/>");e=this.$.elem.html(b).find("span");if(d){e.wrapWordsToLinks()}else{e.removeClass("tran")}this.cache[a]=this.$.elem.html()}var c=this;e.hover(function(){return c.proceedSentenceMouseOver(this)},function(){return c.proceedSentenceMouseOut(this)}).click(function(){return c.proceedSentenceClick(this)});this.curActiveSentence=null},highlightWords:function(b){var c={};for(var d in b){c[d.toLocaleLowerCase()]=b[d]||""}var a;this.$.elem.find("a").each(function(){a=$(this);d=a.text().toLocaleLowerCase();if(d in c){a.addClass("selected").attr("title",c[d]||"")}})},dehighlightWord:function(a){a=a.toLocaleLowerCase().trim();this.$.elem.find("a").each(function(){if($(this).text().toLocaleLowerCase()==a){$(this).removeClass("selected").removeAttr("title")}})},free:function(){this.$=null},setButonVisibility:function(a){if(a){this.$.btn.show()}else{this.$.btn.hide()}},proceedButtonClick:function(){return true},proceedContainerClick:function(b){if(b.target.tagName.toLowerCase()=="a"){var a=$(b.target);if(this.onClickWord){this.onClickWord(a.text(),a.parent().text())}}return false},proceedSentenceMouseOver:function(b){var a=$(b);if(!a.hasClass("selected")){a.addClass("selected");this.curActiveSentence=this;if(this.onSentenceMouseOver){this.onSentenceMouseOver(a.text())}if(this.sentenceTranslateTimer){clearTimeout(this.sentenceTranslateTimer)}this.sentenceTranslateTimer=setTimeout((function(){if(this.onSentenceTranslate){this.onSentenceTranslate(a.text(),a)}this.sentenceTranslateTimer=null}).bind(this),this.sentenceTranslatePause)}return true},proceedSentenceMouseOut:function(b){var a=$(b);if(a.hasClass("selected")){if(this.sentenceTranslateTimer){clearTimeout(this.sentenceTranslateTimer)}a.removeClass("selected");this.curActiveSentence=null;if(this.onSentenceMouseOut){this.onSentenceMouseOut($(this).text())}}return true},proceedSentenceClick:function(a){if(this.onSentenceClick){this.onSentenceClick($(a))}return true},proceedContainerMouseUp:function(){var a="";if(window.getSelection){a=window.getSelection().toString()}else{if(document.selection){a=document.selection.createRange().text}}if(a.length>1){if(this.onSetSelection){this.onSetSelection(a)}return false}return true}});var TCustomMenu=Class.extend({timer:null,showOnClick:true,showOnMouseOver:false,fakeShowHide:false,itemsLocator:"a",curElem:null,onShowMenu:null,onHideMenu:null,onClickItem:null,init:function(a){if("showOnClick" in a){this.showOnClick=a.showOnClick}if("showOnMouseOver" in a){this.showOnMouseOver=a.showOnMouseOver}if("itemsLocator" in a){this.itemsLocator=a.itemsLocator}this.$=this.createDOM(a.menuLocator);this.assignEvents();this.assignButton(a.buttonLocator);this.updateItems()},createDOM:function(a){return{elem:$(a)}},assignEvents:function(){var a=this;this.$.elem.mouseover(function(){a.emulateMouseOver(a.curElem)}).mouseout(this.emulateMouseOut.bind(this))},updateItems:function(){var a=this;this.$.elem.find(this.itemsLocator).click(function(){a.proceedItemClick($(this));return false})},getRootElement:function(){return this.$.elem},hide:function(){if(!this.onHideMenu||this.onHideMenu()!==false){if(!this.fakeShowHide){this.getRootElement().hide()}if(this.timer){clearTimeout(this.timer);this.timer=null}this.curElem=null}},assignButton:function(b){if(b){var a=this;$(b).each(function(){var d=this;var c=$(this);if(!c.attr("_tcm")){if(a.showOnClick){c.click(function(){a.proceedShowMenu(d);return false})}c.attr("_tcm",1).mouseover(function(){a.emulateMouseOver(d)}).mouseout(a.emulateMouseOut.bind(a))}})}},proceedShowMenu:function(a){if(a!=this.curElem){this.curElem=a;if(!this.onShowMenu||this.onShowMenu(a)!==false){if(!this.fakeShowHide){this.getRootElement().fadeIn("fast")}}else{if(!this.fakeShowHide){this.getRootElement().hide()}}}},proceedItemClick:function(a){if(!this.fakeShowHide){this.hide()}if(this.onClickItem){this.onClickItem(a)}},proceedMouseEvents:function(a){if(this.timer){clearTimeout(this.timer)}if(!a){var b=this;this.timer=setTimeout(function(){b.timer=null;b.curElem=null;b.hide()},1000)}},emulateMouseOut:function(){this.proceedMouseEvents(false)},emulateMouseOver:function(a){this.proceedMouseEvents(true);if(this.showOnMouseOver){this.proceedShowMenu(a)}}});