var MARKUPBOY = {};
ChiliBook.recipeFolder = "/javascripts/chili/"; 

MARKUPBOY.loadTwitterStatus = function() {
	$.getJSON('http://twitter.com/statuses/user_timeline/markupboy.json?count=1&callback=?', function(data) {
			$.each(data, function(i, item) {
				$('#twitter-post').html('"'+item.text+'"');
			});
		}
	); 
};

MARKUPBOY.updateGutterLinkPositions = function() {
	$('#Gutter a.open, #Gutter a.collapsed').each(function() {
		var id = "#" + $(this).attr('rel');
		$(this).css('top', $(id).offset().top);
	});
	
	$('#Gutter a.close').each(function() {
		var id = "#" + $(this).attr('rel');
		$(this).css('top', $(id).offset().top + $(id).height());
	});
};


$(document).ready(function() {
	MARKUPBOY.loadTwitterStatus();
	
	$("body").append("<ul id='Gutter'></ul>");
	
	$('#Gutter a.open, #Gutter a.close').live('click', function() {
		var id = $(this).attr('rel');
		$('.entry_body[id=body_'+id+']').hide();
		$('.close[rel='+id+']').hide();
		$('.open[rel='+id+']').addClass('collapsed').removeClass('open');
		MARKUPBOY.updateGutterLinkPositions();
		return false;
	});
	
	$('#Gutter .collapsed').live('click', function() {
		var id = $(this).attr('rel');
		$('.entry_body[id=body_'+id+']').show();
		$('.close[rel='+id+']').show();
		$('.collapsed[rel='+id+']').addClass('open').removeClass('collapsed');
		MARKUPBOY.updateGutterLinkPositions();
		return false;
	});
	
	$(".post").each(function() {
		var top = $(this).offset().top;
		var bottom = top + $(this).height();
		var id = $(this).attr('id');
 		$("<li><a href='#' class='open' rel='"+id+"'>&nbsp;</a></li>").appendTo('#Gutter').find('a').css("top", top);
		$("<li><a href='#' class='close' rel='"+id+"'>&nbsp;</a></li>").appendTo('#Gutter').find('a').css("top", bottom);
	});
	
});