$(document).ready(function(){
    slideShow();
});

function slideShow(){

    $('#gallery a').css({opacity: 0.0});
    $('#gallery a:last').css({opacity: 1.0});

    setInterval('gallery()',8000);
}

function gallery(){   

    var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));
    var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));
    var caption = next.attr('rel');

    next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
    current.animate({opacity: 0.0}, 1000).removeClass('show');

    $("#" + current.attr('id') + "h").removeClass('show');
    $("#" + next.attr('id') + "h").addClass('show');

    txt = current.attr('id').split('fimg');
    nrc = parseInt(txt[1]);
    nrp = nrc - 1;

    if(nrp < 1){
    	nrp = 3;
    }

    txt = caption.split('|');
    $('#ft_0').html('<a href="' + txt[1] + '">' + txt[0] + '</a>');

    txt = $('#fimg' + nrp).attr('rel').split("|");
    $('#ft_1').html('<a href="' + txt[1] + '">' + txt[0] + '</a>');

    txt = current.attr('rel').split("|");
    $('#ft_2').html('<a href="' + txt[1] + '">' + txt[0] + '</a>');
} 
