/* GLOBAL */

var detailsRotationInterval = false; // value that will be the interval id for the rotation of the details blocks


/*
	HOME PAGE
*/
// DISPLAY THE FIRST ITEM


$(document).ready(function() {
	// ACTIVATE THE FIRST ITEM
	$('#featured_show_details').children('.one_show_details:first-child').show();
	$('#featured_show_listing').children('.featured_show:first').addClass('over');
	
	// setup the click events for the right side links
	$(".featured_show").click(function (e, d) {
		if(!d){
			if (detailsRotationInterval) {
				clearInterval(detailsRotationInterval);
				detailsRotationInterval = false;
			}
		}
		switchToMe(this);
		return false;
	});
	
});


function highlightNextItem () {
	
	$(".featured_show").each(function (i) {
		if ($(this).hasClass("over")) {
			$(this).next().click();
		}
	});
	
}

/**
* Traverse the "featured_show" classed elements and find the one that is the target
* passed to the function. For every one that isn't, remove the "over" class. For the
* proper one, add the over class.
* When the proper one is found, use its index to show the left details block that corresponds
* and hide those that don't
*/
function switchToMe(targ) {

	
	
	$(".featured_show").each(function (i) {
		
		if (this != targ) {
			
			$(this).removeClass("over");
		
		} else {
			
			$(this).addClass("over");
			
			$(".one_show_details").each ( function (v) {
				if (i != v) {
					$(this).css("display", "none");
				} else {
					$(this).css("display", "block");
				}
			});

		}
	});
	
}
 
function getNextFeaturedShow () {
	
	var targ;
	$('.featured_show').each(function (i) {
	
		if ($(this).hasClass('over')) {
			if (i != $(".featured_show").length-1) {
				targ = $(this).next();
			} else {
				targ = $('.featured_show:first');
			}
			
		}
		
	});
	targ.trigger('click', [true]);
}


detailsRotationInterval = setInterval(getNextFeaturedShow, 4000);

