var actProduct = 1;

$(function() {
	$("#slideLeft").click ( function ()
	{
		productSlider ("prev", 500);
	});
	$("#slideRight").click ( function ()
	{
		productSlider ("next", 500);
	});
	
	sliderHeight = $("#contentSlider").height ();
	
	
	$("#positionContainer").css ("height", $(document).height()-25);
	
	
	var i = 0;
	$(".contentItem").each(function()
	{
		i++;
		if (i == actProduct)
		{
			$(this).find ("img").load ( function () 
			{
				
				
			
				if ($(this).height () < 250)
				{
					newHeight = $(this).height ()+250;
				}
				else
				{
					newHeight = $(this).height ()+250;
				}
				
				/*
				$("#contentSlideContainer").height (newHeight);
				*/
				
			} );
			
		}
	} );
	
});


function productSlider(todo, speed)
{	

	var jumpTo = arguments[2];

		
	productCount = $("#contentSlider .contentItem").size();
	
	var position;
		
	if (todo == "next")
	{
		actProduct = actProduct + 1;
	}
	else 
	{
		if (actProduct == 1)
		{
			actProduct = productCount;
		}
		else
		{
			actProduct = actProduct - 1;
		}
	}
	
	if (actProduct <= 0)
	{
		actProduct = productCount;
	}
	else if (actProduct > productCount)
	{
		actProduct = 1;
	}	
	
	
	var i = 0;
	$(".contentItem").each(function()
	{
		i++;
		if (i == actProduct)
		{
			/*$("#contentSlideContainer").height ($(this).height ());*/
		}
	} );
	
	
	position = (actProduct*$(".contentItem").width())-$(".contentItem").width();
	
	$("#contentSlider").animate({ 
		left: "-" + position + "px"
	  }, speed, "swing" );
	
}

function goToProduct(id, speed)
{	
		
	var actProduct = id;
	
	
	var i = 0;
	$(".contentItem").each(function()
	{
		i++;
		if (i == actProduct)
		{
			$("#contentSlideContainer").height ($(this).height ());
		}
	} );
	
	
	position = (actProduct*$(".contentItem").width())-$(".contentItem").width();
	$("#contentSlider").animate({ 
		left: "-" + position + "px"
	  }, speed, "swing" );
	
}
