// BEHAVIOUR: WELCOME PAGE (SLIDESHOW, etc)

// (c) 2006 Toowoomba Motor Village - all rights reserved



// 'MAIN' - called when complete page loaded with images, etc
// Initially, only start slideshow projector if broadband (to ensure responsiveness on low-bandwidth); however,
// when page fully downloaded (hence cached), & then re-entered , slideshow will download even if low-bandwidth.
// Site response-times (& UX) are improved by use of common image-files for both slideshow & other page-bkgds.
// Notes: - slideshow PAUSES when mouse HOVERS over MENU (on left) or main black CENTRAL TEXT
//        - slideshow ADVANCES to next-slide when MAP is CLICKED (once carousel has 2 slides)

function hostLoaded()
{

  try
  {
      if (slowLoad())  { return; }                                   // abort if slow page load.

      new ProjctorB( 'viewport',            // target element for slideshow
                     20,                    // first-slide  duration in secs
                     15,                    // other-slides duration in secs
                     2,                     // resume-after-pause delay in secs
                     0.1,                   // start delay, in secs (breathing-space)
                     'map',                 // [bg-only] target element for next-click    [otherwise use '']
                     'notes',               // [bg-only] target element1 for hover-pause  [otherwise use '']
                     'nav',                 // [bg-only] target element2 for hover-pause  [otherwise use '']
                     'images',              // slides-folder - relative to page           [otherwise use '']
                     'home_bkgd1.jpg',      // (also bkgd for home page - welcome)
                     'home_bkgd2.jpg',      // (also bkgd for products page Units)
                     'home_bkgd3.jpg',      // (also bkgd for products page Cabins)
                     'home_bkgd4.jpg',
                     'home_bkgd5.jpg' );

      window.document.getElementById('xcss').ondblclick = xStyleSheetsOnOff;    // dev-tool (can be eliminated)
      window.document.getElementById('visa').ondblclick = function(){window.location='vtmv/default.htm';}
      window.document.getElementById('aaat').ondblclick = function(){window.location='xtmv/default.htm';}
  }
  catch(e) {}

  function slowLoad(tooLong)
  {
      var PAGELOAD_SLOW_SECS = tooLong || 8.0;
      var pageLoad_secs = ((new Date()).getTime() - hostLoaded.pageloadStartTime) / 1000;
      return (pageLoad_secs >= PAGELOAD_SLOW_SECS) ? true : false;
  }

}




// SCRIPT INITIALISATION
// When page fully loaded, initiate processing, but only if a modern-browser;
// obsolete browsers are not countenanced (as script merely enhances an already competent page).
// As the page is unloaded, this script removes its own bindings to window.
// This script formally binds the page events, hence does not use deprecated 'window.onload' event, etc.
// The following is a statement which defines & executes a literal anonymous function
// and does not reserve any names in the global identifier namespace.
// [review-crossbrowser: consider alternatives to use of 'window-load' event: eg 'window.document.load', etc.]

(
        function (loadHandler)
        {
            try
            {
                if (!(loadHandler instanceof Function))  { return; }
                loadHandler.pageloadStartTime = (new Date()).getTime();
                var w3cCapture = false;
                bindWindowEvents();
            }
            catch(e){}

            function bindWindowEvents()
            {
                if (window.addEventListener)                                                  // w3c-DOM method?
                {
                    window.addEventListener('load',   loadHandler, w3cCapture);               // w3c standard binding
                    window.addEventListener('unload', unbindWindowEvents, w3cCapture);
                }
                else
                if (window.attachEvent)                                                       // IE method?
                {
                    window.attachEvent('onload',   loadHandler);                              // non-standard binding for IE
                    window.attachEvent('onunload', unbindWindowEvents);
                }
            }

            function unbindWindowEvents()
            {
              try
              {
                  if (window.removeEventListener)
                  {
                      window.removeEventListener('load',   loadHandler, w3cCapture);
                      window.removeEventListener('unload', unbindWindowEvents, w3cCapture);
                  }
                  else
                  {
                      window.detachEvent('onload',   loadHandler);
                      window.detachEvent('onunload', unbindWindowEvents);
                  }
              }
              catch(e){}
            }
        }
)(hostLoaded);                                                       // change target function-name if namespace clash (use find+replace)




// -----------------------------------------------------------------------------------------

// DEVELOPMENTAL COMPONENTS (dev-purposes only)
// [these component(s) are not formal features of classes above]
// Toggle Stylesheet(s) Off/On        [when off, default HTML styles are used]
// loop thru stylesheets collection, setting 'disabled' property of
// all stylesheets to inverted 'disabled' property-value of the first sheet.

function xStyleSheetsOnOff()
{
   var sss = window.document.styleSheets;
   var len = sss.length;
   if (len > 0)
   {
      var dsbld = !(sss[0].disabled);            // invert sheet0 disabled-state
      for (var i=0; i<len; i++)
      {
          sss[i].disabled = dsbld;
      }
   }
   ProjctorB.enabled = false; // special: freeze projector - current slide, if visible, remains so
}

// ------------------------------------------------------------------------------------------

// (c) 2006 Ian Brown

// end script

