function fbAlert(msg) {
	$("#alertMessage").html(msg);
	$("a#alertBox_link").trigger("click");
	$.fancybox.resize();
}

function showError(msg) {
	$("p.error").html(msg);
	$("p.error").show();
	$.fancybox.resize();
}

$(document).ready(function() {
	$("a#alertBox_link").fancybox({
		'autoDimensions': true,
		'padding'		: 0,
		'titleShow'		: false
	});
	$("a#inline").fancybox({
		'hideOnContentClick': true
	});
	$(".nutr-info").fancybox({
		'width': 360,
		'height': 555,
		'transitionIn' : 'none',
		'transitionOut' : 'none',
		'type' : 'iframe'
	});
	$("a.signupForm_link").fancybox({
		'autoDimensions': true,
		'padding'		: 0,
		'titleShow'		: false,
		'onStart'		: function() {
	    	$("p.error").hide();
		},
		'onClosed'		: function() {
	    	$("p.error").hide();
		}
	});
	$("a.loginForm_link").fancybox({
		'autoDimensions': true,
		'padding'		: 0,
		'titleShow'		: false,
		'onStart'		: function() {
	    	$("p.error").hide();
		},
		'onClosed'		: function() {
	    	$("p.error").hide();
		}
	});
	$("a.pwdReminderForm_link").fancybox({
		'autoDimensions': true,
		'padding'		: 0,
		'titleShow'		: false,
		'onStart'		: function() {
	    	$("p.error").hide();
		},
		'onClosed'		: function() {
	    	$("p.error").hide();
		}
	});

	if (self.document.location.hash.substring(1) == 'login')
		$('a.loginForm_link').trigger('click');
	if (self.document.location.hash.substring(1) == 'signup')
		$('a.signupForm_link').trigger('click');

	$("#loginForm").bind("submit", function() {
		if ( bpass() ) {

	    	$("#error").hide();
			$.fancybox.showActivity();

			$.ajax({
				type	: "POST",
				cache	: false,
				url		: "/members/memberlogin.cfm",
				data	: $(this).serializeArray(),
				success	: function(data) {
					if ($.trim(data).length)
						if (data.indexOf('login_ok') > 0)
							$.fancybox(data,{
								'autoDimensions': true,
								'padding'		: 0,
								'scrolling'		: 'no',
								'titleShow'		: false,
								'onClosed'		: function() {
									window.location = window.location.href.replace( /#.*/, "");
									return true;
								}
							});
						else
							$.fancybox(data,{
								'autoDimensions': false,
								'padding'		: 0,
								'width'         : 500,
								'height'        : 'auto',
								'scrolling'		: 'no',
								'titleShow'		: false
							});
					else {
						window.location = window.location.href.replace( /#.*/, "");
					}
				}
			});
		}
		return false;
	});
	$("#loginNewForm").bind("submit", function() {
		if ( loginNewSubmit() ) {

	    	$("#error").hide();
			$.fancybox.showActivity();

			$.ajax({
				type	: "POST",
				cache	: false,
				url		: "/members/memberlogin.cfm",
				data	: $(this).serializeArray(),
				success	: function(data) {
					if (data.indexOf('login_ok') < 0)
						$.fancybox(data,{
							'autoDimensions': false,
							'padding'		: 0,
							'width'         : 500,
							'height'        : 'auto',
							'scrolling'		: 'no',
							'titleShow'		: false
						});
					else window.location = "/members/member-form.cfm";
				}
			});
		}
		return false;
	});
	$("#pwdReminderForm").bind("submit", function() {
		if ( pwdReminderSubmit() ) {

	    	$("#error").hide();
			$.fancybox.showActivity();

			$.ajax({
				type	: "POST",
				cache	: false,
				url		: "/members/pwdSender.cfm",
				data	: $(this).serializeArray(),
				success	: function(data) {
					if ($.trim(data).length)
						$.fancybox(data,{
							'autoDimensions': false,
							'padding'		: 0,
							'width'         : 625,
							'height'        : 'auto',
							'scrolling'		: 'no',
							'titleShow'		: false
						});
					else $.fancybox.close();
				}
			});
		}
		return false;
	});
});

