/**
 * Shows the given number of tweets
 */
function showTweets(number) {
	$.ajax({
		dataType: 'jsonp',
		url: 'http://api.twitter.com/1/statuses/user_timeline.json',
		data: 'screen_name=naja1987&count=' + number + '&include_rts=true',
		success: twitterCallback2 // callback defined in http://twitter.com/javascripts/blogger.js"
	});
}

/**
 * Highlights the given page (by url) in the navigation menu
 */
function highlightPage(page) {
	$('#navigation a').each(function() {
		href = $(this).attr('href');
		if ( (href == page) || (href == '') ) {
			$(this).addClass('on');
		} else {
			$(this).removeClass('on');
		}
	});
}

/**
 * Loads the markdown from the given url (via python script) 
 * and puts the content in the given DOM element.
 */
function loadMarkdown(url, domElem) {
	$.ajax({
		url: url,
		data: { ajax: 'on' },
		mimeType: 'text/html',
		type: 'GET',
		success: function(data) {
			domElem.empty();
			domElem.append(data);
			domElem.removeClass('error');
		}, 
		error: function(jqXHR, textStatus, errorThrown) {
			domElem.empty();
			domElem.append('Error reading from ' + url + ':<br />'  + jqXHR + ' ' + textStatus + ' ' + errorThrown);
			domElem.addClass('error');
		}
	});
}

/* from http://jumk.de/nospam/ */

function UnCryptMailto(s) {
    var n = 0;
    var r = "";
    for( var i = 0; i < s.length; i++)
    {
        n = s.charCodeAt( i );
        if( n >= 8364 )
        {
            n = 128;
        }
        r += String.fromCharCode( n - 1 );
    }
    return r;
}

function linkTo_UnCryptMailto(s) {
    location.href=UnCryptMailto( s );
}
