/** photo fader by puredesign.be **/
Array.prototype.shuffle = function (){
    var i = this.length, j, temp;
    if ( i == 0 ) return;
    while ( --i ) {
        j = Math.floor( Math.random() * ( i + 1 ) );
        temp = this[i];
        this[i] = this[j];
        this[j] = temp;
    }
};
$(function(){
    var fotoAmount = $("#fotofader img").size();
    var myFotos         = new Array();
    var bg_begin        = 0;
    var bg_current      = bg_begin;
    var bg_next         = 0;
    var fade_seconds    = 4000;  // 1 sec = 1000
    for(i=0;i<fotoAmount;i++){
        myFotos[i] = i;
    }
    myFotos.shuffle();
    $("#fotofader img:eq("+myFotos[0]+")").show();
    item_interval = setInterval(fadeNext,fade_seconds);
    
    function fadeNext(){
        if(bg_current==(fotoAmount-1)){
            bg_next = 0;
        }
        else{
            bg_next = bg_current+1;
        }
        $("#fotofader img:eq("+myFotos[bg_current]+")").fadeOut("slow");
        $("#fotofader img:eq("+myFotos[bg_next]+")").fadeIn("slow");
        
        bg_current = bg_next;
    }
});
