/**
ORIGINAL SOURCE CODE WRITTEN BY
/*****
Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com

Please leave this notice intact. 

Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html
*****/


/*****
Re-written by Omi
to hanle multiple objects in one document;
2008.04.01,2009.12.11
*****/

function setSlideImages(Lists) {

 if (Lists) {
  if (!isArray(Lists)) {
   Lists = new Array(Lists);
  }
  var a = new Array();
  var slideParams = new Array();
  
  for (var i = 0; i < Lists.length; i++) {
   slideParams[i] = Lists[i].params;
   a[i] = new Array();
   for (var j = 0; j < Lists[i].list.length; j++) {
    a[i][j] = new Image();
    var imgsrc = slideParams[i].path + Lists[i].list[j];
    a[i][j].src = imgsrc;
    $(slideParams[i].s_id).appendChild(
     createElementWithAttrs('img',
      {
        src:    imgsrc,
        height: slideParams[i].height, 
        width:  slideParams[i].width
      }
     )
    );
   }
  
  }

  for (var i = 0; i < Lists.length; i++) {
   if (typeof(Lists[i]) == 'object') {
    var o = new slideImages(slideParams[i]);
   }
  }
 } // end of if (arguments[0])
}





function slideImages() {
 var d = document;
 if (!d.getElementById || !d.createElement) { return };

 this.p			= arguments[0];
 this.zInterval	= null;
 this.current	= 0;
 this.pause		= false;

 for (var k in this.p) {
  eval('this.' + k + ' = this.p.' + k)
 }
 
 this.slideObj = d.getElementById(this.s_id);
 this.slideObj.style.position = 'relative';
 
 this.imgs = this.slideObj.getElementsByTagName("img");

 for (var i = 0; i < this.imgs.length; i++) {
  this.imgs[i].xOpacity			= 0;
  this.imgs[i].style.display	= 'none';
  this.imgs[i].style.position	= 'absolute';
  this.imgs[i].style.top		= 0;
  this.imgs[i].style.left		= 0;
 }
 this.imgs[0].style.display = "block";
 this.imgs[0].xOpacity = .99;
 this.slideObj.style.height = this.imgs[0].height + 'px';
 
 var obj = this;
 function startFade () {// alert(obj);
  obj.cOpacity	= obj.imgs[obj.current].xOpacity;
  obj.nIndex	= (obj.imgs[obj.current+1])? obj.current+1 : 0;
 
  obj.nOpacity = obj.imgs[obj.nIndex].xOpacity;
  
  obj.cOpacity -= .05; 
  obj.nOpacity += .05;
  
  obj.imgs[obj.nIndex].style.display	= "block";
  obj.imgs[obj.current].xOpacity		= obj.cOpacity;
  obj.imgs[obj.nIndex].xOpacity			= obj.nOpacity;
  
  setOpacity(obj.imgs[obj.current]); 
  setOpacity(obj.imgs[obj.nIndex]);


  function setOpacity(obj) {
   if (obj == null) { return }
   if (obj.xOpacity > .99) {
    obj.xOpacity = .99;
    return;
   }
   obj.style.opacity = obj.xOpacity;
   obj.style.MozOpacity = obj.xOpacity;
   obj.style.filter = "alpha(opacity = " + (obj.xOpacity * 100) + ")";
  }

  if(obj.cOpacity <= 0) {
   obj.imgs[obj.current].style.display = "none";
   obj.current = obj.nIndex;
   setTimeout(startFade, obj.delay);
  } else {
   setTimeout(startFade, obj.speed);
  }
 };
 
 setTimeout(startFade, this.delay);

};


//function slideImagesBase() {};
slideImages.prototype = new Object({
 's_id'		: 'imageContainer',
 's_height'	: '300px',
 'delay'	: 1000,
 'speed'	: 50,
 'test'		: 'testvalue'
});


//slideImages.prototype = new slideImagesBase();

