// Featured Event Initialization
$(document).ready(function() {
	featured_event_pagination_init();
});

var featured_event_index = 0;
var featured_event_override = false;
function featured_event_pagination_init() {
	//console.log('featured_event_pagination_init()');
	if (ary_featured_events.length > 1)
		setTimeout("featured_event_timer(" + (featured_event_index + 1) + ", false)", 10000);
}

// Timer function - Loads the Featured Event by the given index
// if the viewer hasn't overriden the timer by manually controlling
// the pagination (clicking the left or right arrows)
function featured_event_timer(index) {
	if (!featured_event_override)
		featured_event_load(index, false);
}

// Load a Featured Event
function featured_event_load(index, override) {
	featured_event_index = index;
	
	$('.featured_content').css('background', 'url(' + decodeURIComponent((ary_featured_events[index][3]+'').replace(/\+/g, '%20')) + ') no-repeat 0 0');
	$('.featured_content').css('background-position', 'center');
	$('.featured_event_date span').text(ary_featured_events[index][4]);
	$('.featured_event_title span').text(ary_featured_events[index][1]);
	$('.featured_event_desc span').text(ary_featured_events[index][2]);
	$('.featured_event_get_tickets a').attr('href', decodeURIComponent((ary_featured_events[index][5]+'').replace(/\+/g, '%20')));
	
	if (index == 0)
		$('.featured_event_pagination').css('background', 'url(../../img/newsite/newsite_feature_pagination.png) no-repeat 0 0');
	else if (index == 1)
		$('.featured_event_pagination').css('background', 'url(../../img/newsite/newsite_feature_pagination.png) no-repeat 0 -24px');
	else if (index == 2)
		$('.featured_event_pagination').css('background', 'url(../../img/newsite/newsite_feature_pagination.png) no-repeat 0 -48px');
	else if (index == 3)
		$('.featured_event_pagination').css('background', 'url(../../img/newsite/newsite_feature_pagination.png) no-repeat 0 -72px');
	
	if (!override) {
		var next_index = featured_event_index + 1
		if (next_index == ary_featured_events.length)
			next_index = 0;
		
		setTimeout("featured_event_timer(" + (next_index) + ")", 10000);
	}
}

// Load the previous Featured Event (called when a viewer clicks the left arrow)
function featured_event_previous() {
	featured_event_override = true;
	if (ary_featured_events.length > 1) {
		var prev_index = featured_event_index - 1;
		if (prev_index < 0)
			prev_index = ary_featured_events.length - 1;
			
		featured_event_load(prev_index, true);
	}
}

// Load the next Featured Event (called when a viewer clicks the right arrow)
function featured_event_next() {
	featured_event_override = true;
	if (ary_featured_events.length > 1) {
		var next_index = featured_event_index + 1;
		if (next_index >= ary_featured_events.length)
			next_index = 0;
			
		featured_event_load(next_index, true);
	}
}
