// handles showing the most recent notifications
document.observe("dom:loaded", function() {
	$$("#stats_box").invoke("observe", "click", function(event) {
		player_id = this.className;
		var box = this.parentNode;
		
		if(!$$("#" + box.id + " .noteMenu")[0]) {
			var noteMenu = document.createElement("div");
			noteMenu.className = "noteMenu";
			$(box).insert({top: noteMenu});
			//new Ajax.Request("imageContextBox.php?snapshot_id=" + box.id.split("image")[1], {
			new Ajax.Request("notifications.php?player_id=" + player_id, {

				method: "post",
				onSuccess: function(ajax) {
					noteMenu.innerHTML = ajax.responseText;
					
					// add on click handler for the close Button
					$$("#" + box.id + " .closeButton").invoke("observe", "click", function(event) {
						this.parentNode.toggle();
					});
				},
				onFailure: function(ajax) {
					noteMenu.innerHTML = "There was a problem loading the data. Try again.";
				}
			});
		} else {
			$$("#" + box.id + " .noteMenu")[0].toggle();
		}
	});
});
