var index = 1;

$(document).ready
(
	function()
	{
		var numPosts = $('#blog-posts .the-post').size();
		var postWidth = 276;			
		
		if(numPosts > 0)
		{
			var blogPostsWidth = postWidth * numPosts;
			
			if(numPosts > 3)
			{
				$('#blog-posts').width(blogPostsWidth);
				
				$('#previous-posts').click
				(
					function()
					{
						if(index > 1)
						{
							$('#blog-posts').animate({'margin-left': '+=' + postWidth + 'px'}, 'slow');
						
							index--;
						}
						
						return false;
					}
				);
				
				$('#next-posts').click
				(
					function()
					{
						if(index < numPosts)
						{
							$('#blog-posts').animate({'margin-left': '-=' + postWidth + 'px'}, 'slow');
						
							index++;
						}
						
						return false;
					}
				);
			}
			else
			{
				$('#previous-posts').hide();
				$('#next-posts').hide();
			}
		}
	}
);
