var currentPhoto = 0;

$(document).ready(function() {		
    $(".photo-holder").removeClass("show");
    
    $(".choose-photo").click(function(){
        var id = $(this).attr("rel");
        
        showPhoto(id);
        
        return false;
    });
    
    //showPhoto(currentPhoto);
    rotatePhotos();
});

function showPhoto(id)
{
    $(".photo-holder").removeClass("show");
    $(".photo-button").removeClass("active");
    
    $("#photo-" + id).addClass("show");
    $("#button-" + id).addClass("active");

    //Set the opacity to 0 and height to 1px
    $('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	

    //Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
    $('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '75px'},500 );
    
    $(".caption .content").html($("#photo-" + id).children("img").attr("rel"));
}

function rotatePhotos() {
    showPhoto(currentPhoto);
    
    if((currentPhoto) >= $(".choose-photo:last").attr("rel")) {
        currentPhoto = 0;
    } else {
        currentPhoto++;
    }
    
    window.setTimeout(rotatePhotos, 5000);
}
