/* --- USAGE
==============

-- in <Head> Section:
====================
<script language="javascript" type="text/javascript" src='imageFade.js'></script>


-- in <Body>
==========


-- After Image object/s <img> put this script, anywhere below;
===============================================================

  <script language="JavaScript" type="text/javascript">
    var oA = new oImg('oA', 'a1', '10', '', 'add.gif,cut.gif,cancel.gif');
    oA.showImg();

    var oB = new oImg('oB', 'b1', '10', '', '11.gif,22.gif');
      oB.showImg();

    var oC = new oImg('oC', 'c1', '10', '', 'add.gif,22.gif,cut.gif, 33.gif');
      oC.showImg();
    var oD = new oImg('oD', 'd1', '10', '', '11.gif,add.gif,22.gif,cut.gif,33.gif, cancel.gif');
      oD.showImg();
  </script>


-- That's it
============
*/

    function showImg(){
       //alert("Num: " + this.faderNum + " | till: " + this.faderTill + " | Img: " + this.imgArray[this.ctr] + " | Arrlen: " + this.imgArray.length);
        var pauseBtwn = 200;
        if(this.aniMate == 'N'){ // && this.imgArray.length == 1){
            //this.imgX.src = this.imgPath + this.imgArray[this.ctr];
			this.imgX.src = this.preLoad[this.ctr].src;
            this.imgX.style.filter = "alpha(opacity = 100)"; // IE  .
            this.imgX.style.opacity = 100;  // FF  .
        } else {
            if((this.faderTill == 0   && this.speed > 0) || (this.faderTill == 100 && this.speed < 0) ){
                this.speed = (this.speed * -1);
            }

          	this.faderNum = this.faderNum + (this.speed);

            if(this.faderNum >= 100){
                this.faderTill = 0;
                this.faderNum = 100;
                if(this.pause != 0){ pauseBtwn = this.pause * 1000; }
            } else if(this.faderNum <= 0){
                this.faderTill = 100;
                this.faderNum = 0;
                this.ctr = this.ctr + 1;
              	if (this.ctr >= (this.imgArray).length){this.ctr = 0;}
                //this.imgX.src = this.imgPath + this.imgArray[this.ctr];
				this.imgX.src = this.preLoad[this.ctr].src;
				if(this.noimageTime != 0){ pauseBtwn = this.noimageTime * 1000;	}
            }

            this.imgX.style.filter = "alpha(opacity = " + this.faderNum +")"; // IE
            this.imgX.style.opacity = (this.faderNum/100);  // FF

            clearTimeout(this.tout);
            this.tout = setTimeout(this.objName+".showImg()", pauseBtwn);
        }
      }

      function oImg(myContainer, objName, imgID, speedX, imgPath, imagesX, aniMate, pauseTime, noimageTime){
		  //alert(imagesX);
          this.objName      = objName;
          this.imgID        = imgID;
          //this.imgX         = document.getElementById(imgID);
          this.imgPath      = imgPath;
		  
          if(pauseTime == ""){pauseTime = 0;}
          this.pause        = pauseTime;
		  
		  if(noimageTime == ""){noimageTime = 0; }
		  this.noimageTime	= noimageTime;
          
		  this.imgArray     = imagesX.split(",");
          this.ctr          = 0;
          if(speedX <= 0 || speedX == ""){speedX = 10;}
          this.speed        = parseInt(speedX);
          this.faderNum     = 0 - this.speed;       // adjusted for 1st image
          this.faderTill    = 100;
          this.showImg      = showImg;
          this.tout         = "";
          this.aniMate      = aniMate;
          var oImgNew       = new Image(); //document.createElement("img");
          this.imgX         = oImgNew;
          this.imgX.id      = imgID;
          if(myContainer != ""){
                document.getElementById(myContainer).appendChild(oImgNew);
          } else{
                document.body.appendChild(oImgNew);
          }
		
          // Pre Loading
		  this.preLoad = new Array();
          for(i=0; i < this.imgArray.length; i++){
				this.preLoad[i]		= new Image();
				this.preLoad[i].src = this.imgPath + this.imgArray[i];
				//this.imgArray[i] 	= this.imgPath + this.imgArray[i];
                //this.imgX.src 		= this.imgArray[i];
				//alert(this.preLoad[i].src);
          }

         //alert(this.imgArray);
		 //alert(this.imgPath);
      }
