//login scripts
var firstLogin = true;
egg.bind({
	"simple.login":function(success){
		//Login will be false, only if its the first time loading
		if (!success) egg.trigger("simple.logout",true);
		else{
			//we don't want to refresh the page on the first page load
			if (!firstLogin) egg.history(true);
			else firstLogin = false;
			//display logout links
			$('#login_logout').text("<a href='javascript:simple_server.logout()'>Logout</a>");
			displayLogin(false);
		}
	},
	"simple.logout":function(success){
		if (!success) alert("Could not logout, please try again.");
		else{
			//we don't want to refresh the page on the first page load
			if (!firstLogin) egg.history(true);
			else firstLogin = false;
			//display login box
			$('#login').ajax('pages/admin/login_format.php',{html:true,oncomplete:function(text){
				$$(this).refine("* input").inputClearFX('#68462f');
			}});
			$('#login_logout').text("<a href=\"javascript:displayLogin(true)\" title=\"For registered users...\">Login</a>");
		}
	}
});
function displayLogin(show){
	var newStyle = show ? 'block' : 'none';
	egg.lookup('#centering')[0].style.display = newStyle;
	egg.lookup('#opacity_mask')[0].style.display = newStyle;
}

