/*
$(document).ready(function(){
	$('#video_container').animate( { left:'-304px' } , 1000)
});
*/

var queue = 0;
var move_speed = 600;
var video_counter = 1;
/* UPDATE THIS WITH THE NUMBER OF videoS */
var number_of_videos = 10;

function queue_left()
{
	if(queue < 0) queue = 0;
	else queue++;
	if(queue == 1)
	{
		move_left();
	}
}

function queue_right()
{
	if(queue > 0) queue = 0;
	else queue--;
	if(queue == -1)
	{
		move_right();
	}
}

function move_left()
{
	if(queue > 0)
	{
		$('#video_container').animate( { left:'-456px' } , move_speed, "swing", function(){
			var this_video = document.getElementById("video_" + video_counter);
			//get parent variable too
			var this_parent_node = this_video.parentNode;
			//remove the node
			this_parent_node.removeChild(this_video);
			//add it to the end
			this_parent_node.appendChild(this_video);
			video_counter++;
			if(video_counter > number_of_videos)
			{
				video_counter = 1;
			}
			$('#video_container').css( { 'left':'-304px' } );
			if(queue != 0) queue--;
			move_left();
		});
	}
}

function move_right()
{
	if(queue < 0)
	{
		var old_video_counter = video_counter;
		video_counter--;
		if(video_counter < 1)
		{
			video_counter = number_of_videos;
		}

		var this_video = document.getElementById("video_" + video_counter);
		//get parent variable too
		var this_parent_node = this_video.parentNode;
		//remove the node
		this_parent_node.removeChild(this_video);
		//add it to the end
		this_parent_node.insertBefore(this_video, document.getElementById("video_" + old_video_counter));

		$('#video_container').css( { 'left':'-456px' } );

		$('#video_container').animate( { left:'-304px' } , move_speed, "swing", function(){

			if(queue != 0) queue++;
			move_right();
		});
	}
}
