(function(a,b){var c=null,d=null,e=null;c=function(){this.more="more"},d=function(){this.more="View more"},e=function(){this.oApplyTo=null,this.oBackupApplyTo=null,this.oTarget=null,this.oClasses=new c,this.oTexts=new d,this.nWords=0,this.nWordsCounter=0,this.oViewMore=null,this.oSerialized={},this.oDocumentFragment=b.createDocumentFragment(),this.bTest=!1,this.nIdTest=0,this.bNeedViewMore=!1,this.bNotViewMore=!1},e.prototype.applyTo=function(a){return a?(this.oApplyTo=a,this.oBackupApplyTo=a.cloneNode(!0),this):this},e.prototype.setTarget=function(a){return a?(this.oTarget=a,this):this},e.prototype.setClasses=function(a){return a?(this.oClasses=a,this):this},e.prototype.setTexts=function(a){return a?(this.oTexts=a,this):this},e.prototype.setWords=function(a){return a?(this.nWords=a-1,this):this},e.prototype.trim=function(a){return a.replace(/^\s+/g,"").replace(/\s+$/g,"")},e.prototype.countWords=function(a){return this.trim(a).split(" ").length},e.prototype.getOnlyNumberOfWords=function(a,b){return this.trim(a).split(" ").splice(0,b).join(" ")},e.prototype.createViewMore=function(){var a=b.createElement("a");a.className=this.oClasses.more,a.title=this.oTexts.more,a.innerHTML=this.oTexts.more,this.oViewMore=a},e.prototype.getFirstElementOfObject=function(a){var b=null,c="";for(c in a)if(a.hasOwnProperty(c)){b=a[c];break}return b},e.prototype.deserializeObject=function(a,c){var d=null,e="";if(a.nodeType===1){d=b.createElement(a.tagName);if(typeof a.attributes!="undefined")for(e in a.attributes)a.attributes.hasOwnProperty(e)&&d.setAttribute(e,a.attributes[e]);c.appendChild(d)}else a.nodeType===3&&(typeof a.textContent!="undefined"?d=b.createTextNode(a.textContent):a.data?d=b.createTextNode(a.data):d=b.createTextNode(a.innerText),c.appendChild(d));typeof a.childNodes!="undefined"&&this.loopOnDeserialize(a.childNodes,d)},e.prototype.loopOnDeserialize=function(a,b){var c="";for(c in a)a.hasOwnProperty(c)&&this.deserializeObject(a[c],b)},e.prototype.deserializeSerializedObject=function(a,c){var d=!1,e=null;typeof a=="undefined"&&(a=this.getFirstElementOfObject(this.oSerialized),this.oDocumentFragment=b.createDocumentFragment(),d=!0),typeof c=="undefined"&&(e=b.createElement("div"),this.oDocumentFragment.appendChild(e),c=e),this.deserializeObject(a,c),typeof a.childNodes!="undefined"&&this.loopOnDeserialize(a.childNodes,c)},e.prototype.serializeDomObject=function(a,c){var d=Math.random()*15412457562,e=null,f=[],g=null,h=0,i=0,j=0,k=0,l=a.childNodes.length;this.bTest&&(d="__"+(this.nIdTest+=1)+"__");if(this.nWordsCounter<this.nWords){e={},e.nodeType=a.nodeType,typeof a.tagName!="undefined"&&(e.tagName=a.tagName.toLowerCase()),f=a.attributes;if(f){e.attributes={},i=f.length;for(;h<i;h+=1)g=f[h],g.nodeValue&&(e.attributes[g.name]=g.value)}e.nodeType===3&&(j=this.nWordsCounter,typeof a.textContent!="undefined"?this.nWordsCounter+=this.countWords(this.trim(a.textContent)):a.data?this.nWordsCounter+=this.countWords(this.trim(a.data)):this.nWordsCounter+=this.countWords(this.trim(a.innerText)),this.nWordsCounter<this.nWords?typeof a.textContent!="undefined"?e.textContent=a.textContent:a.data?e.innerText=a.data:e.innerText=a.innerText:(this.bNeedViewMore=!0,j<this.nWords&&this.nWordsCounter>this.nWords?typeof a.textContent!="undefined"?e.textContent=this.getOnlyNumberOfWords(a.textContent,this.nWords-j):a.data?e.innerText=this.getOnlyNumberOfWords(a.data,this.nWords-j):e.innerText=this.getOnlyNumberOfWords(a.innerText,this.nWords-j):b.body.textContent?e.textContent="":e.innerText=""));if(a.hasChildNodes()){e.childNodes={},k=0,l=a.childNodes.length;for(;k<l;k+=1)this.serializeDomObject(a.childNodes[k],e.childNodes)}typeof c=="undefined"?this.oSerialized[d]=e:c[d]=e}},e.prototype.addEvent=function(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent&&a.attachEvent("on"+b,c)},e.prototype.setBehaviour=function(){var a=this;this.addEvent(this.oViewMore,"click",function(){return a.showAll(),!1})},e.prototype.showAll=function(){var a=this.oTarget,b=a.parentNode;b.insertBefore(this.oBackupApplyTo,a),b.removeChild(a)},e.prototype.init=function(){this.serializeDomObject(this.oApplyTo),this.deserializeSerializedObject();var a=this.oDocumentFragment.childNodes[0];a.removeChild(this.oDocumentFragment.childNodes[0].childNodes[0]),this.oTarget.innerHTML="",this.createViewMore(),this.bNeedViewMore&&!this.bNotViewMore&&(a.appendChild(b.createTextNode(" ... ")),a.appendChild(this.oViewMore),this.setBehaviour()),this.oTarget.appendChild(this.oDocumentFragment)},e.run=function(a,b,c,d,f){var g=new e;g.applyTo(a).setTarget(b).setWords(c),typeof d!="undefined"&&g.setTexts(d),typeof f!="undefined"&&g.setClasses(f),g.init()},a.Cutter=e})(window,document)
