/*
	TourCalendarInterface.js
	
	Basic Pagination setup for the Tour Calendar Application. 
	
*/

var TourCalendarPagination = new Class({
	/*
		Options to set rendering locations.
	*/
	options: {
		Wrapper:        '/tour.cfm',    // Page where we run AJAX requests on. Relative to root directory.
		TourCalendar:	'calendar',    	// Where we replace new Tour Calendar AJAX response with 
		NextPage:       'NextPage',		// Next Page Button
		PrevPage:       'PrevPage',     // Prev Page Button	
		TipContainer:	'tour_right'	// Page element that contains the calendar tips
	},
	
	initialize: function(options) {
		// Start-Up Code	
		this.setOptions(options);

		this.TourCalendar = $(this.options.TourCalendar);
				
		this.InterfaceSetup();
		
	},
	/*
		sAttributes : Attributes in the form of /Page/1/Request/Test Request Response or ?Page=1&Request=Test Request Response
		oContainer  : Container in the form of 'test'
		postFunction: Function to execute after the response has been received.
	*/	
	LoadContent: function(sAttributes, oContainer, postFunction) {
		if( postFunction != null )
			new Ajax( this.options.Wrapper + sAttributes, { method: 'get', update: oContainer, onComplete: postFunction }).request();
		else
			new Ajax( this.options.Wrapper + sAttributes, { method: 'get', update: oContainer}).request();
	},
	
	NextPress: function( event ){			
		this.SetNextPage( this.NextPage.name );
	
		event.stop();
	},
	
	PrevPress: function( event ){	
		this.SetPrevPage( this.PrevPage.name );
		
		event.stop();
	},
		
	InterfaceSetup: function() {
		this.NextPage       = $(this.options.NextPage);
		this.PrevPage       = $(this.options.PrevPage);
		
		if( this.NextPage )
			this.Total = this.NextPage.name;
		else
			this.Total = null;
		// End Initial Setup

		// Setup Navigation
		if( this.NextPage )
			this.NextPage.addEvent('click', this.NextPress.bindWithEvent( this ));
		if( this.PrevPage )
			this.PrevPage.addEvent('click', this.PrevPress.bindWithEvent( this ));
			
		// Initialize Tool-Tips | ** USES: InputClearAndReplace.js **
		var inputList = new InputClearAndReplace();
		if( $( this.options.TipContainer ) ) initToolTips();

	},
	
	SetNextPage: function( page ) {		
		
		var cPage = $(this.options.TourCalendar);
		
		if( cPage ) {
			// Load Content
			var Attributes = '/CalendarDate/' + page + '/';
			this.LoadContent( Attributes, this.TourCalendar, this.InterfaceSetup.bind(this) );
		}
	},
	
	SetPrevPage: function( page ) {		
		
		var cPage = $(this.options.TourCalendar);
		
		
		if( cPage ) {
			// Load Content
			var Attributes = '/CalendarDate/' + page + '/';
			this.LoadContent( Attributes, this.TourCalendar, this.InterfaceSetup.bind(this) );
		} 
	},

	initToolTips: function( ) {	
	
		var Tips1 = new Tips( $$( '.calendar_tips' ) );
	
	}
	
});

TourCalendarPagination.implement(new Options);

// DOMReady
window.addEvent('domready', function(){
	var Pagination = new TourCalendarPagination();
});