var typeselect={browser:{'mac':navigator.platform.indexOf("Mac")>=0?true:false},fontproperties:{'height':'','overrideSize':'','color':'','family':'','width':'','weight':'','style':''},selectionVars:{'direction':-1,'selection':''},myTextRender:function(a,b){var c=0;spanWrapper=document.getElementById("fake");if(spanWrapper.hasChildNodes()){spanWrapper.removeChild(spanWrapper.firstChild)}$(spanWrapper).css(b);spanWrapper.appendChild(document.createTextNode(a));if(_typeface_js){if(spanWrapper.hasChildNodes()){var d=spanWrapper.childNodes[0];c=_typeface_js.getRenderedText(d)}if(c){this.fontproperties.height=c.span.childNodes[0].height;this.fontproperties.width=c.span.childNodes[0].width;var e=c.span.childNodes[0].toDataURL();if(typeof e=="undefined"){return c.span}else{return{png:e,fontface:c.fontface,style:c.styleObj}}}}return c},replaceText:function(a){var b={"font-family":$(a).css("font-family"),"font-size":$(a).css("font-size"),"font-weight":$(a).css("font-weight"),"font-style":$(a).css("font-style"),"font-stretch":$(a).css("font-stretch"),"text-decoration":$(a).css("text-decoration"),"text-transform":$(a).css("text-transform"),"color":$(a).css("color"),"line-height":$(a).css("line-height"),"letter-spacing":($(a).css("letter-spacing")=="normal"?"0":$(a).css("letter-spacing")),"word-spacing":($(a).css("word-spacing")=="normal"?"0":$(a).css("word-spacing"))};var c=a.text().replace(/^\s+|\s+$/g,"").split(/\s/);a.empty();var d=$("<span></span>");a.append(d);d=a.find("span:last");a.empty();var e=" ";var f=typeselect.myTextRender(e,b);var g=f.fontface;var h=f.style;var k=typeselect.fontproperties.width;var l=parseInt(b["letter-spacing"]);var m=parseInt(b["word-spacing"]);for(var i in c){var n=c[i]+" ";if(i==c.length-1){n=c[i]}var o=n.split('');var p=0;if(g.glyphs[o[0]].x_min<0){n=" "+n;p=k}var q=typeselect.myTextRender(n,b);var r=typeselect.fontproperties.width;var s=q.png;wordSpan=d.clone().appendTo(a);wordSpan.css({"background":"transparent url("+s+") no-repeat 0 50%","line-height":typeselect.fontproperties.height+"px","height":typeselect.fontproperties.height+"px","font-size":typeselect.fontproperties.height+"px"});for(var j in o){var t=$("<span></span>").append("<span>"+o[j]+"</span>");var u=Math.max(g.glyphs[o[j]].ha,g.glyphs[o[j]].x_max);var v=Math.min(g.glyphs[o[j]].ha,g.glyphs[o[j]].x_max);var w=u;if(o[j]==" "){w=_typeface_js.pixelsFromPoints(g,h,k,"horizontal")+m+130}if(h.fontStyle=="italic"){w=v}var x=_typeface_js.pixelsFromPoints(g,h,w+_typeface_js.pointsFromPixels(g,h,h.letterSpacing,'horizontal'),'horizontal');var y=_typeface_js.pixelsFromPoints(g,h,g.glyphs[o[j]].x_min);if(j==0&&g.glyphs[o[j]].x_min<0){x-=y}wordSpan.append(t);var z=_typeface_js.pixelsFromPoints(g,h,g.glyphs[o[j]].x_max,"horizontal");var A=parseInt(t.width());var B=x-A+p+l;p=0;if(j==o.length-2&&o[j]!=" "&&z>x){B+=z-x}t.css({"letter-spacing":B+"px"})}}if(a.get(0).tagName=="A"){var C=$("<span></span>");hoverColor=C.addClass('hilite').css('background-color');C.remove();a.find("span").css("cursor","pointer");a.hover(function(){$(this).css({"background-color":hoverColor})},function(){$(this).css({"background-color":"transparent"})})}},resetHighlights:function(){$(".hilite").each(function(){c=$(this).get(0).firstChild;if(!typeselect.selectionVars.selection.containsNode(c,false)||c!=selectionVars.selection.focusNode){$(this).removeClass('hilite')}})},recurseHighlights:function(c,a){if(typeselect.selectionVars.selection.containsNode(c,false)&&c.parentNode.nodeName.toLowerCase()=="span"){$(c).parent().parent().addClass("hilite");return typeselect.recurseHighlights(typeselect.incrementNode(c,typeselect.selectionVars.direction))}else{$(c).parent().parent().removeClass("hilite");return 0}},setHighlights:function(b){typeselect.selectionVars.selection=window.getSelection();var c=typeselect.selectionVars.selection.toString();var a=typeselect.selectionVars.selection.anchorNode;var f=typeselect.selectionVars.selection.focusNode;if(c!=""){if(b=="dblclick"){f=typeselect.incrementNode(f,-1);if($.browser.mozilla){if(a.parentNode.parentNode.previousSibling==null){f=typeselect.incrementNode(f,-1)}}}if((typeselect.browser.mac||$.browser.mozilla)&&a==f){a=a.firstChild.firstChild.firstChild.firstChild;f=f.lastChild.lastChild.lastChild.lastChild}typeselect.selectionVars.direction=-1;typeselect.recurseHighlights(f);typeselect.selectionVars.direction=1;typeselect.recurseHighlights(f);typeselect.selectionVars.direction=1;typeselect.recurseHighlights(a);typeselect.selectionVars.direction=-1;typeselect.recurseHighlights(a)}},incrementNode:function(a,b){b=!b?0:b;if(b<=0){ns=a.parentNode.parentNode.previousSibling;if(ns==null)return a.parentNode.parentNode.parentNode.previousSibling.lastChild.lastChild.lastChild;return a.parentNode.parentNode.previousSibling.lastChild.lastChild}else{ns=a.parentNode.parentNode.nextSibling;if(ns==null)return a.parentNode.parentNode.parentNode.nextSibling.firstChild.firstChild.firstChild;return a.parentNode.parentNode.nextSibling.firstChild.firstChild}},init:function(){$("<span id='fake'></span>").css("visibility","hidden").appendTo("body");var b=$('.select');if(_typeface_js.vectorBackend=="vml"){_typeface_js.renderDocument()}else{b.each(function(){typeselect.replaceText($(this))});$(document).keydown(function(e){var a=e.charCode||e.keyCode||0;if(((a==97||a==65)&&e.metaKey)&&!e.ctrlKey&&typeselect.browser.mac){b.find("span span").addClass("hilite");return false}else if(((a==97||a==65)&&e.ctrlKey)&&!typeselect.browser.mac){b.find("span span").addClass("hilite");return false}return true}).bind('tripleclick',function(a){typeselect.setHighlights()}).dblclick(function(){typeselect.setHighlights("dblclick")}).mousemove(function(e){typeselect.setHighlights()}).mousedown(function(){$(".hilite").removeClass("hilite")}).mouseup(function(){typeselect.setHighlights()})}}};jQuery.event.special.tripleclick={setup:function(a,b){var c=this,$elem=jQuery(c);$elem.bind('click',jQuery.event.special.tripleclick.handler)},teardown:function(a){var b=this,$elem=jQuery(b);$elem.unbind('click',jQuery.event.special.tripleclick.handler)},handler:function(a){var b=this,$elem=jQuery(b),clicks=$elem.data('clicks')||0;clicks+=1;if(clicks===3){clicks=0;a.type="tripleclick";jQuery.event.handle.apply(this,arguments)}$elem.data('clicks',clicks)}};window.onload=function(){if(!window.opera){typeselect.init()}}
