var base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(input){var output="",chr1,chr2,chr3,enc1,enc2,enc3,enc4,i=0;input=base64._utf8_encode(input);while(i<input.length){chr1=input.charCodeAt(i++);chr2=input.charCodeAt(i++);chr3=input.charCodeAt(i++);enc1=chr1>>2;enc2=((chr1&3)<<4)|(chr2>>4);enc3=((chr2&15)<<2)|(chr3>>6);enc4=chr3&63;if(isNaN(chr2)){enc3=enc4=64}else if(isNaN(chr3))enc4=64;output=output+this._keyStr.charAt(enc1)+this._keyStr.charAt(enc2)+this._keyStr.charAt(enc3)+this._keyStr.charAt(enc4)};return output},decode:function(input){var output="",chr1,chr2,chr3,enc1,enc2,enc3,enc4,i=0;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(i<input.length){enc1=this._keyStr.indexOf(input.charAt(i++));enc2=this._keyStr.indexOf(input.charAt(i++));enc3=this._keyStr.indexOf(input.charAt(i++));enc4=this._keyStr.indexOf(input.charAt(i++));chr1=(enc1<<2)|(enc2>>4);chr2=((enc2&15)<<4)|(enc3>>2);chr3=((enc3&3)<<6)|enc4;output=output+String.fromCharCode(chr1);if(enc3!=64)output=output+String.fromCharCode(chr2);if(enc4!=64)output=output+String.fromCharCode(chr3)};output=base64._utf8_decode(output);return output},_utf8_encode:function(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128){utftext+=String.fromCharCode(c)}else if((c>127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128)}else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128)}};return utftext},_utf8_decode:function(utftext){var string="",i=0,c=c1=c2=0;while(i<utftext.length){c=utftext.charCodeAt(i);if(c<128){string+=String.fromCharCode(c);i++}else if((c>191)&&(c<224)){c2=utftext.charCodeAt(i+1);string+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2}else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3}};return string}};(function(jQuery){jQuery.fn.extend({elastic:function(){var mimics=['paddingTop','paddingRight','paddingBottom','paddingLeft','fontSize','lineHeight','fontFamily','width','fontWeight','border-top-width','border-right-width','border-bottom-width','border-left-width','borderTopStyle','borderTopColor','borderRightStyle','borderRightColor','borderBottomStyle','borderBottomColor','borderLeftStyle','borderLeftColor'];return this.each(function(){if(this.type!=='textarea')return false;var $textarea=jQuery(this),$twin=jQuery('<div />').css({position:'absolute',display:'none','word-wrap':'break-word'}),lineHeight=parseInt($textarea.css('line-height'),10)||parseInt($textarea.css('font-size'),'10'),minheight=parseInt($textarea.css('height'),10)||lineHeight*3,maxheight=parseInt($textarea.css('max-height'),10)||Number.MAX_VALUE,goalheight=0;if(maxheight<0)maxheight=Number.MAX_VALUE;$twin.appendTo($textarea.parent());var i=mimics.length;while(i--)$twin.css(mimics[i].toString(),$textarea.css(mimics[i].toString()))
function setTwinWidth(){curatedWidth=Math.floor(parseInt($textarea.width(),10));if($twin.width()!==curatedWidth){$twin.css({width:curatedWidth+'px'});update(true)}}
function setHeightAndOverflow(height,overflow){var curratedHeight=Math.floor(parseInt(height,10));if($textarea.height()!==curratedHeight){$textarea.css({height:curratedHeight+'px',overflow:overflow});$textarea.trigger('resize')}}
function update(forced){var textareaContent=$textarea.val().replace(/&/g,'&amp;').replace(/ {2}/g,'&nbsp;').replace(/<|>/g,'&gt;').replace(/\n/g,'<br />'),twinContent=$twin.html().replace(/<br>/ig,'<br />');if(forced||textareaContent+'&nbsp;'!==twinContent){$twin.html(textareaContent+'&nbsp;');if(Math.abs($twin.height()+lineHeight-$textarea.height())>3){var goalheight=$twin.height()+lineHeight;if(goalheight>=maxheight){setHeightAndOverflow(maxheight,'auto')}else if(goalheight<=minheight){setHeightAndOverflow(minheight,'hidden')}else setHeightAndOverflow(goalheight,'hidden')}}};$textarea.css({overflow:'hidden'});$textarea.bind('keyup change cut paste',function(){update()});$(window).bind('resize',setTwinWidth);$textarea.bind('resize',setTwinWidth);$textarea.bind('update',update);$textarea.bind('blur',function(){if($twin.height()<maxheight)if($twin.height()>minheight){$textarea.height($twin.height())}else $textarea.height(minheight)});$textarea.bind('input paste',function(e){setTimeout(update,250)});update()})}})})(jQuery);(function(){var cache={};this.tmpl=function tmpl(str,data){var fn=!/\W/.test(str)?cache[str]=cache[str]||tmpl(document.getElementById(str).innerHTML):new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+str.replace(/[\r\t\n]/g," ").split("<%").join("\t").replace(/((^|%>)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return data?fn(data):fn}})();jQuery.fn.autoLink=function(){return this.each(function(){var re=/((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g;$(this).html($(this).html().replace(re,'<a href="$1" target="_blank">$1</a> '))})};jQuery.fn.autoTwitterAccount=function(){return this.each(function(){var re=/@(\w+)/gi;$(this).html($(this).html().replace(re,'<a href="http://twitter.com/$1" target="_blank">@$1</a> '))})};jQuery.fn.autoTwitterHashTag=function(){return this.each(function(){var re=/(?:^| )[\#]+([\w\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff\u0600-\u06ff]+)/gi;$(this).html($(this).html().replace(re,'<a href="http://twitter.com/search?q=$1" target="_blank">#$1</a> '))})};var link={decode:function(){$('a[data-encodedlink]').each(function(){var encodedLinkValue=$(this).attr("data-encodedlink");if(encodedLinkValue){$(this).attr("href",base64.decode(String(encodedLinkValue)));$(this).removeAttr("data-encodedlink")}})},autolink:function(){return this.each(function(){var re=/((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g;$(this).html($(this).html().replace(re,'<a href="$1">$1</a> '))})}},admin={create:function(){if($('#primary.admin-add-article').length)$('#article-form textarea').elastic()}},twitter={limit:5,create:function(){if($('#tags-twitter').length&&Exprimeo.tags.length)twitter.displayTweetsWithTag()},displayTweetsWithTag:function(usedTag){var numberTags=parseInt(Exprimeo.tags.length);if(numberTags){var tag=Exprimeo.tags[Math.floor(Math.random()*numberTags)];if(numberTags==1&&usedTag==tag){return}else $.getJSON('http://search.twitter.com/search.json?q='+encodeURI(tag)+'&callback=?&lang=fr',function(data){var tweets=data.results;if(tweets.length){var widget='<h2>Tweets "'+tag+'" :</h2><ul class="stream-items">',i=0;while(i<twitter.limit&&i<tweets.length){var tweet=tweets[i];widget+='<li class="stream-item"><div class="tweet-image"><img src="'+tweet.profile_image_url+'" /></div><div class="tweet-content"><div class="tweet-row"><span class="tweet-user-name"><a href="http://twitter.com/'+tweet.from_user+'" target="_blank">'+tweet.from_user+'</a></span></div><div class="tweet-row">'+tweet.text+'</div></div></li>';i++};widget+='</ul>';var twitterTags=$('#tags-twitter');twitterTags.prepend(widget);twitterTags.autoLink();twitterTags.autoTwitterAccount();twitterTags.autoTwitterHashTag()}else twitter.displayTweetsWithTag(tag)})}}};$('html').addClass('js');$(document).ready(function(){link.decode();twitter.create();admin.create()})
