var Tweets = {};

$(document).ready(function() {
	
	$('#banner img').mouseover(function() {
		$('#banner-info').stop(true).animate({right: '-335px'}, 1000);
	});
	$('#banner img').mouseout(function() {
		$('#banner-info').stop(true).animate({right: '-1px'}, 500);
	});
	
	$.ajax({ url: "ajax/twitter-feed.php", success: function(JSON){
		
		Tweets = eval(JSON);
		var date = Tweets.Items[0].date;
		date = date.substring(0, date.indexOf(','));
		
		$('#my-tweets p').replaceWith('<p class="line-height-small">'+Tweets.Items[0].description+'</p>');
		$('#my-tweets #date').replaceWith('<span id="date">'+date+'</span>');
		Tweets.index = 0;
		
	}});
	
	$('.submit-button').click(function() {
		document.forms[0].submit();
	});
	
	//Code element behavior
	$('code').hover(function(){
		this.original_width = $(this).width();
		$(this).animate({width: '940px'}, function() {
			//enable line breaks
		});
	}, function() {
		$(this).stop(true).animate({width: this.original_width+'px'});
	});
	
});

function previous_tweet() {
	
	Tweets.index++;
	
	var date = Tweets.Items[Tweets.index].date;
	date = date.substring(0, date.indexOf(','));

	$('#my-tweets p').replaceWith('<p class="line-height-small">'+Tweets.Items[Tweets.index].description+'</p>');
	$('#my-tweets #date').replaceWith('<span id="date">'+date+'</span>');
	
	if( Tweets.index == Tweets.Items.length - 1 ) {
		$('#next-tweet').css('display','none');
	}
	if(Tweets.index > 0 )  {
		$('#previous-tweet').css('display','block');
	}
	
}
function next_tweet() {

	Tweets.index--;
	
	var date = Tweets.Items[Tweets.index].date;
	date = date.substring(0, date.indexOf(','));

	$('#my-tweets p').replaceWith('<p class="line-height-small">'+Tweets.Items[Tweets.index].description+'</p>');
	$('#my-tweets #date').replaceWith('<span id="date">'+date+'</span>');
	
	if( Tweets.index == 0 ) {
		$('#previous-tweet').css('display','none');
	}
	if( Tweets.index < Tweets.Items.length - 1 ) {
		$('#next-tweet').css('display','block');
	}
		
}