// global vars
var loadedImages = [];
// domready
window.addEvent("domready", function(){

});

// onload
window.addEvent("load", function(){
    // Slideshow
    if($defined($("slideshow"))){
        var images = [],imageCount=15;
        var path = "/media/slideshow/manufacturing_";
        // Set and load images
        for(var i=0; i< imageCount; i++){
            images[i] = path + (i+1) + ".jpg";
            new Asset.image(images[i], {onload:function(){if(this.height > 0){  loadedImages.push(this);} }});
        }
        doSlideshow.delay(2500, null, [$("slideshow")]);
    }
});

/* Function */

// generic Slideshow
var doSlideshow = function(container, index){
    var img = container.getFirst("img");
    if(!$defined(index)){
        index = 0;
        loadedImages.push(img.clone());
    }
    if(img.src != loadedImages[index].src){
        loadedImages[index].fade('hide');loadedImages[index].set('class', 'slide');
        loadedImages[index].inject(img, "after");
        img.fade(0);
        loadedImages[index].fade(1);
        //img.set.delay(800, img, ["src", loadedImages[index].src]);
        //var change = function(){loadedImages[index].replaces(img)}
        //change.delay(800);
        var change = function(){img.dispose()}
        change.delay(500);
        //loadedImages[index].fade.delay(1000, loadedImages[index], 1);
    }
    if(loadedImages.length-1 > index) doSlideshow.delay(3000, null, [container, index+1]);
    else doSlideshow.delay(3000, null, [container, 0]);
}

// dump a element
var dump = function(element){
    var props = "Element: ";
    new Hash($(element).attributes).each(function(value, key){
        props = props + " "+key+": "+value+";";
    });
    alert(props);
}

