// Setup a facebook user
var fbuser = '90322663488';

// Set dutch month names
var dutch = ['',
    'januari', 'februari', 'maart', 'april', 'mei', 'juni',
    'juli', 'augustus', 'september', 'oktober', 'november', 'december'
];

// Set toggle
var r = false;

// Start functioning when DOM is ready
$(function()
{
	// Set link to get the data from
	var link = 'http://graph.facebook.com/_USER_/feed?limit=3&callback=?'
	.replace('_USER_', fbuser);
	
	// Get Facebook messages
	$.getJSON(link, function(d,s)
	{
		// Loop through the status items
		for (i in d.data) {
			// Set shortcut
			i = d.data[i];
			// Get date, name and text
			var date = i.updated_time.substr(0,10).split('-');
				date = new Date(date[0], date[1], date[2]);
			var date = {
				day: date.getDate(),
				month: dutch[ date.getMonth() ],
				year: date.getFullYear()
			};
			var time = i.updated_time.substr(11,5);
			
			var name = i.from.name;
			var text = i.message || i.caption;
			var pict = i.picture;
			
			// Empty current contents on the site if necessary
			if (!r) {
				$('.fb').empty();
				r = true;
			}
			
			// Define content
			var content = new String();
			if (typeof pict != 'undefined') {
				content = content+'<img src="'+pict+'" alt="fbpicture" />';
			}
			if (typeof text != 'undefined') {
				content = content+'<p>'+text+'</p>';
			}
			
			// Add the item
			$('.fb').append('<li style="display:none;"><h3>'+date.day+' '+date.month+' '+date.year+' | '+time+'</h3><span class="subtitle">'+name+'</span>'+content+'</li>');
			$('.fb li:first').addClass('first');
		}
		
		// Fade in the facebook messages
		$('.fb li').fadeIn('normal');
		
		// Make the items clickable
		$('.fb li')
			.css('cursor', 'pointer')
			.click(function() {
				var url = $('.wordfan').attr('href');
				window.open(url, '_blank');
			});
			
		//fixHeight();
	});
	
	// Fix height
//	setTimeout(fixHeight, 1000);
	
	// Fix height on resize
//	$(window).resize(function() {
//		fixHeight();
//	});
});

// Set orig height
//var orig = 0;

// Function to fix the full height
//function fixHeight()
//{
//	if (orig > 0) $('#right').height(orig);
	
	// Get right and window height
//	var r = $('#right').height();
//	var w = $(document).height();
	
	// Set original height
//	if (!orig) orig = r;
	
	// Set new height
//	var n = (orig < w) ? w : orig;
	
//	console.log('orig: '+orig+'; w: '+w+'; n: '+n);
//	$('#right').height(n);
//}
