/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);


/**
 * Tweet
 *
 * http://tweet.seaofclouds.com/
 */
(function($){$.fn.tweet=function(o){var s=$.extend({username:null,list:null,favorites:false,query:null,avatar_size:null,count:3,fetch:null,retweets:true,intro_text:null,outro_text:null,join_text:null,auto_join_text_default:"i said,",auto_join_text_ed:"i",auto_join_text_ing:"i am",auto_join_text_reply:"i replied to",auto_join_text_url:"i was looking at",loading_text:null,refresh_interval:null,twitter_url:"twitter.com",twitter_api_url:"api.twitter.com",twitter_search_url:"search.twitter.com",template:"{avatar}{time}{join}{text}",comparator:function(a,b){return b["tweet_time"]-a["tweet_time"]},filter:function(a){return true}},o);$.fn.extend({linkUrl:function(){var c=[];var d=/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi;this.each(function(){c.push(this.replace(d,function(a){var b=(/^[a-z]+:/i).test(a)?a:"http://"+a;return"<a href=\""+b+"\">"+a+"</a>"}))});return $(c)},linkUser:function(){var a=[];var b=/[\@]+(\w+)/gi;this.each(function(){a.push(this.replace(b,"@<a href=\"http://"+s.twitter_url+"/$1\">$1</a>"))});return $(a)},linkHash:function(){var a=[];var b=/(?:^| )[\#]+([\w\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff\u0600-\u06ff]+)/gi;var c=(s.username&&s.username.length==1)?'&from='+s.username.join("%2BOR%2B"):'';this.each(function(){a.push(this.replace(b,' <a href="http://'+s.twitter_search_url+'/search?q=&tag=$1&lang=all'+c+'">#$1</a>'))});return $(a)},capAwesome:function(){var a=[];this.each(function(){a.push(this.replace(/\b(awesome)\b/gi,'<span class="awesome">$1</span>'))});return $(a)},capEpic:function(){var a=[];this.each(function(){a.push(this.replace(/\b(epic)\b/gi,'<span class="epic">$1</span>'))});return $(a)},makeHeart:function(){var a=[];this.each(function(){a.push(this.replace(/(&lt;)+[3]/gi,"<tt class='heart'>&#x2665;</tt>"))});return $(a)}});function parse_date(a){return Date.parse(a.replace(/^([a-z]{3})( [a-z]{3} \d\d?)(.*)( \d{4})$/i,'$1,$2$4$3'))}function relative_time(a){var b=(arguments.length>1)?arguments[1]:new Date();var c=parseInt((b.getTime()-a)/1000,10);var r='';if(c<60){r=c+' seconds ago'}else if(c<120){r='a minute ago'}else if(c<(45*60)){r=(parseInt(c/60,10)).toString()+' minutes ago'}else if(c<(2*60*60)){r='an hour ago'}else if(c<(24*60*60)){r=''+(parseInt(c/3600,10)).toString()+' hours ago'}else if(c<(48*60*60)){r='a day ago'}else{r=(parseInt(c/86400,10)).toString()+' days ago'}return'about '+r}function build_url(){var a=('https:'==document.location.protocol?'https:':'http:');var b=(s.fetch===null)?s.count:s.fetch;if(s.list){return a+"//"+s.twitter_api_url+"/1/"+s.username[0]+"/lists/"+s.list+"/statuses.json?per_page="+b+"&callback=?"}else if(s.favorites){return a+"//"+s.twitter_api_url+"/favorites/"+s.username[0]+".json?count="+s.count+"&callback=?"}else if(s.query===null&&s.username.length==1){return a+'//'+s.twitter_api_url+'/1/statuses/user_timeline.json?screen_name='+s.username[0]+'&count='+b+(s.retweets?'&include_rts=1':'')+'&callback=?'}else{var c=(s.query||'from:'+s.username.join(' OR from:'));return a+'//'+s.twitter_search_url+'/search.json?&q='+encodeURIComponent(c)+'&rpp='+b+'&callback=?'}}return this.each(function(i,w){var x=$('<ul class="tweet_list">').appendTo(w);var y='<p class="tweet_intro">'+s.intro_text+'</p>';var z='<p class="tweet_outro">'+s.outro_text+'</p>';var A=$('<p class="loading">'+s.loading_text+'</p>');if(s.username&&typeof(s.username)=="string"){s.username=[s.username]}var B=function(a){if(typeof s.template==="string"){var b=s.template;for(var c in a){var d=a[c];b=b.replace(new RegExp('{'+c+'}','g'),d===null?'':d)}return b}else return s.template(a)};if(s.loading_text)$(w).append(A);$(w).bind("load",function(){$.getJSON(build_url(),function(u){if(s.loading_text)A.remove();if(s.intro_text)x.before(y);x.empty();var v=$.map(u.results||u,function(a){var b=s.join_text;if(s.join_text=="auto"){if(a.text.match(/^(@([A-Za-z0-9-_]+)) .*/i)){b=s.auto_join_text_reply}else if(a.text.match(/(^\w+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+) .*/i)){b=s.auto_join_text_url}else if(a.text.match(/^((\w+ed)|just) .*/im)){b=s.auto_join_text_ed}else if(a.text.match(/^(\w*ing) .*/i)){b=s.auto_join_text_ing}else{b=s.auto_join_text_default}}var c=a.from_user||a.user.screen_name;var d=a.source;var e="http://"+s.twitter_url+"/"+c;var f=s.avatar_size;var g=a.profile_image_url||a.user.profile_image_url;var h="http://"+s.twitter_url+"/"+c+"/status/"+a.id_str;var i=(typeof(a.retweeted_status)!='undefined');var j=i?a.retweeted_status.user.screen_name:null;var k=parse_date(a.created_at);var l=relative_time(k);var m=i?('RT @'+j+' '+a.retweeted_status.text):a.text;var n=$([m]).linkUrl().linkUser().linkHash()[0];var o='<a class="tweet_user" href="'+e+'">'+c+'</a>';var p=((s.join_text)?('<span class="tweet_join"> '+b+' </span>'):' ');var q=(f?('<a class="tweet_avatar" href="'+e+'"><img src="'+g+'" height="'+f+'" width="'+f+'" alt="'+c+'\'s avatar" title="'+c+'\'s avatar" border="0"/></a>'):'');var r='<span class="tweet_time"><a href="'+h+'" title="view tweet on twitter">'+l+'</a></span>';var t='<span class="tweet_text">'+$([n]).makeHeart().capAwesome().capEpic()[0]+'</span>';return{item:a,screen_name:c,user_url:e,avatar_size:f,avatar_url:g,source:d,tweet_url:h,tweet_time:k,tweet_relative_time:l,tweet_raw_text:m,tweet_text:n,retweet:i,retweeted_screen_name:j,user:o,join:p,avatar:q,time:r,text:t}});v=$.grep(v,s.filter).slice(0,s.count);x.append($.map(v.sort(s.comparator),function(t){return"<li>"+B(t)+"</li>"}).join('')).children('li:first').addClass('tweet_first').end().children('li:odd').addClass('tweet_even').end().children('li:even').addClass('tweet_odd');if(s.outro_text)x.after(z);$(w).trigger("loaded").trigger((v.length===0?"empty":"full"));if(s.refresh_interval){window.setTimeout(function(){$(w).trigger("load")},1000*s.refresh_interval)}})}).trigger("load")})}})(jQuery);


/**
 * NoSpam
 */

jQuery.fn.nospam=function(a){a=jQuery.extend({replaceText: true,filterLevel:'normal'},a);return this.each(function(){e=null;if(a.filterLevel=='low'){if($(this).is('a[rel]')){e=$(this).attr('rel').replace('//','@').replace(/\//g,'.')}else{e=$(this).text().replace('//','@').replace(/\//g,'.')}}else{if($(this).is('a[rel]')){e=$(this).attr('rel').split('').reverse().join('').replace('//','@').replace(/\//g,'.')}else{e=$(this).text().split('').reverse().join('').replace('//','@').replace(/\//g,'.')}}if(e){if($(this).is('a[rel]')){$(this).attr('href','mailto:'+e);if(a.replaceText){$(this).text(e)}}else{$(this).text(e)}}})};



/**
 * jquery.msg
 */

/* Copyright 2011, Ben Lin (http://dreamerslab.com/)
* Licensed under the MIT License (LICENSE.txt).
*
* Version: 1.0.6
*
* Requires: 
* jQuery 1.3.0+, 
* jQuery Center plugin 1.0.0+ https://github.com/dreamerslab/jquery.center
*/

;(function(d,e){var a={},c=0,f,b=[function(){}];d.msg=function(){var g,k,j,l,m,i,h;j=[].shift.call(arguments);l={}.toString.call(j);m=d.extend({afterBlock:function(){},autoUnblock:true,center:{topPercentage:0.4},css:{},clickUnblock:true,content:"Please wait...",fadeIn:200,fadeOut:300,bgPath:"",klass:"black-on-white",method:"appendTo",target:"body",timeOut:2400,z:1000},a);l==="[object Object]"&&d.extend(m,j);i={unblock:function(){g=d("#jquery-msg-overlay").fadeOut(m.fadeOut,function(){b[m.msgID](g);g.remove();});clearTimeout(f);}};h={unblock:function(o,n){var p=o===undefined?0:o;m.msgID=n===undefined?c:n;setTimeout(function(){i.unblock();},p);},replace:function(n){if({}.toString.call(n)!=="[object String]"){throw"$.msg('replace'); error: second argument has to be a string";}d("#jquery-msg-content").empty().html(n).center(m.center);},overwriteGlobal:function(o,n){a[o]=n;}};c--;m.msgID=m.msgID===undefined?c:m.msgID;b[m.msgID]=m.beforeUnblock===undefined?function(){}:m.beforeUnblock;if(l==="[object String]"){h[j].apply(h,arguments);}else{g=d('<div id="jquery-msg-overlay" class="'+m.klass+'" style="position:absolute; z-index:'+m.z+"; top:0px; right:0px; left:0px; height:"+d(e).height()+'px;"><img src="'+m.bgPath+'blank.gif" id="jquery-msg-bg" style="width: 100%; height: 100%; top: 0px; left: 0px;"/><div id="jquery-msg-content" class="jquery-msg-content" style="position:absolute;">'+m.content+"</div></div>");g[m.method](m.target);k=d("#jquery-msg-content").center(m.center).css(m.css).hide();g.hide().fadeIn(m.fadeIn,function(){k.fadeIn("fast").children().andSelf().bind("click",function(n){n.stopPropagation();});m.afterBlock.call(h,g);m.clickUnblock&&g.bind("click",function(n){n.stopPropagation();i.unblock();});if(m.autoUnblock){f=setTimeout(i.unblock,m.timeOut);}});}return this;};})(jQuery,document);
/* Copyright 2011, Ben Lin (http://dreamerslab.com/)
* Licensed under the MIT License (LICENSE.txt).
*
* Version: 1.0.0
*
* Requires: jQuery 1.2.6+
*/
$.fn.center=function(a){var b=$(window),c=b.scrollTop();return this.each(function(){var f=$(this),e=$.extend({against:"window",top:false,topPercentage:0.5},a),d=function(){var h,g,i;if(e.against==="window"){h=b;}else{if(e.against==="parent"){h=f.parent();c=0;}else{h=f.parents(against);c=0;}}g=((h.width())-(f.outerWidth()))*0.5;i=((h.height())-(f.outerHeight()))*e.topPercentage+c;if(e.top){i=e.top+c;}f.css({left:g,top:i});};d();b.resize(d);});};



$(document).ready(function () {
    $("#goToReferences").click(function(e){
		$.scrollTo("#references", 500, {offset:-20});//the plugin will take care of this
		e.preventDefault();
	});
	
	$("a[rel='ex']").click(function(){
	  this.target = "_blank";
	});
	
	$("a#m").nospam();	
	
	$("#tweets").tweet({
		username: "bjawnie",
		join_text: "auto",
		avatar_size: 0,
		count: 1,
		auto_join_text_default: "I said,",
		auto_join_text_ed: "I",
		auto_join_text_ing: "I was",
		auto_join_text_reply: "I replied to",
		auto_join_text_url: "I was checking out",
		loading_text: "loading tweets..."
	});
	
	$.msg({
	  autoUnblock : false,
	  bgPath : '/gfx/',
	  content : 'Jeg tager pt. ikke nye opgaver ind, men tak for interessen.',
	  fadeIn : 1000,
	  center : {
	    topPercentage : 0.3
	  },
	  css : {
		padding : '40px'
	  }	  
	});	
});
