﻿// Instantiate the CoverFlow by pointing it at a DIV that contains IMGs...
var MyCoverFlowDiv = document.getElementById(portfolioDivId);
var cf = new CoverFlow(MyCoverFlowDiv, ImageWidth, ImageHeight, CoverFlowWidth, "#fff", ccc);

$(document).ready(function() {
    $("#PortfolioLinks").hide();
    update();
    setTimeout("slideshow()", SlideDuration);
    setTitle(0);
});

// This is called when a cover is clicked on.
function ccc (c) {
    if(c.CoverIndex == currentPos) document.location.href = links[c.CoverIndex];
    setTitle(c.CoverIndex);
    currentPos = c.CoverIndex;
}

// Schedule the CoverFlow Update method.
function update () {
    cf.Update();
    setTimeout("update()", 20);
}

function slideshow () {
    if (cf.targetPos < cf.Covers.length - 1) { // not on the last cover so scroll ahead one and pause for duration
	    cf.Flip(1);
	    setTimeout("slideshow()", SlideDuration);
	    setTitle(cf.targetPos);
	    currentPos = cf.targetPos;
    } else { // we were at the end so jump to beginning and pause for double duration
	    cf.GotoFirst();
	    setTimeout("slideshow()", SlideDuration * 2);
	    setTitle(0);
    }
}

function setTitle(position) {
    var MyTitleLink = document.getElementById(portfolioTitleId);
    MyTitleLink.innerHTML = "<a href='" + links[position] + "'>" + titles[position] + "</a>";
}
