// (c) 2007 Loco (Loohuis Consulting), http://www.loohuis-consulting.nl/
// This work is licensed under a 
// Creative Commons Attribution-Share Alike 3.0 Netherlands License
// see http://www.loohuis-consulting.nl/development/cc-by-sa.php

// settings
var imgCount;
var currentImg = 1;
var imgInterval = 4;
var animator;

// initialize homepage image animation
function initAnim()
{
    var imgs = document.getElementsByClassName('animate', 'animation');
    imgCount = imgs.length;
    animator = new PeriodicalExecuter(swapImgs, imgInterval);
}

// animate images
function swapImgs()
{
    var swapIn = currentImg + 1;
    if (swapIn > imgCount)
        swapIn = 1;
    new Effect.Fade('anim' + currentImg);
    new Effect.Appear('anim' + swapIn);
    currentImg = swapIn;
}

// initialise page
function init()
{
    if ($('animation'))
        initAnim();
}

Event.observe(window, 'load', init);