images = new Array();
images_counter=0;

function image_loaded(img) {
    // skanky workaround for misc browser bugs
//    if (!img.complete)
//        return false;

    if (typeof img.complete !="undefined" && !img.complete)
        return false;

    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0)
        return false;

    return true;
}


function start_slideshow() {
    photos = getElementsByTagAndClassName('img', 'slideshow-image', $('slideshow-container'));
//    photos[0].style.zIndex=1;
    for (i=0;i<photos.length;i++) {
        images.push(photos[i]);
	photos[i].title="";
    }
    setTimeout("advance_slideshow();", 5000);
}

function advance_slideshow() {
    new_images_counter = images_counter+1;
    if (new_images_counter>images.length-1) {
        new_images_counter=0;
    }
    if (image_loaded(images[new_images_counter])) {
        prev_images_counter = images_counter;
        images_counter = new_images_counter;
        images[prev_images_counter].style.zIndex=100;
        images[images_counter].style.zIndex=90;
        Opacity(images[images_counter], {"from":0.9, "to":1, "queue":'before', "duration":0.1});
        $('slideshow-image-caption').innerHTML=images[images_counter].getAttribute("alt") + " &nbsp;&nbsp;("+(1+images_counter)+" of "+images.length+")";
//        $('slideshow-image-caption').innerHTML=images[images_counter].getAttribute("alt");
        Opacity(images[prev_images_counter], {"from":1, "to":0, "queue":"before", "fps":15});
	images[prev_images_counter].zIndex=80;
    }
    setTimeout("advance_slideshow();", 5000);
}

addLoadEvent(start_slideshow);


