var image_loc = '/media/uploads/';
var rotate_delay = 7000;
$(function() {
	$('#featured-video-list li a').click(function() {
		var id = $(this).attr('rel');
		
		if (id.substr(0, 3) == 'pod') {
			$.getJSON('/home/pod_video/'+id.substr(4), function(data) {
				setVideo(data.video.video_file, data.series.image, '/media/uploads/podcasts/');
			});
		} else {
			$.getJSON('/home/ajax/'+id, function(data) {
				setVideo(data.video, data.image);
			});
		}
	});
	$('#featured-video-list li a:first').click();

	$('#upcoming-event-list li a').click(function() {
		var id = $(this).attr('rel');
		
		clearTimeout(rotateTimer);
		$.getJSON('/home/events/'+id, function(data) {
			var tab_box = $('#tab-box-masthead');
			
			$('img', tab_box).attr('src', image_loc+data.image);
			$('h1', tab_box).html(data.title);
			$('#info-box', tab_box).html('<p>'+data.description+'</p><p><a href="'+data.link+'" id="more-info">[Find Out More]</a></p>');
		});
	});
	
	num_features = $('#upcoming-event-list li').length;
	rotateTimer = setTimeout('rotate_features()', rotate_delay);
});

var cur_feature = 0;
function rotate_features() {
	if (cur_feature < num_features - 1) {
		cur_feature++;
	} else {
		cur_feature = 0;
	}
	$('#upcoming-event-list li:eq('+cur_feature+') a').click();
	
	rotateTimer = setTimeout('rotate_features()', rotate_delay);
}

