/*
	CalendarInterface.js
	
	Basic Pagination setup for the Calendar Application. 
	
*/

var CalendarPagination = new Class({
	/*
		Options to set rendering locations.
	*/
	options: {
		Wrapper:       '/the_atrium_blog.cfm',		// Page where we run AJAX requests on. Relative to root directory.
		Calendar:		'blog_calendar',	// Where we replace new Calendar AJAX response with
		NextPage:      'NextPage',		// Next Page Button
		PrevPage:      'PrevPage',		// Prev Page Button
		TipContainer:	'blog_calendar',   	// Page element that contains the calendar tips 
		Section:		'Atrium'			// The section the web site is in.
	},
	
	initialize: function(options) {
		this.setOptions(options);
		this.Calendar = $(this.options.Calendar);
		this.InterfaceSetup();
	},

	LoadContent: function(sAttributes, oContainer, postFunction) {
		if( postFunction != null ) {
			new Ajax( this.options.Wrapper + sAttributes, { method: 'get', update: oContainer, onComplete: postFunction } ).request();
			//var req = new Request.HTML({ update: oContainer, evalScripts: true, url: this.options.Wrapper + sAttributes, onSuccess: postFunction, onFailure: function(){oContainer.set('text', 'The request failed.');} }).get();
		} else {
			new Ajax( this.options.Wrapper + sAttributes, { method: 'get', update: oContainer } ).request();
			//var req = new Request.HTML({  method: 'get', url: this.options.Wrapper + sAttributes, update: oContainer }).get();
		}
	},
	
	NextPress: function( event ){			
		this.SetNextPage( this.NextPage.name.split('_')[0] );
		event.stop();
	},
	
	PrevPress: function( event ){	
		this.SetPrevPage( this.PrevPage.name.split('_')[0] );
		event.stop();
	},
		
	InterfaceSetup: function() {
		this.NextPage       = $(this.options.NextPage.split('_')[0]);
		this.PrevPage       = $(this.options.PrevPage.split('_')[0]);
		
		if (this.NextPage != null) 
			this.NextPage.addEvent('click', this.NextPress.bindWithEvent( this ));
		if (this.PrevPage != null) 
			this.PrevPage.addEvent('click', this.PrevPress.bindWithEvent( this ));
			
		// Initialize Tool-Tips | ** USES: InputClearAndReplace.js **
		//var inputList = new InputClearAndReplace();
		if( $( this.options.TipContainer ) ) this.initToolTips();
	},
	
	SetNextPage: function( page ) {		
		if( $(this.options.Calendar) ) {
			var Attributes = '/?AJAXAction=true&CalendarDate=' + page + '&Section=' + this.options.Section;
			this.LoadContent( Attributes, this.Calendar, this.InterfaceSetup.bind(this) );
		}
	},
	
	SetPrevPage: function( page ) {		
		if( $(this.options.Calendar) ) {
			var Attributes = '/?AJAXAction=true&CalendarDate=' + page + '&Section=' + this.options.Section;
			this.LoadContent( Attributes, this.Calendar, this.InterfaceSetup.bind(this) );
		} 
	},

	initToolTips: function( ) {	
		var Tips1 = new Tips( $$( '.calendar_tips' ), { 
			initialize:function(){
				this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 300, wait: false}).set(0);
			},
			onShow: function(toolTip) {
				this.fx.start(1);
			},
			onHide: function(toolTip) {
				this.fx.start(0);
			}
		});
		/*
		$$('a.calendar_tips').each(function(element,index) {
			var content = element.get('title').split('::');
			element.store('tip:title', content[0]);
			//element.store('tip:text', content[1]);
			element.store('tip:text', '');
		});	
	
		var tipz = new Tips('.calendar_tips',{  
			className: 'calendar_tips',  
			fixed: false,
			hideDelay: 25,
			showDelay: 25
		});
		
		tipz.addEvents({
			'show': function(tip) {
				tip.fade('in');
			},
			'hide': function(tip) {
				tip.fade('out');
			}
		});
		*/
	}
	
});

CalendarPagination.implement(new Options);

// DOMReady
window.addEvent('domready', function(){
	var Pagination = new CalendarPagination();
});
