$(document).ready(function() {
	$("#AccountLoginForm .submit input").click(function(e) {
		e.preventDefault();
		$.post(
			'/accounts/ajax_login',
			{
				'data[Account][email]': $("#AccountEmail").val(),
				'data[Account][password]': $("#AccountPassword").val(),
				'data[ajax_login]': true
			},
			function(response) {
				if(response == 'true') {
					window.location.href = window.location.href;
				} else {
					$("#login_lightbox_error").text(response);
				}
			}
		);
	});

	$("#header_logout").click(function(e) {
		if(parseInt($("#use_fb").text()) == 1) {
			FB.ensureInit(function() {
				var session = FB.Facebook.apiClient.get_session();
				if(session) {
					if(session.uid == parseInt($("#fb_uid").text())) {
						e.preventDefault();
						FB.Connect.logoutAndRedirect('/accounts/logout');
					}
				}
			});
		}
	});
});


function __getClass(obj) {
	return Object.prototype.toString.call(obj).match(/^\[object\s(.*)\]$/)[1];
}

