//**********************************************************************************************************************************
// Fader By D@#
// 02.06.09
// richiede jquery
// Compatibile con Chrome Firefox 2/3 IE6/7 e Opera
//**********************************************************************************************************************************
// Utilizzo : 
//      riempire l'array ph_arr con le immagini da visualizzare
//**********************************************************************************************************************************

var TIMEOUT=5000;
var FADEOUT=1500;

var ph_arr; //da riempire 
var ph_ind=1; //da cambiare se random
var ph_act=0;

function debugVar(){
    $('div#debug').text('');
    $('div#debug').append('active ->' + ph_act + '<br>');
    $('div#debug').append('ph_ind -> '+ ph_ind +'<br>');
    $('div#debug').append('<hr>');

}           

function changePhoto(img){
    var ph_dim=ph_arr.length; 
    $(img).attr('src',ph_arr[ph_ind]);
    //$(img + 'a').attr('href',ph_arr[ph_ind]);
    ph_ind=((ph_ind+1)%ph_dim);
    //return true;
};


function goFader() {
    var next_act = ((ph_act+1)%2);

    $('#img'+ph_act).addClass('last-active');
    $('#img'+next_act).css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, FADEOUT, function() {
            $('#img'+ph_act).removeClass('active last-active');
            changePhoto('#img'+ph_act);
            //debugVar();
            ph_act=next_act;
        });
    setTimeout( "goFader()", TIMEOUT );
}

$(function() {
    debugVar();
    setTimeout( "goFader()", TIMEOUT );
});