/**
 * @author Brandon Posner
 */

/***** Rotating Speed ******/

var holdSecs = 2;
var transSecs = 0.5;

/***************************/



var timerId = 0;
var pictures = null;
var currentPic = null;

function startSlideshow()
{
    pictures = document.getElementsByClassName('photo');
    if (pictures.length < 1) {return;}
    
    if (pictures.length == 1) {
        pictures[0].style.display = 'inline';
        return;
    }
    
    currentPic = 0;
    pictures[currentPic].style.display = 'inline';
    timerId = setTimeout("nextPicture()", holdSecs * 1000);
}

function stopSlideshow()
{
    clearTimeout(timerId);
}

function nextPicture()
{
    if (currentPic == null) {return;}
    if (pictures == null) {return;}
    
    var nextPic = currentPic + 1;
    if (nextPic >= pictures.length) nextPic=0;
    pictures[currentPic].style.zIndex = 1;
    pictures[nextPic].style.zIndex = 0;
    pictures[nextPic].style.display = 'inline';
    $(pictures[currentPic]).fade({duration:transSecs});
    currentPic = nextPic;
    timerId = setTimeout("nextPicture()",(holdSecs+transSecs) * 1000);
}

