var fbBoxPos = {};
var fbClosed = false;

$(document).ready(function(){
	
	// facebook close
	$("#facebook #close").click(function(){
		$("#facebook").hide();
		fbClosed = true;
		return false;
	});
	
	// initiate
	cFbBoxPos();
	if( fbBoxPos.top > 0 && fbBoxPos.right > 0 ) $("#facebook").css({'top':fbBoxPos.top,'right':fbBoxPos.right}).show();
	
	// resize
	$(window).resize(function(){
		cFbBoxPos();
		if ( !fbClosed ) {
			if( fbBoxPos.top > 0 && fbBoxPos.right > 0 ) $("#facebook").css({'top':fbBoxPos.top,'right':fbBoxPos.right}).show();
			else $("#facebook").hide();
		} else {
			$("#facebook").hide();
		}
	});
	
});

function cFbBoxPos() {
	fbBoxPos.top = Math.ceil(($("body").height() - 590)/2 + 114 );
	fbBoxPos.right = Math.ceil(($("body").width() - 990)/2) - 118;
}