﻿///////////////////////////////////////////////////////////////////////////////
//
//  wcoDefault.js
//
// © 2007-2011 Wco iEnterprise Solutions. All Rights Reserved.
// This file is licensed as part of the DataPortal 3.0 Managed Web Presence Solution, for details look here: http://www.wco.com.au
//
///////////////////////////////////////////////////////////////////////////////
var scriptCounter = 0;
var scriptCount = 0;

function ready () {
  set();
}

function set () {
  var websiteData = arguments[0];
  var childCollection = arguments[1];

  // TEMPORARY DATA
  if (! websiteData) {
    var websiteData = { };
    websiteData.BackgroundColour = '#333333'; // '#585858';
    websiteData.BackgroundImage = 'SS2010SiteMasterBkg.jpg';
    websiteData.Skin = 'Whatever';
  }

  // and load the required javascript modules
  switch (unescape(websiteData.Skin.replace(/&amp;/g, '&'))) {
    case 'Custom':
      // load the desired stylesheet template
      $('link #skin').attr('href', 'css/cs2010web-custom.css');

      var bodyCss = {
        'background-color':websiteData.BackgroundColour
      };
      $('body').css(bodyCss);

      scriptCount = 1;
      $.getScript('scripts/wcoPageManager-Custom.js', function() { go(websiteData, childCollection); });
      break;
    default:
      // load the desired stylesheet template
      $('link #skin').attr('href', 'css/vt2010s.css');

      // setup the page background
      var bodyCss = {
        'background-color':websiteData.BackgroundColour,
        'background-image':"url('ssl/images/" + websiteData.BackgroundImage + "')",
        'background-position':'center top',
        'background-repeat':'no-repeat',
        'background-attachment':'fixed'
      };
      $('body').css(bodyCss);

      scriptCount = 1;
      go(websiteData, childCollection);
      break;
  }

}

function go () {
  scriptCounter += 1;

  if (scriptCounter == scriptCount) {
    var websiteData = arguments[0];
    var childCollection = arguments[1];

    // instantiate a global working copy of the PageManager object
    pageManager = new HtmlPageManagerObject();

    // and initialise the pagemanager, starting the website application
    pageManager.init(websiteData, childCollection);
  }

}

function preloadImages() {
  if (document.images) { //check for compatible browser
    var imgFiles = preloadImages.arguments; //get the array of images to be preloaded into memory
    if (document.preloadArray == null) { document.preloadArray = new Array(); } //create the document array to hold the images
    var i = document.preloadArray.length; //create the array counter

    //load the images into the document array
    with (document) {
      for (var j = 0; j < imgFiles.length; j++) {
        preloadArray[i] = new Image();
        preloadArray[i++].src = imgFiles[j];
      }
    }
  }
}

function createDelegate(instance, method) {
  return function () {
    return method.apply(instance, arguments);
  }
}

var _delayTimerId = null;
function delayAction(delay, callback) {
  if (_delayTimerId != null) {
    // stop the previous timer
    window.clearTimeout(_delayTimerId);
  }
  _delayTimerId = window.setTimeout(callback, delay);
}

function delayStop() {
  if (_delayTimerId != null) {
    // stop the timer
    window.clearTimeout(_delayTimerId);
  }
}


