/*****

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

// write initial value(s) somewhere in the document like follows:

var imgConts = new Array(
  'imageContainer1',
  {
   's_id': 'imageContainer2',
   'speed' : 150
  },
  {
   's_id': 'imageContainer3'
  }
 );


*****/



/*window.addEventListener ?
 window.addEventListener("load", setSlideImages, false)
 :
 window.attachEvent("onload", setSlideImages);
*/

function setSlideImages(params) {
 if (!params) {
  params = imgConts;
 }
 else if (typeof(params) == typeof({})) {
  params = [params];
 }
 for (var i = 0; i < params.length; i++) {
  if (typeof(params[i]) == 'object') {
   var o = new slideImages(params[i]);
  }
  else {
   var o = new slideImages({ 's_id' : params[i] });
  }

 }
}

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();
