
/*===============================================================================
	events.js
	John Larson
	6/24/08
	
	All page-specific JavaScript for events.asp.
	
	
	
===============================================================================*/


window.addEvent('domready', function() {

	dbug.enable();
	
	futureEventListing = $('futureEventListing');
	futureEventListing.mySlider = new Fx.Slide(futureEventListing,
		{open: true, duration: 500});
	
	pastEventListing = $('pastEventListing');
	pastEventListing.mySlider = new Fx.Slide(pastEventListing,
		{open: false, duration: 500});
	pastEventListing.mySlider.hide();
//	pastEventListing.setStyle('margin-left', '0px');
});



/****************************************************************************
//	SECTION::Past Event Loading
*/
	
	var viewingPastEvents = false;
	var pastContainerIsScrolling = false;
	var pastEventIsLoading = false;
	function loadPastEvent(DanceEventID) {
		showLoad();
		if(viewingPastEvents) {
			pastEventListing.mySlider.slideOut();
			pastContainerIsScrolling = true;
			slideInLoadedEvent.delay(600);
		}
		else
			futureEventListing.mySlider.slideOut();
		
		swapSections('futureTitle', 'pastTitle');
		pastEventIsLoading = true;
		new Ajax('events.asp?a=loadPastEvent', {
			method: 'post',
			data: 'DanceEventID=' + DanceEventID,
			update: 'pastEventListing',
			onComplete: function() {
				pastEventIsLoading = false;
				dbug.log('loaded, are we still scrolling? ' + pastContainerIsScrolling);
				if(!pastContainerIsScrolling) // we're done sliding out, so can slide back in!
					pastEventListing.mySlider.slideIn();
				hideLoad();
				viewingPastEvents = true;
			}
		}).request();
	}
	
	function slideInLoadedEvent() {
		dbug.log('done sliding, are we still loading? ' + pastEventIsLoading);
		pastContainerIsScrolling = false;  // by the time I am called, this is true!
		if(!pastEventIsLoading) // it's loaded now, so roll out!
			pastEventListing.mySlider.slideIn();
	}
	
	function returnToFutureEvents() {
		swapSections('pastTitle', 'futureTitle');
		pastEventListing.mySlider.slideOut().chain(function() {
			futureEventListing.mySlider.slideIn();
			viewingPastEvents = false;
		});
	}
/*
//	End SECTION::Past Event Loading
****************************************************************************/