$(document).ready(function(){

	// count the show trailers
	var total_shows = $('div.bzl_prev_shows ul.show_list li').length;

	// if there are more than 6 trailers, we want custom navigation
	if (total_shows > 6)
	{
		scrollVideoTrailers(total_shows, '#shows_next_arrow', '#shows_prev_arrow', 'ul.show_list', 104, 6);
	}
	
	
	// count the show trailers
	var total_prev_shows = $('div.previous_shows ul.prev_show_list li').length;
	
	// if there are more than 3 trailers, we want custom navigation
	if (total_prev_shows > 3)
	{
		scrollVideoTrailers(total_prev_shows, '#shows_next_arrow_lg', '#shows_prev_arrow_lg', 'ul.prev_show_list', 327, 3);
	}
	
	
	$('.bz_livebrowser li a:not(.comingsoon)').click(function(){
		var vid = $(this).attr("trailer-url");
		playTrailer(vid, 'true');

		$('.bz_livebrowser li.active').removeClass('active');
		$(this).parent().addClass('active');

		return false;
	});

	$('div.bz_livebrowser li.available').hover( function(){
		$(this).children('div.over_arrow').css('display', 'block');
	},
	function(){
		$(this).children('div.over_arrow').css('display', 'none');
	});
	
	
	$('#shows_prev_arrow').fadeOut();
	
	$('div.play').click(function(){
		window.location = "http://www.brazzers.com/tour3/?action=join";
	});

});



/**
*
*  Function to allow for trailer navigation
*  @param   total_trailers  trailer count
*  @param   next_arrow      identify the next arrow object
*  @param   prev_arrow   	identify the previous arrow object
*  @param   list		    identify the list object
*
**/
function scrollVideoTrailers(total_trailers, next_arrow, prev_arrow, list, distance, max_item) {

	var current_pos = 0;

	$(next_arrow).show();

	$(next_arrow).click(function() {

		if ((max_item + current_pos) < total_trailers)
		{

			current_pos++;
			$(list).animate({"left": "-="+distance+"px"}, "slow");

			if ((max_item + current_pos) == total_trailers)
			{
				$(this).fadeOut();
			}
			if ($(prev_arrow).is(':hidden'))
			{
				$(prev_arrow).fadeIn();
			}
		}
	});

	$(prev_arrow).click(function() {

		if (current_pos > 0)
		{
			current_pos--;
			$(list).animate({"left": "+="+distance+"px"}, "slow");

			if (current_pos == 0)
			{
				$(this).fadeOut();
			}
			if ($(next_arrow).is(':hidden'))
			{
				$(next_arrow).fadeIn();
			}
		}
	});
}
