jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}
jQuery.fn.centertop = function () {
    this.css("position","absolute");
    this.css("top", "0px");
    this.css("left", ( $(window).width() - 280 ) / 2+$(window).scrollLeft() + "px");
    return this;
}



$(document).ready(function() {
	$("#nutrition").hide().draggable();
	//$("#controlPanel").draggable();fadeIn(2500);
	$(".nutrientButton").mousedown(function() {
		$('#nutrition').load('./pdf/nutritionform.php?id='+this.id, function() {
			$('#nutrition').show().css('background','white');
			$('#nutritionSave').mousedown(function() {
				$.post("./pdf/bridge.php", { form:'nutrition', data:$(nutritionForm).serialize() }
				, function(data) {
					alert(data);
				});	
			});
		});
	});
	$('input[type=submit]').button();
	
	$('#loginForm').submit(function() {
		$.post("./bridge.php", { email: $("#email").val(), password: $("#pass").val() }
		, function(data) {
			if(data.success)
			{
				$('#errorText').html(data.message);
				$('#messagePanel').fadeIn().center().delay(700).fadeOut(1000, function() {
						location.reload(true);
					});
			}
			else 
			{
				$('#errorPanel').fadeIn().center().delay(700).fadeOut(1000);
				$('#errorText').html(data.message);	
			}
		}, 'json');
	
	return false;
	});
	
	$('#logoutButton').button().mousedown(function() {
		$('#controlPanel').load('./destroy.php', function() {
			location.reload(true);
		});
	});
	
	$('#clientsButton').button().mousedown(function() {
		$('#clientPanel').load('./clientlist.php', function(){
			$('#clientPanel').draggable().addClass('lcs-widget').fadeToggle();
			$('button').button();
		});
	});
	
	$('#logo').hover(function () {
        this.src = './lcshover.gif';
    }, function () {
        this.src = './lcs.gif';
    });
		$('#logodiv').mousedown(function() {
		$('#controlPanel').fadeIn();
	});
	});
