var imageurl = "";

function initializeHeader(url) {
    imageurl = url;
    /*
    $("#colorbar").click(function(){    
        reloadPhotos(url);
    });
    */
    
    setTimeout('reloadPhotos()', 5000);    
}

function reloadPhotos() {
    
    /* get new random images */
    $.ajax({
        url: imageurl,
        dataType: 'json',
        success: function(data){            
            if ( data != ''){                
                /* animate */
                $(".cover").each(function(index, element){
                    var id = $(element).attr("id");
                    $(element)
                        .delay((id-1)*75)
                        .animate({opacity:1.0}, 300, function(){                            
                            // swap image
                            $(".foto[id='"+id+"']").attr('src', data[id-1]);                            
                            // fade in
                            $(element).animate({opacity:0.0}, 300);
                        });
                });
                setTimeout('reloadPhotos()', 10000);
            }
        }
    });
}
