var JIss_timer;
var JIss_obj;
var JIss_slid;
var JIss_mod;
var JIss_pos;
var JIss_path;
var JIss_imgid;
var JIss_front = 1;
var JIss_back  = 0;
var JIss_anim;

var JIss_handleSuccess = function(o)
{
    if(o.responseText !== undefined)
        JIss_obj = eval("(" + o.responseText + ")");

    JIss_slid = new Array(YAHOO.util.Dom.get(JIss_imgid[0]), YAHOO.util.Dom.get(JIss_imgid[1]));
    JIss_mod  = JIss_obj.images.length;
    JIss_pos  = 0;

    JIss_anim = new YAHOO.util.Anim(JIss_slid[JIss_front], { opacity: { to: 1 } }, 0.9, YAHOO.util.Easing.easeIn);
    JIss_anim.onComplete.subscribe(JIss_transitionComplete);

    JIss_showNext(true);
}

var JIss_handleFailure = function()
{
    alert("Slideshow did not start.");
}

var JIss_callback =
{
    success: JIss_handleSuccess,
    failure: JIss_handleFailure
};

function JIss_transitionComplete()
{
    // copy the displayed to the background, and hide the top.
    JIss_slid[JIss_back].src = JIss_slid[JIss_front].src;
    YAHOO.util.Dom.setStyle(JIss_slid[JIss_front], "opacity", 0);

    // increment, and queue up to refresh...
    JIss_pos = (JIss_pos+1) % JIss_mod;
    window.setTimeout("JIss_showNext(false)", JIss_timer);
}

function JIss_showNext(initialize)
{
    JIss_slid[JIss_front].src = "http://www.saintalsseattle.org" + JIss_path + "/" + JIss_obj.images[JIss_pos];
    // lookahead/preload the next image:
    var image = new Image();
    image.src = "http://www.saintalsseattle.org" + JIss_path + "/" + JIss_obj.images[(JIss_pos+1)%JIss_mod];

    if ( initialize )
        JIss_transitionComplete();
    else
        JIss_anim.animate();
}

function JIss_start()
{
    YAHOO.util.Connect.asyncRequest('GET', 'http://www.saintalsseattle.org/sshow.php?path=' + JIss_path, JIss_callback); 
}

function JIss_setup(path, imageId0, imageId1)
{
    JIss_setup2(path, imageId0, imageId1, 2500);
}

function JIss_setup2(path, imageId0, imageId1, timer)
{
    JIss_timer = timer;
    JIss_path  = path;
    JIss_imgid = new Array(imageId0, imageId1);
    JIss_start();
}
