function setNavBarHeight(bottom) {
	var contentHeight = $('content').offsetHeight;
	var navbarHeight = $('lnav-mid').offsetHeight;
	if(contentHeight > navbarHeight) {
		if(bottom) { $('lnav-bottom-buttons').style.height = (contentHeight-250 < 495) ? "300px" : (contentHeight-250) + "px"; }
		else { $('lnav-mid').style.height = (contentHeight-150) + "px"; }
	}
}

function showNavBar(pid) {

	var npath = "getNavMenu.php";
	if(location.href.indexOf("content") != -1) { npath = "../../"+npath; }
	new Ajax.Request(npath,
			{
				parameters: {pid: pid },
				onSuccess: function(transport){

					var response = transport.responseText;
					$('lnav-mid').innerHTML = response;
				},
				onFailure: function(){ alert('The menu could not be loaded.') }
			});	
}

function showEvents() {
	var npath = "getEvents.php";
	if(location.href.indexOf("content") != -1) { npath = "../../"+npath; }
	new Ajax.Request(npath,
			{
				onSuccess: function(transport){

					var response = transport.responseText;
					$('lnav-mid').innerHTML = response;
					setNavBarHeight();
				},
				onFailure: function(){ alert('The events summary could not be loaded.') }
			});	
}

function showMonth(mon,year,is_init) {
	openEvent = -1;
	var npath = "admin/getMonth.php";
	if(location.href.indexOf("content") != -1) { npath = "../../"+npath; }
	new Ajax.Request(npath,
		{
			parameters: { mon:mon, year:year, size:'small' },	
			onSuccess: function(transport){
			  var response = transport.responseText || "no response text";
			  $('calendarDiv').innerHTML = response;
			  if(is_init) $('day-'+dayHighlight).className += " today-highlight ";
			},
			onFailure: function(){ alert('Unable to load the calendar.') }
		});	
}

function openEvents(yr,mon,day) {
	openEvent = -1;
	var npath = "getEventDetails.php";
	if(location.href.indexOf("content") != -1) { npath = "../../"+npath; }
	new Ajax.Request(npath,
		{
			parameters: { mon:mon, year:yr, day:day },	
			onSuccess: function(transport){
			  var response = transport.responseText || "no response text";
			  $('eventsDiv').innerHTML = response;
			  $('day-'+dayHighlight).className = " event-highlight calendar ";			  
			  dayHighlight = day;
			  $('day-'+dayHighlight).className += " today-highlight ";
			},
			onFailure: function(){ alert('Unable to load the events.') }
		});	
}

function go(loc) {
window.location.href = loc;
}

var openEvent = -1;

function showDetails(eid) {
	if(openEvent != -1 && $('event_'+openEvent)) {
		new Effect.toggle('event_'+openEvent, 'blind', {duration: 0.25});
	}
	if(openEvent != eid) {
		new Effect.toggle('event_'+eid, 'blind', {duration: 0.25});
		openEvent = eid;
	} else {
		openEvent = -1;
	}

}

