// =================================== //
// Bouncing Slideshow                  //
// v1.0 - May 14, 2006                 //
// ----------------------------------- //
// Created by Lloyd Hassell            //
// Website: lloydhassell.brinkster.net //
// Email: lloydhassell@hotmail.com     //
// =================================== //

// INITIALIZATION:

bouncingSlideshow = new Object();

// CONFIGURATION:

bouncingSlideshow.picturePath = '';
bouncingSlideshow.pictureSrc = new Array('01.jpg','02.jpg','03.jpg','04.jpg','05.jpg');

bouncingSlideshow.pictureWidth = 320;
bouncingSlideshow.pictureHeight = 240;

bouncingSlideshow.frameRate = 30;
bouncingSlideshow.speedX = 2;
bouncingSlideshow.speedY = 2;

// MAIN:

bouncingSlideshow.currentPicture = 0;
bouncingSlideshow.isLoaded = false;
bouncingSlideshow.winWidth = null;
bouncingSlideshow.winHeight = null;
bouncingSlideshow.pictureObj = new Array();
bouncingSlideshow.picturesLoaded = false;

if (dyn) bouncingSlideshow.pictureObj[0] = loadImg(bouncingSlideshow.picturePath + bouncingSlideshow.pictureSrc[0]);

function changePictureSrc() {
   bouncingSlideshow.currentPicture++;
   if (bouncingSlideshow.currentPicture == bouncingSlideshow.pictureSrc.length) bouncingSlideshow.currentPicture = 0;
   bouncingSlideshow.imgObj.src = bouncingSlideshow.pictureObj[bouncingSlideshow.currentPicture].src;
   }

function loadPictures() {
   bouncingSlideshow.picturesLoaded = true;
   for (var pictureLoop = 1; pictureLoop < bouncingSlideshow.pictureSrc.length; pictureLoop++) bouncingSlideshow.pictureObj[pictureLoop] = loadImg(bouncingSlideshow.picturePath + bouncingSlideshow.pictureSrc[pictureLoop]);
   }

function getWindowDimensions() {
   bouncingSlideshow.winWidth = getWinWidth();
   bouncingSlideshow.winHeight = getWinHeight();
   }

function loadBouncingSlideshow() {
   if (dyn && !bouncingSlideshow.isLoaded) {
      getWindowDimensions();
      bouncingSlideshow.dirX = (Math.round(Math.random()) == 0) ? 'left' : 'right';
      bouncingSlideshow.dirY = (Math.round(Math.random()) == 0) ? 'up' : 'down';
      bouncingSlideshow.posX = (bouncingSlideshow.winWidth - bouncingSlideshow.pictureWidth) / 2;
      bouncingSlideshow.posY = (bouncingSlideshow.winHeight - bouncingSlideshow.pictureHeight) / 2;
      bouncingSlideshow.layerObj = addLayer('bouncingSlideshowLayer');
      setLayerSize(bouncingSlideshow.layerObj,bouncingSlideshow.pictureWidth,bouncingSlideshow.pictureHeight);
      setLayerClip(bouncingSlideshow.layerObj,0,bouncingSlideshow.pictureWidth,bouncingSlideshow.pictureHeight,0);
      setLayerHTML(bouncingSlideshow.layerObj,getImgTag('bouncingSlideshowImage',bouncingSlideshow.pictureObj[bouncingSlideshow.currentPicture].src,bouncingSlideshow.pictureWidth,bouncingSlideshow.pictureHeight,0));
      moveLayerTo(bouncingSlideshow.layerObj,bouncingSlideshow.posX,bouncingSlideshow.posY);
      showLayer(bouncingSlideshow.layerObj);
      bouncingSlideshow.imgObj = getImgObj('bouncingSlideshowImage');
      }
   bouncingSlideshow.isLoaded = true;
   moveBouncingLayer();
   }

function moveBouncingLayer() {
   if (bouncingSlideshow.picturesLoaded == false) loadPictures();
   if (bouncingSlideshow.dirX == 'left') {
      if (bouncingSlideshow.posX > bouncingSlideshow.speedX) bouncingSlideshow.posX -= bouncingSlideshow.speedX;
      else {
         changePictureSrc();
         bouncingSlideshow.dirX = 'right';
         bouncingSlideshow.posX = 0;
         }
      }
   else if (bouncingSlideshow.dirX == 'right') {
      if (bouncingSlideshow.posX + bouncingSlideshow.pictureWidth < bouncingSlideshow.winWidth - bouncingSlideshow.speedX) bouncingSlideshow.posX += bouncingSlideshow.speedX;
      else {
         changePictureSrc();
         bouncingSlideshow.dirX = 'left';
         bouncingSlideshow.posX = bouncingSlideshow.winWidth - bouncingSlideshow.pictureWidth;
         }
      }
   if (bouncingSlideshow.dirY == 'up') {
      if (bouncingSlideshow.posY > bouncingSlideshow.speedY) bouncingSlideshow.posY -= bouncingSlideshow.speedY;
      else {
         bouncingSlideshow.dirY = 'down';
         bouncingSlideshow.posY = 0;
         }
      }
   else if (bouncingSlideshow.dirY == 'down') {
      if (bouncingSlideshow.posY + bouncingSlideshow.pictureHeight < bouncingSlideshow.winHeight - bouncingSlideshow.speedY) bouncingSlideshow.posY += bouncingSlideshow.speedY;
      else {
         bouncingSlideshow.dirY = 'up';
         bouncingSlideshow.posY = bouncingSlideshow.winHeight - bouncingSlideshow.pictureHeight;
         }
      }
   moveLayerTo(bouncingSlideshow.layerObj,bouncingSlideshow.posX + getDocScrollLeft(),bouncingSlideshow.posY + getDocScrollTop());
   window.setTimeout('moveBouncingLayer();',bouncingSlideshow.frameRate);
   }

window.onresize = getWindowDimensions;
window.onload = loadBouncingSlideshow;