if(window.Saki){Saki.Library.Require(["sek","0.0.x"]);function main(){}}function LoadLibrary(a){if(!a){a=window}a.SLK=window.SLK}var SLK={};SLK.EllipsizeMode={NONE:"none",START:"start",MIDDLE:"middle",END:"end"};SLK.WrapMode={NONE:"none",WORD:"word",CHAR:"char"};SLK.Text={_hit_count:0,_miss_count:0,_total:0,_s_widths:{},_c_widths:{},_element:null,GetCacheHitRatio:function(){return SLK.Text._hit_count/SLK.Text._total},GetMeasureCount:function(){return SLK.Text._total},GetCacheHits:function(){return SLK.Text._hit_count},GetCacheMisses:function(){return SLK.Text._miss_count}};SLK.TextLayout=function(b,a){this._regions=[];this.Describe=function(){var c="";for(var d=0;d<this._regions.length;d++){c+="Region: "+this._regions[d].GetText()+"\n";c+=this._regions[d].Describe()}return c};this.GetText=function(){var c=[];for(var d=0;d<this._regions.length;d++){c.push(this._regions[d].GetText())}return c.join("")};this.GetMarkup=function(){var d=[];var c=[];for(var g=0;g<this._regions.length;g++){var l=this._regions[g];if(l.GetText().indexOf("\n")==-1){c.push(l.GetMarkup())}else{var k=l.GetText().split("\n");for(var f=0;f<k.length;f++){var h=k[f];if(h==""){d.push(c.join(""));c=[];continue}var e=["<span ",l.GetStyle().GetStyleForMarkup(),">",SEK.String.EscapeHtml(h),"</span>"].join("");c.push(e);if(f!=(k.length-1)){d.push(c.join(""));c=[]}}}}d.push(c.join(""));return d.join("<br/>")};this.SetMarkup=function(d,c){delete this._regions;var f=new SEK.Element.Span();f.SetContent(d);f.SetStyle("position","absolute");f.SetStyle("visibility","hidden");if(c){c.SetStyleOnElement(f)}SEK.Doc.Body().Add(f);this._regions=this._LinearizeRegions(f.dom_elmt);f.Destroy();delete f};this.Measure=function(){var l=0;var g=0;var c=0;var k=0;for(var f=0;f<this._regions.length;f++){if(this._regions[f].GetText().indexOf("\n")==-1){var m=this._regions[f].Measure();c+=m.w;k=Math.max(k,m.h)}else{var d=this._regions[f].GetText().split("\n");for(var e=0;e<d.length;e++){var n=d[e];if(n==""){n="\n"}var m=SLK.Text.Measure(n,this._regions[f].GetStyle());c+=m.w;k=Math.max(k,m.h);if(e!=(d.length-1)){l=Math.max(l,c);g+=k;c=0;k=0}}}}l=Math.max(l,c);g+=k;return{w:l,h:g}};this.GetMarkupEllipsized=function(c,d){if(d==SLK.EllipsizeMode.END){return this.GetMarkupEllipsizedEnd(c)}return this.GetMarkupEllipsizedEnd(c)};this.GetMarkupEllipsizedEnd=function(e){if(isNaN(e)||e===undefined){return this.GetMarkup()}var d=0;var o=[];var p=[];for(var h=0;h<this._regions.length;h++){if(this._regions[h].GetText().indexOf("\n")==-1){var k=this._regions[h].Measure();if(d+k.w<e){d+=k.w;o.push(this._regions[h].GetMarkup())}else{var c=e-d;if(c>0){o.push(this._regions[h].GetMarkupEllipsized(c,SLK.EllipsizeMode.END));d+=c}}}else{var g=this._regions[h].GetText().split("\n");for(var f=0;f<g.length;f++){var n=g[f];if(n==""){p.push(o.join(""));o=[];d=0;continue}var k=SLK.Text.Measure(n,this._regions[h].GetStyle());if(d+k.w<e){var m=["<span ",this._regions[h].GetStyle().GetStyleForMarkup(),">",SEK.String.EscapeHtml(n),"</span>"].join("");o.push(m);d+=k.w}else{var c=e-d;if(c>0){var l=SLK.Text.Ellipsize(c,n,this._regions[h].GetStyle(),SLK.EllipsizeMode.END);var m=["<span ",this._regions[h].GetStyle().GetStyleForMarkup(),">",SEK.String.EscapeHtml(l),"</span>"].join("");o.push(m);d+=c}}if(f!=(g.length-1)){p.push(o.join(""));o=[];d=0}}}}p.push(o.join(""));return p.join("<br/>")};this.GetMarkupWrapped=function(d,g){if(!d||isNaN(d)){return this.GetMarkup()}var e="";var c=0;for(var f=0;f<this._regions.length;f++){var l=this._regions[f];var k=l.Measure();if(c+k.w<d){e+=l.GetMarkup();c+=k.w}else{var h={};var j=l.GetMarkupWrapped(d,g,c,h);c=h.w;e+=j}}return e};this._LinearizeRegions=function(g){var h=[];for(var c in g.childNodes){if(g.childNodes[c].nodeType==3){var f=new SLK.TextRegion(g.childNodes[c],g);h.push(f)}else{if(g.childNodes[c].nodeType==1){var d=this._LinearizeRegions(g.childNodes[c]);h=h.concat(d)}}}return h};this.SetMarkup(b,a)};SLK.TextRegion=function(b,a){this._text="";this._style;this._tags={};this.Describe=function(){var d="";var e=this._style.GetStyles();for(var c in e){if(e.hasOwnProperty(c)){d+="&nbsp;&nbsp;&nbsp;&nbsp;"+c+": "+e[c]+"<br/>"}}return d};this.GetText=function(){return this._text};this.GetMarkup=function(){return["<span ",this._style.GetStyleForMarkup(),">",SEK.String.EscapeHtml(this.GetText()),"</span>"].join("")};this.GetMarkupEllipsized=function(d,e){var c=SLK.Text.EllipsizeEnd(d,this.GetText(),this._style);return["<span ",this._style.GetStyleForMarkup(),">",SEK.String.EscapeHtml(c),"</span>"].join("")};this.GetMarkupWrapped=function(e,i,h,d){var c=SLK.Text.Wrap(e,this.GetText(),this.GetStyle(),i,h);if(d){var g=c.slice(c.lastIndexOf("\n"));var f=SLK.Text.Measure(g,this.GetStyle());d.w=f.w}return["<span ",this._style.GetStyleForMarkup(),">",SEK.String.EscapeHtml(c),"</span>"].join("")};this.GetStyle=function(){return this._style};this.Measure=function(){var c=SLK.Text.Measure(this.GetText(),this.GetStyle());return c};this._text=b.nodeValue;this._style=new SLK.TextStyle(a);if(SEK.UserAgent.IsGecko()){if(a.nodeName.toUpperCase()=="B"){this._style.SetStyle("font-weight","bold")}}};SLK.TextStyle=function(a){this._cached_hash=null;this._styles=null;this.Reset=function(){this._styles={};for(var b in SLK.TextStyle.style_defaults){this._styles[b]=SLK.TextStyle.style_defaults[b]}};this.Copy=function(){var c=new SLK.TextStyle();for(var b in this._styles){if(this._styles.hasOwnProperty(b)){c._styles[b]=this._styles[b]}}if(this._cached_hash){c._cached_hash=new String(this._cached_hash)}return c};this._FilterOperaFontFamily=function(b){b=b.replace(/["]/g,"");b=b.replace(/\[.*\]/g,"");b=b.replace(/\s/g,"");b=b.toLowerCase();return b};this.LoadFromElement=function(f){if(!f||typeof f!="object"){SEK.Log.Error("SLK::TextStyle::LoadFromElement - expected element of type object");return}var j=SEK.UserAgent.IsOpera();var g={};try{if(SEK.doc.defaultView&&SEK.doc.defaultView.getComputedStyle){var d=SEK.doc.defaultView.getComputedStyle(f,null);if(d){for(var c in SLK.TextStyle.style_properties){g[c]=d.getPropertyValue(c);if(j&&c=="font-family"){g[c]=this._FilterOperaFontFamily(g[c])}}}}else{if(f.currentStyle){for(var c in SLK.TextStyle.style_properties){var b=SLK.TextStyle.style_properties[c];var h=String(f.currentStyle[b]);if(h!="undefined"){g[c]=h}else{g[c]=this._styles[c]}}}}}catch(i){SEK.Log.Error("Excepted when loading Styles From element: %s",i)}for(var c in SLK.TextStyle.style_defaults){this._styles[c]=g[c]}return g};this.LoadFromStyles=function(c){for(var b in SLK.TextStyle.style_properties){this.SetStyle(b,c.GetStyleProperty(b))}};this.Hash=function(){if(this._cached_hash){return this._cached_hash}var c=[];for(var b in this._styles){c=c.concat(this._styles[b])}this._cached_hash=c.join("");return this._cached_hash};this.GetStyleForMarkup=function(){var c=['style="'];for(var b in this._styles){if(this._styles[b]&&this._styles[b].length>0){c=c.concat(b,":",this._styles[b],";")}}c=c.concat('"');return c.join("")};this.SetStyleOnElement=function(d){for(var c in this._styles){if(this._styles.hasOwnProperty(c)){if(d.SetStyleCSS){d.SetStyleCSS(c,this._styles[c])}else{var b=SLK.TextStyle.style_properties[c];d.style[b]=this._styles[c]}}}};this.SetStyle=function(b,c){this._styles[b]=c;this._cached_hash=null};this.GetStyle=function(b){return this._styles[b]};this.GetStyles=function(){return this._styles};this.Reset();if(a){this.LoadFromElement(a)}};SLK.TextStyle.style_defaults={"font-family":"","font-size":"","font-size-adjust":"","font-stretch":"","font-style":"","font-variant":"","font-weight":"",color:"",direction:"","line-height":"","letter-spacing":"","text-decoration":"","text-shadow":"","text-transform":"","unicode-bidi":"","word-spacing":""};SLK.TextStyle.style_properties={"font-family":"fontFamily","font-size":"fontSize","font-size-adjust":"fontSizeAdjust","font-stretch":"fontStretch","font-style":"fontStyle","font-variant":"fontVariant","font-weight":"fontWeight",color:"color",direction:"direction","line-height":"lineHeight","letter-spacing":"letterSpacing","text-decoration":"textDecoration","text-shadow":"textShadow","text-transform":"textTransform","unicode-bidi":"unicodeBidi","word-spacing":"wordSpacing"};SLK.Text.Ellipsize=function(a,d,b,c){if(c==SLK.EllipsizeMode.END){return SLK.Text.EllipsizeEnd(a,d,b)}return SLK.Text.EllipsizeEnd(a,d,b)};SLK.Text.EllipsizeEnd=function(m,k,a){var l=SLK.Text.Measure(k,a);if(l.w<m){return k}var g="...";var d=SLK.Text.Measure(g,a);if(d.w>m){g="..";d=SLK.Text.Measure(g,a);if(d.w>m){g=".";d=SLK.Text.Measure(g,a);if(d.w>m){return""}return g}return g}var b=0;var e="";for(var f=0;f<k.length;f++){var j=k.charAt(f);var h=SLK.Text.MeasureChar(j,a);if(b+h.w+d.w>m){return e+"..."}b+=h.w;e+=j}return e};SLK.Text._InitMeasure=function(){SLK.Text._element=new SEK.Element.Span();SLK.Text._element.SetStyle("display","none");SLK.Text._element.SetStyle("visibility","hidden");SEK.Doc.Body().Add(SLK.Text._element)};SLK.Text._NeedsBrokenLetterSpacingHack=function(a){return(SEK.UserAgent.IsExplorer())&&a.GetStyle("letter-spacing")!="normal"};SLK.Text.Measure=function(o,e){SLK.Text._total+=1;var q=e.Hash();if(q.length==0){q="default"}if(((q+o) in SLK.Text._s_widths)){SLK.Text._hit_count+=1;return{w:Number(SLK.Text._s_widths[(q+o)]["w"]),h:Number(SLK.Text._s_widths[(q+o)]["h"])}}SLK.Text._miss_count+=1;var a;if(SLK.Text._NeedsBrokenLetterSpacingHack(e)){var l=e.Copy();l.SetStyle("letter-spacing","normal");a=SLK.Text.MeasureChar("a",l);delete l}if(!SLK.Text._element){SLK.Text._InitMeasure()}if(!(q in SLK.Text._c_widths)){SLK.Text._c_widths[q]={}}var d=SLK.Text._c_widths[q];e.SetStyleOnElement(SLK.Text._element);SLK.Text._element.SetStyle("display","inline");var p=0;var b=0;var g=0;var n=0;for(var f=0;f<o.length;f++){var m=o.charAt(f);if(m=="\n"){if(b==0&&n==0){n=SLK.Text.Measure(" ",e).h}p=Math.max(p,b);g+=n;b=0;n=0;continue}if(m in d){b+=Number(d[m].w);n=Math.max(n,Number(d[m].h));continue}var k=m;switch(m){case"&":k="&amp;";break;case">":k="&gt;";break;case"<":k="&lt;";break;case" ":k="&nbsp;";break;default:break}if(SLK.Text._NeedsBrokenLetterSpacingHack(e)){k=k+"a"}SLK.Text._element.SetContent(k);var j=SLK.Text._element.GetSize();if(SLK.Text._NeedsBrokenLetterSpacingHack(e)){j.w-=a.w}d[m]={w:j.w,h:j.h};b+=j.w;n=Math.max(n,j.h)}p=Math.max(p,b);g+=n;SLK.Text._element.SetStyle("display","none");SLK.Text._s_widths[(q+o)]={w:p,h:g};return{w:p,h:g}};SLK.Text.MeasureChar=function(i,e){var d=e.Hash();if(d.length==0){d="default"}if(!(d in SLK.Text._c_widths)){SLK.Text._c_widths[d]={}}var b=SLK.Text._c_widths[d];if(i=="\n"){return{w:0,h:0}}if(i in b){return{w:Number(b[i].w),h:Number(b[i].h)}}var g;if(SLK.Text._NeedsBrokenLetterSpacingHack(e)){var h=e.Copy();h.SetStyle("letter-spacing","normal");g=SLK.Text.MeasureChar("a",h);delete h}if(!SLK.Text._element){SLK.Text._InitMeasure()}e.SetStyleOnElement(SLK.Text._element);SLK.Text._element.SetStyle("display","inline");var f=i;switch(i){case"&":f="&amp;";break;case">":f="&gt;";break;case"<":f="&lt;";break;case" ":f="&nbsp;";break;default:break}if(SLK.Text._NeedsBrokenLetterSpacingHack(e)){f=f+"a"}SLK.Text._element.SetContent(f);var a=SLK.Text._element.GetSize();if(SLK.Text._NeedsBrokenLetterSpacingHack(e)){a.w-=g.w}b[i]={w:a.w,h:a.h};SLK.Text._element.SetStyle("display","none");return{w:a.w,h:a.h}};SLK.Text.GetAverageCharSize=function(a){var b=SLK.Text.Measure("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",a);b.w=b.w/62;return b};SLK.Text.Wrap=function(a,e,c,d,b){if(d==SLK.WrapMode.WORD){return SLK.Text.WrapWord(a,e,c,b)}else{if(d==SLK.WrapMode.CHAR){return SLK.Text.WrapChar(a,e,c,b)}}return SLK.Text.WrapWord(a,e,c,b)};SLK.Text.WrapWord=function(p,n,b,k){var h=n.split(" ");var o=SLK.Text.MeasureChar(" ",b);var f="";var a=(k===undefined)?0:k;for(var g=0;g<h.length;g++){var d=h[g];var m=SLK.Text.Measure(d,b);if(g!=0){f+=" ";a+=o.w}if(a+m.w<p){f+=d;a+=m.w}else{if(m.w>p){var c=SLK.Text.WrapChar(p,d,b,a);if(a>0){f+="\n"}f+=c;var e=c.split("\n");var l=e[e.length-1];var j=SLK.Text.Measure(l,b);a=j.w}else{f+="\n";f+=d;a=m.w}}}return f};SLK.Text.WrapChar=function(n,m,b,h){var d=[];var a=(h===undefined)?0:h;for(var f=0;f<m.length;f++){var l=m.charAt(f);var k=SLK.Text.MeasureChar(l,b);if(k.w+a<n){a+=k.w}else{a=k.w;d.push(f)}}d.reverse();for(var e=0;e<d.length;e++){var g=d[e];m=m.slice(0,g)+"\n"+m.slice(g)}return m};