var posicionsX = [];
var posCarrusel = 0;
var endCarrusel = false;

$(document).ready(function()
{	
	
	var carruselWidth = 0;
	for (x = 0; x < posicionsX.length; x++) carruselWidth += posicionsX[x];
	
	$("#showcase-left").css('display','none');
	$("#showcase-left").css('opacity','0');
	//$("#showcase-right").css('display','block');
	$("#showcase-right").css('opacity','.6');
	
	$(function() {
		
		$('#showcase-right').hover(function(){
			$(this).stop().animate({opacity:'.9'},{queue:false,duration:100});
		}, function(){
			$(this).stop().animate({opacity:'.6'},{queue:false,duration:100});
		});
				
		$('#showcase-left').hover(function(){
			$(this).stop().animate({opacity:'.9'},{queue:false,duration:100});
		}, function(){
			$(this).stop().animate({opacity:'.6'},{queue:false,duration:100});
		});
		
		$('#showcase-right').click(function(){
			
			
			if(endCarrusel)
			{
				posNova = 0;
				posCarrusel = 0;
				endCarrusel = false;
				$('#showcase-left').animate({opacity:'0'},{queue:false,duration:100});
				$("#showcase-left").css('display','none');
			}
			else
			{
			
				posCarrusel++;
			
				posNova = 0;
				for (x = 0; x <= posCarrusel-1; x++)
				{
					posNova += posicionsX[x];
				}
			
				if ((posNova + parseInt($("#showcase").css('width'))) >= carruselWidth)
				{
					posNova = carruselWidth - parseInt($("#showcase").css('width'));
					endCarrusel = true;				
				}
				
				posNova = posNova * -1;

				if ($("#showcase-left").css('display') == "none")
				{
					$("#showcase-left").css('display','block');
					$('#showcase-left').animate({opacity:'.6'},{queue:false,duration:100});
				}
			
			}
			
			$('#carrusel').animate({marginLeft:posNova},{queue:false,duration:500});			
			
		});
		
		$('#showcase-left').click(function(){
			
			posCarrusel--;
			
			posNova = 0;
			for (x = 0; x <= posCarrusel-1; x++)
			{
				posNova += posicionsX[x];
			}
			posNova = posNova * -1;
			
			$('#carrusel').animate({marginLeft:posNova},{queue:false,duration:500});			
			
			if (posNova == 0)
			{				
				$('#showcase-left').animate({opacity:'0'},{queue:false,duration:100});
				$("#showcase-left").css('display','none');
			}
			
			if ($("#showcase-right").css('display') == "none")
			{
				$("#showcase-right").css('display','block');
				$('#showcase-right').animate({opacity:'.6'},{queue:false,duration:100});
			}
			
		});
				
		$('.showcase-content-wrapper').hover(function(){
			$(this).find('#sample').stop().animate({opacity:'.3'},{queue:false,duration:350});
		}, function(){
			$(this).find('#sample').stop().animate({opacity:'1'},{queue:false,duration:350});
		});
		
	});

});
