﻿/**********************************************************/
/** Not part of the BANNER - These are utility functions **/

function ImagePreloader(images, call_back)
{
   // store the call-back
   this.call_back = call_back;
 
   // initialize internal state.
   this.nLoaded = 0;
   this.nProcessed = 0;
   this.aImages = new Array;
 
   // record the number of images.
   this.nImages = images.length;
 
   // for each image, call preload()
   for ( var i = 0; i < images.length; i++ )
      this.preload(images[i]);
}

ImagePreloader.prototype.preload = function(image)
{
   // create new Image object and add to array
   var oImage = new Image;
   this.aImages.push(oImage);
  
   // set up event handlers for the Image object
   oImage.onload = ImagePreloader.prototype.onload;
   oImage.onerror = ImagePreloader.prototype.onerror;
   oImage.onabort = ImagePreloader.prototype.onabort;
  
   // assign pointer back to this.
   oImage.oImagePreloader = this;
   oImage.bLoaded = false;
  
   // assign the .src property of the Image object
   oImage.src = image;
}

ImagePreloader.prototype.onComplete = function()
{
   this.nProcessed++;
   if ( this.nProcessed == this.nImages )
   {
      this.call_back(this.aImages, this.nLoaded);
   }
}

ImagePreloader.prototype.onload = function()
{
   this.bLoaded = true;
   this.oImagePreloader.nLoaded++;
   this.oImagePreloader.onComplete();
}

ImagePreloader.prototype.onerror = function()
{
   this.bError = true;
   this.oImagePreloader.onComplete();
}

ImagePreloader.prototype.onabort = function()
{
   this.bAbort = true;
   this.oImagePreloader.onComplete();
}


function blendimage____(divid, imageid, imagefile, secs) {
  
  //set the current image as background
  document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
  
  //make image transparent
  Element.hide(imageid);
  
  //make new image
  document.getElementById(imageid).src = imagefile;
   
  Effect.Appear(imageid, { duration: secs });
}

function blendImage(divid, imagefile, secs) {
  var t = divid;
  var te = t.childElements();
  var i = $('base_main_image');
  
  if (i == null) {
    i = new Element('img', {'id':'base_main_image'});
    i.src = t.style.backgroundImage.replace('url(', '').replace(')', '');
    i.height = Element.getHeight(t);
    i.width = Element.getWidth(t);
    
    //i.clonePosition(t);
    //debugger;
    var n = te[0];
    if (n == null)
      t.appendChild(i);
    else
      t.insertBefore(i, n);
  }
  else {
    i.src = t.style.backgroundImage.replace('url(','').replace(')','');
    i.show();
  }

  
  t.style.background = 'url(' + imagefile + ')';
  Effect.Fade('base_main_image', { duration: secs });  
}



/********** LOG *****************/
function log(message) {
    if (!log.window_ || log.window_.closed) {
        var win = window.open("", null, "width=400,height=200," +
                              "scrollbars=yes,resizable=yes,status=no," +
                              "location=no,menubar=no,toolbar=no");
        if (!win) return;
        var doc = win.document;
        doc.write("<html><head><title>Debug Log</title></head>" +
                  "<body></body></html>");
        doc.close();
        log.window_ = win;
    }
    var logLine = log.window_.document.createElement("div");
    logLine.appendChild(log.window_.document.createTextNode(message));
    log.window_.document.body.appendChild(logLine);
} 