/**
	Global.js - Globally available scripts

*/

jQuery(function($) {
	/**
		When the page first loads, the page checks for the current users
		identity and updates the login area accordingly.
	*/
	$.JSONService().add("users", "/netsmartz_v3/services/users_2.asmx");
	$.UserIsLoggedIn = false;
	
	$(window).bind("login", function(e, username) {
		$("#login-status .authenticated .name").text(username);
		$("#login-status .authenticated").fadeIn();
		$("#login-status .anonymous").hide();
		$.UserIsLoggedIn = true;
	});
	$(window).bind("logout", function(e) {
		$("#login-status .authenticated .name").text("");
		$("#login-status .authenticated").hide();
		$("#login-status .anonymous").fadeIn();
		$.UserIsLoggedIn = false;
	});
	
	checkLoginStatus = function(name) {
		if(name == "Anonymous") {
			$(window).trigger("logout");
		}
		else {
			$(window).trigger("login", [name]);
		}
	}
	$.JSONService("users").ok(checkLoginStatus).call("WhoAmI");
});
