$(document).ready(function() {
	var popup = false;
	$('a.readmorelink').click(function(event) {
		event.preventDefault();
		if(popup) {
			popup = false;
			$('#bp-container').fadeOut("slow");
			$('#bp-overlay').fadeOut("fast");
			return false;
		} else {
			popup = true;
			var id = $(this).attr('id');
			var title = $('#title' + id).html();
			var content = $('#readmore' + id).html();
			$('#bp-title').html(title);
			$('#bp-content').html(content);
			$('#bp-container').fadeIn("slow");
			$('#bp-overlay').fadeIn("fast");
			var thisheight = $('#bp-popup').height();
			var halfheight = -thisheight/2;
			var newheight = halfheight-50;
			$('#bp-popup').css('margin-top', newheight);
			return false;
		};
	});

	$('body').append('<div id="bp-overlay" style="filter:alpha(opacity=60);">&nbsp;</div><div id="bp-container"><div id="bp-popup"><h4 id="bp-title"></h4><a href="#" class="close">close</a><div id="bp-content"></div></div></div>');
	
	$('.close').click(function(event) {
		event.preventDefault();
		if(popup) {
			popup = false;
			$('#bp-container').fadeOut("fast");
			$('#bp-overlay').fadeOut("fast");
			return false;
		};
	});
});
