
function init() {	
	$("#usermenu").hide()
	$("#usermenu-button").toggle( showUserMenu, hideUserMenu )
	$("#appmenu-button").toggle( showAppMenu, hideAppMenu )
	
	// ANNOUNCEMENTS
	//wireupAnnouncements();
	
	// MEMBER DIRECTORY
	//wireupMemberDirectory();
}

function minit() {
	wireupUserMenu();
	
	//wireupMemberDirectory();
	// TODO: re-enable this, after the new Ajax stuff is written
}

$(document).ready(init)

//////////////////////////////////////////////////
// USER MENU FUNCTIONS ///////////////////////////

function showUserMenu() {

	$("#usermenu-button").addClass('active')
	$("#usermenu").css('display', 'block')
}

function hideUserMenu() {
	$("#usermenu-button").removeClass('active')
	$("#usermenu").css('display', 'none')
}

function showAppMenu() {
    $("#appmenu-button").addClass('active')
    $("#appmenu").css('display', 'block')
}

function hideAppMenu() {
	$("#appmenu-button").removeClass('active')
	$("#appmenu").css('display', 'none')
}

//////////////////////////////////////////////////
// ANNOUNCEMENT FUNCTIONS ////////////////////////

function wireupAnnouncements() {
	$(document.body).getElement("a.add-announcement").toggle( showAnnouncementForm, hideAnnouncementForm )
}

function showAnnouncementForm(event) {
	event.stop();
	$(this).parent(".announcement-feed").find(".add-announcement-form").show();
}

function hideAnnouncementForm(event) {
	event.stop();
	$(this).parent(".announcement-feed").find(".add-announcement-form").hide();
}

//////////////////////////////////////////////////
// MEMBER DIRECTORY //////////////////////////////

function wireupMemberDirectory() {
	$(document.body).getElements("div.people a").addEvent('click', loadMemberProfile )
}

function loadMemberProfile(event) {

	// `this` has the value of the clicked link:
	// parse the `href` attribute to get the member's ID
	// and load the AJAX-ified profile data	
	event.stop();
		
	// show this link as active:
	$(this).getParents(".people").getElements(".active")[0].removeClass("active")
	$(this).addClass("active")
	
	// determine the member ID:
	profile_url = this.href
	if( this.href.lastIndexOf("/") == this.href.length-1 )
		profile_url = profile_url.substring(0,this.href.length-1)
	profile_id = profile_url.substring( profile_url.lastIndexOf("/")+1 )
	
	// load the profile data:
	var profileView = $(this).getParents("#directory").getElements(".person")[0];
	profileView.load("/people/ajax_profile/" + profile_id)
	
	// update the browser's URL, so this is bookmarkable
	// TODO
	
	return false;
}