/**
 * Create an instance of FeaturedEventViewer
 * @classDescription	Featured Event Viewer
 * @return {FeaturedEventViewer} Return a new instance of FeaturedEventViewer
 * @constructor
 */
function FeaturedEventViewer(content) {
	this._content = content;
}

FeaturedEventViewer.prototype = {
	/**
	 * Reference to VCMContent
	 * @type {VCMContent}
	 */
	_content: null,
	/**
	 * Reference to a jquery cycle
	 * @type {Object}
	 */
	_cycle: null,
	/**
	 * jQuery reference to events link
	 * @type {jQuery}
	 */
	_events: null,
	/**
	 * jQuery reference to the navigation
	 * @type {jQuery}
	 */
	_navigation: null,
		
	/**
	 * Initialize the viewer
	 */
	init: function() {
		console.log('FeaturedEventViewer.init()');
		this._events = $('.featured_title,.featured_date,.btn_ensavoirplus,.featuredImageLink');
		this._navigation = $('#navigation');
		this._cycle = $('#featuredEvents').cycle({
			fx: 			'fade',
			pause:			1,
			timeout: 		5000,
			pager:  		'#navigation',
	        startingSlide:	0,
			pagerAnchorBuilder: function(i, el){
				return '#navigation a:eq(' + i + ')';
			}
		});
		// Construct the navigation
		var me = this;		
		this._cycle.children().each(function(i) { 
	        $('<a href="#" class="'+(i==0?'activeSlide':'')+'">'+(i+1)+'</a>') 
	            .appendTo(me._navigation).click(function() { 
	            	me._cycle.cycle(i); 
	                return false; 
	        }); 
	    });
		// Add event
		this._events.click($.proxy(this, 'onEventClick'));
	},
	
	/**
	 * Destroy
	 */
	destroy: function() {
		console.log('FeaturedEventViewer.destroy()');
		// Remove event
		this._events.unbind('click');
		
		this._cycle.cycle('destroy');
		this._cycle = null;
		this.events = null;
		this._navigation.empty();
		this._navigation = null;
	},

	/**
	 * On event click
	 * @param evt {Object} The Event object
	 */	
	onEventClick: function(evt) {
		console.log('FeaturedEventViewer.onEventClick()');
		this._content.showEvent(VCMUtils.findNumber($(evt.currentTarget).attr('id')));
		return false;
	}
};


