// ----------------------------------------------------------------------------------------------------
/*

   Version: DVF v2.1.110521

   Program: vnd_home.js

   Author:  James Whitfield
   Date:    1 January 2009

   Description:
   Home page effects.

   Amendments:

   12/03/09  Added 'SelectPath' for revamped welcome page.
   23/07/10  Included new slide show functions.
   23/10/10  Conversion for new website.
   10/11/10  Standardisation of websites and added 'Shorlist' to 'SelectPath'.
   15/05/11  Included 'AllVillas' for 'SelectPath'.
   21/05/11  Included code to stop oversized slide-show pictures.  Removed community fade code.

*/
// ----------------------------------------------------------------------------------------------------

// ====================================================================================================
// Swap the welcome and welcome-selected graphics on the home pages.
// ====================================================================================================

function SelectPath(thisid, picsrc) {
  tblid= document.getElementById("id" + thisid);
  if (tblid) { 
     if (tblid.className == "welcome_map") { tblid.className = "welcome_map_select" }
      else 
      if (tblid.className == "welcome_map_select") { tblid.className = "welcome_map" }
       else 
       if (tblid.className == "welcome_community") { tblid.className = "welcome_community_select" }
        else
        if (tblid.className == "welcome_community_select") { tblid.className = "welcome_community" }
         else 
         if (tblid.className == "welcome_promotions") { tblid.className = "welcome_promotions_select" }
          else
          if (tblid.className == "welcome_promotions_select") { tblid.className = "welcome_promotions" }
           else 
           if (tblid.className == "welcome_shortlist") { tblid.className = "welcome_shortlist_select" }
            else
            if (tblid.className == "welcome_shortlist_select") { tblid.className = "welcome_shortlist" }
             else 
             if (tblid.className == "welcome_allvillas") { tblid.className = "welcome_allvillas_select" }
              else
              if (tblid.className == "welcome_allvillas_select") { tblid.className = "welcome_allvillas" };

  };
}


// ====================================================================================================
// Thanks to... for providing the initial idea for the slide show.
//
// Browser Slide-Show script. With image cross fade effect for those browsers
// that support it.
// Script copyright (C) 2004-2010 www.cryer.co.uk.
// Script is free to use provided this copyright header is included.
// ====================================================================================================

var FadeDurationMS=1000;

function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}

// ----------------------------------------------------------------------------------------------------

function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var msNow = (new Date()).getTime();
  var opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity<=0)
  {
    SetOpacity(element,0);
    element.timer = undefined;
  }
  else if (opacity>=100)
  {
    SetOpacity(element,100);
    element.timer = undefined;
  }
  else 
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",10);
  }
}

// ----------------------------------------------------------------------------------------------------

function FadeInImage(imgSlideShow,newImage)
{
  var idSlideShowImage=document.getElementById(imgSlideShow);
  if (idSlideShowImage.timer) window.clearTimeout(idSlideShowImage.timer);
  idSlideShowImage.src = newImage; 
  if (idSlideShowImage.width > 600) { idSlideShowImage.style.width= 600 };
  SetOpacity(idSlideShowImage,0);
  var startMS = (new Date()).getTime();
  idSlideShowImage.timer = window.setTimeout("ChangeOpacity('" + imgSlideShow + "'," + FadeDurationMS + "," + startMS + ",0,100)",10);
}

// ----------------------------------------------------------------------------------------------------

var slideCache = new Array();
function RunSlideShow(imgSlideShow, pathVillaImages, imageFiles, displaySecs)
{

  var imageSeparator  = imageFiles.indexOf(";");
  var imageToShowNext = imageFiles.substring(0,imageSeparator);
  var imageToShow     = pathVillaImages + "/" + imageToShowNext;

  if (slideCache[imageToShowNext] && slideCache[imageToShowNext].loaded)
  {
    FadeInImage(imgSlideShow, imageToShow);
    var futureImages = imageFiles.substring(imageSeparator+1,imageFiles.length) + ';' + imageToShowNext;
    setTimeout("RunSlideShow('" + imgSlideShow + "','" + pathVillaImages + "','" + futureImages + "'," + displaySecs + ")",  displaySecs*1000);
    // Identify the next image to cache.
    imageSeparator  = futureImages.indexOf(";");
    imageToShowNext = futureImages.substring(0,imageSeparator);
  } else {
    setTimeout("RunSlideShow('" + imgSlideShow + "','" + pathVillaImages + "','" + imageFiles + "'," + displaySecs + ")",  250);
  }
  // Cache the next image to improve performance.
  if (slideCache[imageToShowNext] == null)
  {
    slideCache[imageToShowNext] = new Image;
    slideCache[imageToShowNext].loaded = false;
    slideCache[imageToShowNext].onload = function(){this.loaded=true};
    slideCache[imageToShowNext].src = pathVillaImages + "/" + imageToShowNext;
  }
}

// ====================================================================================================

// ----------------------------------------------------------------------------------------------------
