$(document).ready(function()
{
	$('#popup').css({
		width: "420px", 
		height: "320px"});
	
	$('div[mweori]').hover(function()
	{
		$('div[mweori2="'+$(this).attr("mweori")+'"]').removeClass('invisible');
	}, function()
	{
		$('div[mweori2="'+$(this).attr("mweori")+'"]').addClass('invisible');
	});
	
	$('#contentholder a.lightbox').lightBox();
	
	$('#popupclose').click(function()
	{
		$('#popup').addClass('invisible');
	});
	
	$('#mpopupclose').click(function()
	{
		$('#mpopup').addClass("invisible");
	});

	$('.compose').click(function()
	{
		$('#mpopupt').html("loading...");
		
		$('#mpopup').center();
		
		$('#mpopup').removeClass("invisible");
		
		$.get("messagestuff.php?rtype=compose", { recipient: $(this).attr("cid") } , function(data)
		{
			$('#mpopupt').html(data);

			if($('#post')) $('#post').bindPost();

		});
		
	});
});

jQuery.fn.bindPost = function()
{
	$(this).click(function()
	{
		$.post("messagestuff.php?rtype=post", 
		{
			subject: $('#subject').val(),
			recipient: $('#recipient').val(),
			message: $('#message').val(), 
			replyto: $('#replyto').val()
		},
		function(data)
		{
			$('#mpopupt').html(data);
			if($('#post')) $('#post').bindPost();
		});
	});
	
	return this;
}
