/* javascript that controls the splash animation big images.
   uses spry framework */
   
// load up all the splash images here. new ones, just push onto the end of the array
window.splashImages = Array('images/splash_rot/kitchen.jpg','images/splash_rot/brick.jpg','images/splash_rot/yellowroom.jpg','images/splash_rot/kitchen2.jpg','images/splash_rot/Master-bath.jpg','images/splash_rot/nebraska-kitchen1.jpg','images/splash_rot/Utility-room.jpg','images/splash_rot/Exterior-smaller.jpg','images/splash_rot/Bath-detail.jpg');

// keep track of which images you've preloaded
window.preloadedImages = Array();  

// will be used to store the fade up and fade down effects (Spry 1.6)
var fadeUp;
var fadeDown;
   
/* this function kicks off the splash animation */
function startSplashImageAnim(delay){
  //setTimeout('nextSplashImageAnim(0)',10000);
  //preLoadImages(splashImages[1]); // anticipates the next image to be swapped in
  
  setTimeout('nextSplashImageAnim(0)',delay);
  MM_preloadImages(splashImages[1]);

}

/* this function controls the movement of the splash image rotation feature */
function nextSplashImageAnim(i){

  i++; if(i>splashImages.length-1)i=0;
  
  // swap the new image in
  switchSplashImage(splashImages[i]);
  
  // adjust the delay between image switches by changing the parameter below
  //  which is # milliseconds (1000 = 1 second)
  setTimeout('nextSplashImageAnim('+i+')',5000);
  
  // preload the next image, in preparation for the next switch
  if((!preloadedImages[i+1]) && splashImages[i+1]){
    im = new Image(); im.src = splashImages[i+1];
    preloadedImages[i+1]=true;
  }
  
}

/* this function controls the show/hide of images
   on the splash page */
window.next_image_splash='';
function switchSplashImage(url){
  
  /* the following will produce a pleasing fade-in/fade-out effect */

  if(!document.images) return;
  d=document['SplashImage'];
  if(!d) return;
  
  // if we are on the same image, don't bother with the effects
  if(window.next_image_splash==url) return;
  
  // do a quick preload of the next image in preparation
  // this will help a little, as it begins loading the next image while the 
  // current image fades out.
  //im = new Image(); im.src=url;

  // this window variable is set because it is needed in showImage_next()
  window.next_image_splash=url;
  
  // fade out current and trigger next show    
  // the first parameter controls the speed by which the image disappears, in milliseconds
  //Spry.Effect.AppearFade('SplashImage', {duration: 1500, from: 100, to: 0, toggle: false, finish: showSplashImage_next});
  if(!fadeDown){
     fadeDown = new Spry.Effect.Fade('SplashImage', {duration: 1000, from: 100, to: 0, toggle: false, finish: showSplashImage_next});
  }
  fadeDown.start();

  
}

/* helper function works in concert with showImage() to reveal the "next" image
   in the rotation */
function showSplashImage_next(element,effect){
  element.src=window.next_image_splash; // sets the next image  
  
  // duration is # milliseconds for the new image to appear
  //Spry.Effect.AppearFade('SplashImage', {duration: 1500, from: 0, to: 100, toggle: false});
  if(!fadeUp){
    fadeUp = new Spry.Effect.Fade('SplashImage', {duration: 1000, from: 0, to: 100, toggle: false});
  }
  fadeUp.start();
}
   