itens = new Array();
counter = 0;
tempo = 0;
ativo = "";

$(function()
{
    $(".thumbs .content a.master").each(function(){
        itens.push($(this)); 
    });
    
    $(".thumbs .content a.master").click(function(e){
        e.preventDefault();
        animaLegenda($(this));
        
        clearInterval(tempo);
        tempo = setInterval(autoAnimate, 8000);
    });
    
    tempo = setInterval(autoAnimate, 8000);
    counter = 1;
    ativo = $("#legenda .ativo");
});

function autoAnimate()
{

    if(itens.length <= counter){
        counter = 0;
    }
	

   	animaLegenda(itens[counter++]);
}	

function animaLegenda(object)
{
    if(ativo != ""){
        $(ativo).animate({
            width : 85
        }, 500);
    }
    
    $("#destaque #img").fadeOut("slow", function() {changeImg(object) });

    $(object).parent().parent().animate({
        width : 250
    }, 500);
    
    ativo = $(object).parent().parent();
}

function changeImg(img)
{
    img = $(img).attr("item");
   
    $("#destaque #img img").css({
		display	: "none"
	});
	
	$("#destaque #img img."+img).css({
		display	: "block"
	});
    
	$("#destaque #img").fadeIn("slow");
}

