$(function () {
	$('div#highlight').addClass('tabbed');
	$('div#twitter').addClass('tabbed');
	
	// Random starting tab
	var start = Math.floor(Math.random()*3)
	if(start == 0) {
		$('a[href="#mostCommented"]').addClass('active');
		$('#highlight div.window').css('left','0px');
	} else if (start == 1) {
		$('a[href="#popular"]').addClass('active');
		$('#highlight div.window').css('left','-300px');
	} else {
		$('a[href="#featured"]').addClass('active');
		$('#highlight div.window').css('left','-600px');
	}
	
	// Highlighted posts
    $('a[href="#mostCommented"]').click(function(event) {
    	event.preventDefault();
    	$(this).parent().parent().find('a.active').removeClass('active');
    	$(this).toggleClass('active');
    	$('#highlight div.window').animate({"left": "0px"},400,'easeInOutExpo');
    });
    $('a[href="#popular"]').click(function(event) {
    	event.preventDefault();
    	$(this).parent().parent().find('a.active').removeClass('active');
    	$(this).toggleClass('active');
    	$('#highlight div.window').animate({"left": "-300px"},400,'easeInOutExpo');
    });
    $('a[href="#featured"]').click(function(event) {
    	event.preventDefault();
    	$(this).parent().parent().find('a.active').removeClass('active');
    	$(this).toggleClass('active');
    	$('#highlight div.window').animate({"left": "-600px"},400,'easeInOutExpo');
    });
    
    // Twitter
    $('a[href="#twosecondsaway"]').addClass('active');
	$('#twitter div.window').css('left','0px');
	
    $('a[href="#twosecondsaway"]').click(function(event) {
    	event.preventDefault();
    	$(this).parent().parent().find('a.active').removeClass('active');
    	$(this).toggleClass('active');
    	$('#twitter div.window').animate({"left": "0px"},400,'easeInOutExpo');
    });
    $('a[href="#timseley"]').click(function(event) {
    	event.preventDefault();
    	$(this).parent().parent().find('a.active').removeClass('active');
    	$(this).toggleClass('active');
    	$('#twitter div.window').animate({"left": "-300px"},400,'easeInOutExpo');
    });
    $('a[href="#largen"]').click(function(event) {
    	event.preventDefault();
    	$(this).parent().parent().find('a.active').removeClass('active');
    	$(this).toggleClass('active');
    	$('#twitter div.window').animate({"left": "-600px"},400,'easeInOutExpo');
    });
});