﻿var fadeDuration = 500;
var photoWait = 5000;
var imageIntervalID;
var activeItem;
var timer=10000;

function SetUpInterval() {
    imageIntervalID = setInterval("SlideSwitch('next')", photoWait);
}


function SlideSwitch(direction) {
    var newItem;
    var next = activeItem.next();
    var prev = activeItem.prev();

    if (direction == "next") {
        if (next.length) {
            newItem = next;
        }
        else {
            newItem = $("#slideshow .productionItem:first");
        }
    }
    else {
        if (prev.length) {
            newItem = prev;
        }
        else {
            newItem = $("#slideshow .productionItem:last");
        }
    }

    newItem.fadeIn(fadeDuration);
    activeItem.fadeOut(fadeDuration);
    activeItem = newItem;
}

function PreviousClick(item) {
    if (imageIntervalID) {
        clearInterval(imageIntervalID);
    }
    SlideSwitch("previous");
    SetUpInterval();
}

function NextClick(item) {
    if (imageIntervalID) {
        clearInterval(imageIntervalID);
    }
    SlideSwitch("next");
    SetUpInterval();
}




function PauseClick(item) {

    $("#btnPlay").show();
    $("#btnPause").hide();
    clearInterval(imageIntervalID);
    return false;
    }


function PlayClick(item) {
    $("#btnPlay").hide();
    $("#btnPause").show();
    SetUpInterval();
    return false;
    }

$(document).ready(function() {
    $("#slideshow .productionItem").hide();
    activeItem = $("#slideshow .productionItem:first");
    activeItem.show();
    SetUpInterval();
});







