(function(){function g(b,h,a){function l(){if(c)return null;var e=h;if(h.childNodes&&h.childNodes.length&&!d)h=h.firstChild;else if(h.nextSibling)h=h.nextSibling,d=!1;else if(h.parentNode)h=h.parentNode,h===b&&(c=!0),d=!0,l();e===a&&(c=!0);return e}var h=h||b.childNodes[0],c=!h,d=!1;return l}function a(b){for(var h=1;h<arguments.length;h++)for(key in arguments[h])b[key]=arguments[h][key];return b}function d(b){return(b||"").replace(/^\s+|\s+$/g,"")}function c(b,h){var a="";document.defaultView&&document.defaultView.getComputedStyle? a=document.defaultView.getComputedStyle(b,"").getPropertyValue(h):b.currentStyle&&(h=h.replace(/\-(\w)/g,function(b,h){return h.toUpperCase()}),a=b.currentStyle[h]);return a}function e(b,h){for(;b&&!m(h).test(b.className);)b=b.parentNode;return b||null}function j(b,h){for(var a=g(b),l;l=a();)if(l.nodeType==1&&m(h).test(l.className))return l}function k(b){for(var b=g(b),h;h=b();)if(h.nodeType==3)return h}function r(b,h){if(b.getElementsByClassName)return b.getElementsByClassName(h);else{for(var a= [],l,c=g(b);l=c();)l.nodeType==1&&m(h).test(l.className)&&a.push(l);return a}}function s(b){for(var h=[],a=g(b);b=a();)b.nodeType==3&&h.push(b);return h}function m(b){return RegExp("(^|\\s+)"+b+"(?:$|\\s+)","g")}function u(b,h){if(!m(h).test(b.className))b.className=b.className+" "+h}function t(b,h){var a=m(h);if(a.test(b.className))b.className=d(b.className.replace(a,"$1"))}function v(b,h){for(var a=0,l=h.length;a<l;a++)if(h[a]===b)return a;return-1}function o(b,h,a){b.addEventListener?b.addEventListener(h, a,!1):b.attachEvent&&b.attachEvent("on"+h,a)}function x(b){if(b.pageX==null){var h=document.documentElement,a=document.body;return{x:b.clientX+(h&&h.scrollLeft||a&&a.scrollLeft||0)-(h.clientLeft||0),y:b.clientY+(h&&h.scrollTop||a&&a.scrollTop||0)-(h.clientTop||0)}}return{x:b.pageX,y:b.pageY}}var p=function(b){this.options=a({},p.default_options,b);a(this,{counter:0,savedSel:[],ranges:{},childs:[],blocks:{}});this.init()};p.default_options={regexp:"[^\\s,;:\u2013.!?<>\u2026\\n\u00a0\\*]+",selectable:"maintext", marker:"txtselect_marker",location:window.location,ignored:null,onMark:function(){$.TextSelectorMessage()},onUnmark:null,onHashRead:function(){var b=j(this.selectable,"user_selection_true");b&&window.setTimeout(function(){for(var a=0,f=0;b;)a+=b.offsetLeft,f+=b.offsetTop,b=b.offsetParent;window.scrollTo(a,f-150)},1)},is_block:function(b){return b.nodeName=="BR"||v(c(b,"display"),["inline","none"])==-1}};p.prototype={init:function(){this.selectable=typeof this.options.selectable=="string"?document.getElementById(this.options.selectable): this.options.selectable;var b=typeof this.options.marker=="string"?document.getElementById(this.options.marker):this.options.marker;if(typeof this.options.regexp!="string")throw"regexp is set as string";this.regexp=RegExp(this.options.regexp,"ig");var a=this;this.selectable&&(this.enumerateElements(),o(document,"mouseup",function(f){var l=x(f);window.setTimeout(function(){var f=window.getSelection().toString();if(f!=""&&a.regexp.test(f)&&a.range_is_selectable())b.style.top=l.y-33+"px",b.style.left= l.x+5+"px",u(b,"show")},1)}),o(b,"click",function(f){f.preventDefault?f.preventDefault():f.returnValue=!1;t(b,"show");a.range_is_selectable()&&(a.addSelection(),a.updateHash(),a.options.onMark&&a.options.onMark.call(a))}),o(document,"click",function(a){(a.target||a.srcElement)!=b&&t(b,"show")}),this.readHash())},delete_selections:function(b){for(var a=[],f=b.length;f--;){var l=b[f],c=r(this.selectable,l),d=j(c[c.length-1],"closewrap");d.parentNode.removeChild(d);this.removeTextSelection(c);a.push(this.ranges[l]); delete this.ranges[l]}},removeTextSelection:function(b){for(var a=b.length;a--;){for(var f=b[a],c=0;c<f.childNodes.length;c++)f.parentNode.insertBefore(f.childNodes[c],f);f.parentNode.removeChild(f)}},is_internal:function(b){for(;b.parentNode;){if(b==this.selectable)return!0;b=b.parentNode}return!1},_siblingNode:function(b,a,f,c,d){for(d=d||this.regexp;b.parentNode&&this.is_internal(b);){for(;b[a+"Sibling"];){for(b=b[a+"Sibling"];b.nodeType==1&&b.childNodes.length;)b=b[f+"Child"];if(b.nodeType==3&& b.data.match(d)!=null)return{_container:b,_offset:c*b.data.length}}b=b.parentNode}},prevNode:function(b,a){return this._siblingNode(b,"previous","last",1,a)},nextNode:function(b,a){return this._siblingNode(b,"next","first",0,a)},wordCount:function(b){var a=0;if(b.nodeType==3)(b=b.nodeValue.match(this.regexp))&&(a+=b.length);else if(b.childNodes&&b.childNodes.length){b=s(b);for(i=b.length;i--;)a+=b[i].nodeValue.match(this.regexp).length}return a},words:function(b,a,f){b.nodeType==1&&(b=k(b));a=b.data.substring(0, a).match(this.regexp);if(a!=null){if(f=="start"&&(a=a.length+1),f=="end")a=a.length}else a=1;for(var f=b,b=this.getNum(b),c=this.getFirstTextNode(b);f&&f!=c;){var f=this.prevNode(f,/.*/)._container,d=this.wordCount(f);a+=d}return b+":"+a},symbols:function(b){var a=0;if(b.nodeType==3)a=b.nodeValue.length;else if(b.childNodes&&b.childNodes.length)for(var b=s(b),f=b.length;f--;)a+=b[f].nodeValue.length;return a},updateHash:function(){var b=[];for(key in this.ranges)b.push(this.ranges[key]);this.options.location.hash= "sel="+b.join(";")},readHash:function(){var b=this.splittedHash();if(b){for(var a=0;a<b.length;a++)this.deserializeSelection(b[a]);this.updateHash();this.options.onHashRead&&this.options.onHashRead.call(this)}},splittedHash:function(){var b=this.options.location.hash;if(b&&(b=b.replace(/^#/,"").replace(/;+$/,""),/^sel\=(?:\d+\:\d+\,\d+\:\d+;)*\d+\:\d+\,\d+\:\d+$/.test(b)))return b=b.substring(4,b.length),b.split(";")},deserializeSelection:function(b){var a=window.getSelection();a.rangeCount>0&&a.removeAllRanges(); (range=this.deserializeRange(b))&&this.addSelection(range)},deserializeRange:function(b){var a=/^([^,]+),([^,]+)$/.exec(b),f=a[1].split(":"),a=a[2].split(":");if(parseInt(f[0],10)<parseInt(a[0],10)||f[0]==a[0]&&parseInt(f[1],10)<=parseInt(a[1],10))if(f=this.deserializePosition(f,"start"),a=this.deserializePosition(a,"end"),f.node&&a.node)return b=document.createRange(),b.setStart(f.node,f.offset),b.setEnd(a.node,a.offset),b;window.console&&typeof console.warn=="function"&&console.warn("Cannot deserialize range: "+ b)},deserializePosition:function(b,a){for(var f=this.blocks[parseInt(b[0],10)],c,d=0;f;){for(var e=RegExp(this.options.regexp,"ig");(myArray=e.exec(f.data))!=null;)if(d++,d==b[1]){if(a=="start")c=myArray.index;if(a=="end")c=e.lastIndex;return{node:f,offset:parseInt(c,10)}}(f=(f=this.nextNode(f,/.*/))?f._container:null)&&this.isFirstTextNode(f)&&(f=null)}return{node:null,offset:0}},serializeRange:function(b){var a=this.words(b.startContainer,b.startOffset,"start"),b=this.words(b.endContainer,b.endOffset, "end");return a+","+b},checkSelection:function(b){this.checkPosition(b,b.startOffset,b.startContainer,"start");this.checkPosition(b,b.endOffset,b.endContainer,"end");this.checkBrackets(b);this.checkSentence(b);return b},checkPosition:function(b,a,f,c){function e(b){return b.match(m.regexp)!=null}function g(b){return b.match(m.regexp)==null}function j(b,a,f){for(;a>0&&f(b.data.charAt(a-1));)a--;return a}function w(b,a,f){for(;a<b.data.length&&f(b.data.charAt(a));)a++;return a}var m=this;if(c=="start"){if(f.nodeType== 1&&d(f.textContent||f.innerText)!=""){if(b.startContainer.nodeType==1)for(f=b.startContainer.childNodes[b.startOffset];f.nodeType!=3;)f=f.nextSibling;else f=k(f);a=0}if(f.nodeType!=3||f.data.substring(a).match(this.regexp)==null)a=this.nextNode(f),f=a._container,a=a._offset;a=w(f,a,g);a=j(f,a,e);b.setStart(f,a)}if(c=="end"){if(f.nodeType==1&&d(f.textContent||f.innerText)!=""&&a!=0){for(f=b.endContainer.childNodes[b.endOffset-1];f.nodeType!=3;)f=f.previousSibling;a=f.data.length}if(f.nodeType!=3|| f.data.substring(0,a).match(this.regexp)==null)a=this.prevNode(f),f=a._container,a=a._offset;a=j(f,a,g);a=w(f,a,e);b.setEnd(f,a)}},checkBrackets:function(b){this._checkBrackets(b,"(",")",/\(|\)/g,/\(x*\)/g);this._checkBrackets(b,"\u00ab","\u00bb",/\\u00ab|\\u00bb/g,/\u00abx*\u00bb/g)},_checkBrackets:function(b,a,f,c,d){var e=b.toString();if(c=e.match(c)){for(var c=c.join(""),g=c.length+1;c.length<g;)g=c.length,c=c.replace(d,"x");c.charAt(c.length-1)==f&&e.charAt(e.length-1)==f&&(b.endOffset==1?(f= this.prevNode(b.endContainer),b.setEnd(f.container,f.offset)):b.setEnd(b.endContainer,b.endOffset-1));c.charAt(0)==a&&e.charAt(0)==a&&(b.startOffset==b.startContainer.data.length?(f=this.nextNode(b.endContainer),b.setStart(f.container,f.offset)):b.setStart(b.startContainer,b.startOffset+1))}},checkSentence:function(b){function a(){b.setEnd(f._container,f._offset+1)}if(b.endOffset==b.endContainer.data.length){var f=this.nextNode(b.endContainer,/.*/);if(!f)return;var c=f._container.data.charAt(0)}else f= {_container:b.endContainer,_offset:b.endOffset},c=b.endContainer.data.charAt(b.endOffset);if(c.match(/\.|\?|\!/)){c=b.toString();if(c.match(/(\.|\?|\!)\s+[A-Z\u0410-\u042f\u0401]/))return a();if(b.startOffset==0&&b.startContainer.previousSibling&&b.startContainer.previousSibling.nodeType==1&&b.startContainer.previousSibling.className=="selection_index")return a();for(var e,g=b.getElementIterator();e=g();)if(e.nodeType==1&&e.className=="selection_index")return a();if(c.charAt(0).match(/[A-Z\u0410-\u042f\u0401]/)){c= b.startContainer.data.substring(0,b.startOffset);if(!c.match(/\S/))c=this.prevNode(b.startContainer,/\W*/)._container.data;c=d(c);if(c.charAt(c.length-1).match(/(\.|\?|\!)/))return a()}}},mergeSelections:function(b){var a=[],f=b.getElementIterator(),c=f(),d=c,g=e(c,"user_selection_true");g&&(g=/(num\d+)(?:$| )/.exec(g.className)[1],b.setStart(k(j(this.selectable,g)),0),a.push(g));for(;c;)c.nodeType==1&&m("user_selection_true").test(c.className)&&(d=/(num\d+)(?:$|)/.exec(c.className)[0],v(d,a)==-1&& a.push(d)),d=c,c=f();if(d=e(d,"user_selection_true")){var d=/(num\d+)(?:$| )/.exec(d.className)[1],n;(f=r(this.selectable,d))&&(n=f[f.length-1]);n=s(n);n=n[n.length-1];b.setEnd(n,n.length)}if(a.length)n=b.startContainer,f=b.startOffset,c=b.endContainer,d=b.endOffset,this.delete_selections(a),b.setStart(n,f),b.setEnd(c,d);return b},addSelection:function(b){var b=b||this.getFirstRange(),b=this.checkSelection(b),b=this.mergeSelections(b),a="num"+this.counter;this.ranges[a]=this.serializeRange(b);b.wrapSelection(a+ " user_selection_true");this.addSelectionEvents(a)},addSelectionEvents:function(b){for(var a=!1,c=this,d=r(this.selectable,b),e=d.length;e--;)o(d[e],"mouseover",function(){for(var b=d.length;b--;)u(d[b],"hover");window.clearTimeout(a)}),o(d[e],"mouseout",function(b){for(b=b.relatedTarget;b&&b.parentNode&&b.className!=this.className;)b=b.parentNode;if(!b||b.className!=this.className)a=window.setTimeout(function(){for(var b=d.length;b--;)t(d[b],"hover")},2E3)});e=document.createElement("a");e.className= "txtsel_close";e.href="#";var g=document.createElement("span");g.className="closewrap";g.appendChild(e);o(e,"click",function(a){a.preventDefault?a.preventDefault():a.returnValue=!1;c.delete_selections([b]);c.updateHash();c.options.onUnmark&&c.options.onUnmark.call(c)});d[d.length-1].appendChild(g);this.counter++;window.getSelection().removeAllRanges()},getFirstRange:function(){var b=window.getSelection();return b.rangeCount?b.getRangeAt(0):null},enumerateElements:function(){function b(d){for(var d= d.childNodes,e=!1,g=!1,j=0;j<d.length;++j){var k=d.item(j),m=k.nodeType;if(m!=3||k.nodeValue.match(c.regexp))if(m==3){if(!g)a++,e=document.createElement("span"),e.id="selection_index"+a,e.className="selection_index",k.parentNode.insertBefore(e,k),j++,c.blocks[a]=k,e=g=!0}else m==1&&!c.is_ignored(k)&&(c.options.is_block(k)?(k=b(k),e=e||k,g=!1):g||(g=b(k),e=e||g))}return e}var a=0,c=this;b(this.selectable)},isFirstTextNode:function(b){for(var b=[b.previousSibling,b.parentNode.previousSibling],a=b.length;a--;)if(b[a]&& b[a].nodeType==1&&b[a].className=="selection_index")return!0;return!1},getFirstTextNode:function(b){if(b&&(b=document.getElementById("selection_index"+b)))return b.nextSibling.nodeType==1?b.nextSibling.childNodes[0]:b.nextSibling},getNum:function(b){for(;b.parentNode;){for(;b.previousSibling;){for(b=b.previousSibling;b.nodeType==1&&b.childNodes.length;)b=b.lastChild;if(b.nodeType==1&&b.className=="selection_index")return b.id.replace("selection_index","")}b=b.parentNode}},is_ignored:function(b){return this.options.ignored&& this.options.ignored(b)},range_is_selectable:function(){var b,a,c,d=!0,g=this.getFirstRange();if(!g)return!1;for(g=g.getElementIterator();b=g();)if(b.nodeType==3&&b.data.match(this.regexp)!=null&&(a=a||b,c=b),b=d&&b.nodeType==3?b.parentNode:b,d=!1,b.nodeType==1){for(;b!=this.selectable&&b.parentNode;){if(this.is_ignored(b))return!1;b=b.parentNode}if(b!=this.selectable)return!1}a=e(a,"user_selection_true");c=e(c,"user_selection_true");return a&&c?(d=/(?:^| )(num\d+)(?:$| )/,d.exec(a.className)[1]!= d.exec(c.className)[1]):!0}};var q=window.Range||document.createRange().constructor;q.prototype.splitBoundaries=function(){var a=this.startContainer,c=this.startOffset,d=this.endContainer,e=this.endOffset,g=a===d;d.nodeType==3&&e<d.length&&d.splitText(e);a.nodeType==3&&c>0&&(a=a.splitText(c),g&&(e-=c,d=a),c=0);this.setStart(a,c);this.setEnd(d,e)};q.prototype.getTextNodes=function(){for(var a=this.getElementIterator(),c=[],d;d=a();)d.nodeType==3&&c.push(d);return c};q.prototype.getElementIterator= function(){return g(null,this.startContainer,this.endContainer)};q.prototype.wrapSelection=function(a){this.splitBoundaries();for(var c=this.getTextNodes(),d=c.length;d--;){var e=document.createElement("span");e.className=a;c[d].parentNode.insertBefore(e,c[d]);e.appendChild(c[d])}};window.MaSha=p;if(window.jQuery)jQuery.fn.masha=function(b){b=b||{};b=a({selectable:this[0]},b);return new p(b)}})(); $.TextSelectorMessage=function(){function g(){$.browser.msie?a.animate({top:"-57px"},500,"easeInQuint",function(){a.removeClass("show")}):a.animate({top:"-57px",opacity:0},500,"easeInQuint",function(){a.removeClass("show")});return!1}var a=$("#upmsg-selectable"),d;if(!(window.localStorage?localStorage.selectable_warning:$.cookie("selectable-warning")))a.addClass("show"),$.browser.msie?a.animate({top:"0px"},{duration:1E3,easing:"easeOutQuint"}):a.animate({top:"0px",opacity:"1"},{duration:1E3,easing:"easeOutQuint"}), clearTimeout(d),d=setTimeout(g,1E4),a.find(".upmsg_closebtn").click(function(){g();window.localStorage?localStorage.selectable_warning="true":$.cookie("selectable-warning","true");clearTimeout(d);return!1})};jQuery.easing.jswing=jQuery.easing.swing; jQuery.extend(jQuery.easing,{def:"easeOutQuad",swing:function(g,a,d,c,e){return jQuery.easing[jQuery.easing.def](g,a,d,c,e)},easeInQuad:function(g,a,d,c,e){return c*(a/=e)*a+d},easeOutQuad:function(g,a,d,c,e){return-c*(a/=e)*(a-2)+d},easeInOutQuad:function(g,a,d,c,e){return(a/=e/2)<1?c/2*a*a+d:-c/2*(--a*(a-2)-1)+d},easeInCubic:function(g,a,d,c,e){return c*(a/=e)*a*a+d},easeOutCubic:function(g,a,d,c,e){return c*((a=a/e-1)*a*a+1)+d},easeInOutCubic:function(g,a,d,c,e){return(a/=e/2)<1?c/2*a*a*a+d:c/ 2*((a-=2)*a*a+2)+d},easeInQuart:function(g,a,d,c,e){return c*(a/=e)*a*a*a+d},easeOutQuart:function(g,a,d,c,e){return-c*((a=a/e-1)*a*a*a-1)+d},easeInOutQuart:function(g,a,d,c,e){return(a/=e/2)<1?c/2*a*a*a*a+d:-c/2*((a-=2)*a*a*a-2)+d},easeInQuint:function(g,a,d,c,e){return c*(a/=e)*a*a*a*a+d},easeOutQuint:function(g,a,d,c,e){return c*((a=a/e-1)*a*a*a*a+1)+d},easeInOutQuint:function(g,a,d,c,e){return(a/=e/2)<1?c/2*a*a*a*a*a+d:c/2*((a-=2)*a*a*a*a+2)+d},easeInSine:function(g,a,d,c,e){return-c*Math.cos(a/ e*(Math.PI/2))+c+d},easeOutSine:function(g,a,d,c,e){return c*Math.sin(a/e*(Math.PI/2))+d},easeInOutSine:function(g,a,d,c,e){return-c/2*(Math.cos(Math.PI*a/e)-1)+d},easeInExpo:function(g,a,d,c,e){return a==0?d:c*Math.pow(2,10*(a/e-1))+d},easeOutExpo:function(g,a,d,c,e){return a==e?d+c:c*(-Math.pow(2,-10*a/e)+1)+d},easeInOutExpo:function(g,a,d,c,e){return a==0?d:a==e?d+c:(a/=e/2)<1?c/2*Math.pow(2,10*(a-1))+d:c/2*(-Math.pow(2,-10*--a)+2)+d},easeInCirc:function(g,a,d,c,e){return-c*(Math.sqrt(1-(a/=e)* a)-1)+d},easeOutCirc:function(g,a,d,c,e){return c*Math.sqrt(1-(a=a/e-1)*a)+d},easeInOutCirc:function(g,a,d,c,e){return(a/=e/2)<1?-c/2*(Math.sqrt(1-a*a)-1)+d:c/2*(Math.sqrt(1-(a-=2)*a)+1)+d},easeInElastic:function(g,a,d,c,e){var j=0,k=c;if(a==0)return d;if((a/=e)==1)return d+c;j||(j=e*0.3);k<Math.abs(c)?(k=c,g=j/4):g=j/(2*Math.PI)*Math.asin(c/k);return-(k*Math.pow(2,10*(a-=1))*Math.sin((a*e-g)*2*Math.PI/j))+d},easeOutElastic:function(g,a,d,c,e){var j=0,k=c;if(a==0)return d;if((a/=e)==1)return d+c; j||(j=e*0.3);k<Math.abs(c)?(k=c,g=j/4):g=j/(2*Math.PI)*Math.asin(c/k);return k*Math.pow(2,-10*a)*Math.sin((a*e-g)*2*Math.PI/j)+c+d},easeInOutElastic:function(g,a,d,c,e){var j=0,k=c;if(a==0)return d;if((a/=e/2)==2)return d+c;j||(j=e*0.3*1.5);k<Math.abs(c)?(k=c,g=j/4):g=j/(2*Math.PI)*Math.asin(c/k);return a<1?-0.5*k*Math.pow(2,10*(a-=1))*Math.sin((a*e-g)*2*Math.PI/j)+d:k*Math.pow(2,-10*(a-=1))*Math.sin((a*e-g)*2*Math.PI/j)*0.5+c+d},easeInBack:function(g,a,d,c,e,j){j==void 0&&(j=1.70158);return c*(a/= e)*a*((j+1)*a-j)+d},easeOutBack:function(g,a,d,c,e,j){j==void 0&&(j=1.70158);return c*((a=a/e-1)*a*((j+1)*a+j)+1)+d},easeInOutBack:function(g,a,d,c,e,j){j==void 0&&(j=1.70158);return(a/=e/2)<1?c/2*a*a*(((j*=1.525)+1)*a-j)+d:c/2*((a-=2)*a*(((j*=1.525)+1)*a+j)+2)+d},easeInBounce:function(g,a,d,c,e){return c-jQuery.easing.easeOutBounce(g,e-a,0,c,e)+d},easeOutBounce:function(g,a,d,c,e){return(a/=e)<1/2.75?c*7.5625*a*a+d:a<2/2.75?c*(7.5625*(a-=1.5/2.75)*a+0.75)+d:a<2.5/2.75?c*(7.5625*(a-=2.25/2.75)*a+ 0.9375)+d:c*(7.5625*(a-=2.625/2.75)*a+0.984375)+d},easeInOutBounce:function(g,a,d,c,e){return a<e/2?jQuery.easing.easeInBounce(g,a*2,0,c,e)*0.5+d:jQuery.easing.easeOutBounce(g,a*2-e,0,c,e)*0.5+c*0.5+d}});
