$(document).ready(function(){
	$('#project_container').animate( { left:'6px' } , 1000)
});

var queue = 0;
var move_speed = 600;
var project_counter = 1;
/* UPDATE THIS WITH THE NUMBER OF PROJECTS */
var number_of_projects = 5;

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)
	{
		$('#project_container').animate( { left:'-274px' } , move_speed, "swing", function(){
			var this_project = document.getElementById("project_" + project_counter);
			//get parent variable too
			var this_parent_node = this_project.parentNode;
			//remove the node
			this_parent_node.removeChild(this_project);
			//add it to the end
			this_parent_node.appendChild(this_project);
			project_counter++;
			if(project_counter > number_of_projects)
			{
				project_counter = 1;
			}
			$('#project_container').css( { 'left':'6px' } );
			if(queue != 0) queue--;
			move_left();
		});
	}
}

function move_right()
{
	if(queue < 0)
	{
		var old_project_counter = project_counter;
		project_counter--;
		if(project_counter < 1)
		{
			project_counter = 5;
		}

		var this_project = document.getElementById("project_" + project_counter);
		//get parent variable too
		var this_parent_node = this_project.parentNode;
		//remove the node
		this_parent_node.removeChild(this_project);
		//add it to the end
		this_parent_node.insertBefore(this_project, document.getElementById("project_" + old_project_counter));

		$('#project_container').css( { 'left':'-274px' } );

		$('#project_container').animate( { left:'6px' } , move_speed, "swing", function(){

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