var popupStatus = 0;
function profile() {
	$('.profile_friends .hidden_by_default').hide();
	$('#content a.dotted').click(function(){
		var arr = $('span:first',this);
		var arrhtml = arr.html();
		if ((arrhtml=='&uarr;') | (arrhtml=='↑')) {
			arr.html('&darr;');
			$(this).parent().parent().find('.hidden_by_default').hide();
		} else {
			arr.html('&uarr;');
			$(this).parent().parent().find('.hidden_by_default').show('200');
		}
		return false;
	});

	$('#sendmessage').click(function(){
		show_message();
		return false;
	});
	$('#messageClose').click(function() {
		hide_message();
		return false;
	});
	$("#backgroundPopup").click(function(){
		hide_message();
		return false;
	});

}

function show_message(id){
	if(popupStatus==0){
		center();
		//showing message
		$("#backgroundPopup").css({
		"opacity": "0.7",
		"filter": "alpha(opacity=70)"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#message").fadeIn("slow",function(){
			$('#replytext').focus().keypress(function(e){
				if((e.ctrlKey) && ((e.keyCode == 0xA)||(e.keyCode == 0xD)))    {
					$('#replysubmit').click();
										
				}
		});});
		popupStatus = 1;
		$(document).keypress(function(e){
			if(e.keyCode==27){
				hide_message();
			}
		});
	}
}



function hide_message() {
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#message").fadeOut("slow");
		popupStatus = 0;
		$(document).unbind('keypress');
	}
}

function center(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#message").height();
	var popupWidth = $("#message").width();
	$("#message").css({
	"position": "absolute",
	"top": windowHeight/2-popupHeight/2,
	"left": windowWidth/2-popupWidth
	});

	$("#backgroundPopup").css({
	"height": windowHeight
	});
}