// Display the Upcoming Events && Hide the Past Events
function showUpcomingEvents(e) {
	if( e != null )
	{
		new Event(e).preventDefault();
		this.blur();
	}

	$E(".upcomingEventsMenu").addClass("active");
	$E(".pastEventsMenu").removeClass("active");
	
	
	$("upcomingEventsNavList").removeClass("hide");
	$("pastEventsNavList").addClass("hide");
}

// Display the Past Events && Hide the Upcoming Events
function showPastEvents(e) {
	if( e != null )
	{
		new Event(e).preventDefault();
		this.blur();
	}
	
	$E(".upcomingEventsMenu").removeClass("active");
	$E(".pastEventsMenu").addClass("active");
	
	
	$("upcomingEventsNavList").addClass("hide");
	$("pastEventsNavList").removeClass("hide");
}

// Grab the Query String Parameter 'name''s Value 
function GET( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

window.addEvent("domready", function () {
	
	// Replace the Spans with Links && Assign Appropriate Events
	var upcomingEventsTitleLink = new Element("a");
	upcomingEventsTitleLink.addClass("upcomingEventsTitleLink");
	upcomingEventsTitleLink.href = "#";
	upcomingEventsTitleLink.addEvents({"click":showUpcomingEvents,"focus":showUpcomingEvents});
	upcomingEventsTitleLink.innerHTML = $E(".upcomingEventsTitle").innerHTML;
	upcomingEventsTitleLink.injectBefore($E(".upcomingEventsTitle"));
	$E(".upcomingEventsTitle").remove();
	
	var pastEventsTitleLink = new Element("a");
	pastEventsTitleLink.addClass("pastEventsTitleLink");
	pastEventsTitleLink.href = "#";
	pastEventsTitleLink.addEvents({"click":showPastEvents,"focus":showPastEvents});
	pastEventsTitleLink.innerHTML = $E(".pastEventsTitle").innerHTML;
	pastEventsTitleLink.injectBefore($E(".pastEventsTitle"));
	$E(".pastEventsTitle").remove();
	
	// Navigation Related Code
	if (GET("nav") == "curr")
		showUpcomingEvents();
	else if (GET("nav") == "past")
		showPastEvents();
	else
	{
		// Hide the Events Sub-Lists
		$("upcomingEventsNavList").addClass("hide");
		$("pastEventsNavList").addClass("hide");
	}
});
