var     rotate_Time = 6000;     //speed of animation
var     imageNum = -1;                         //frame of animation
var     firstTime = true;

var ie5=(document.getElementById && document.all);
var ns6=(document.getElementById && !document.all);

var fadeAmount = 5  //the % of fading for each step
var speed = 70  //the speed
var currentOpacity= 20;
var fadein;

/////////////////////////////////////////////////////
//LoadAnimation
//	This is a preloader for the animation
function LoadAnim()
{
   var   count = 0;
   var   tmpIMG = new Image;

   for(count=0; count<RImages.length; count++)
   {
      tmpIMG.src = RImages[count];
      
   }
}

/////////////////////////////////////////////////////////////////
//var RImages is an array of image paths (defined on the html page)
function Rotate()
{
	 //check if image object is supported
     // if not short circut function
     if( (!document.images) && (!verOk) )
          return;

     //preload animation the first time
     if(firstTime){
          LoadAnim();
          document['bottle'].src = RImages[0];
          setTimeout("Rotate()", rotate_Time);	//start next rotate
          firstTime = false;
          imageNum = 0;
          return;
    }

      //find images
	 bottleIMG = document['bottle'];
	imageNum++;
			
	if(imageNum == RImages.length){
		imageNum = 0;
	}


	//Fade Out
	currentOpacity = 100;
	fadein = false;
	FadeImg();
	
     //Start next animation
     setTimeout("Rotate()", rotate_Time);	//start next rotate

     return;
}

function FadeImg(){
	img = document['bottle'];
	if(fadein){
		if(currentOpacity >=100){
			return;
		}
		currentOpacity += fadeAmount;
		//window.status = currentOpacity;
	}
	if(!fadein){
		if(currentOpacity <= 10){
			currentOpacity = 10;
			fadein = true;
			img.src = RImages[imageNum];
			FadeImg();
			return;
		}
		currentOpacity -= fadeAmount;
		//window.status = currentOpacity;
	}

    if(ie5){
		img.style.filter="alpha(opacity=0)";
		img.filters.alpha.opacity = currentOpacity;
    }
    if(ns6){
		//img.style.MozOpacity = 0 + '%';
		//img.style.MozOpacity = currentOpacity + '%';

		// the following actually works in Mozilla/Gecko based browsers
		img.style.MozOpacity = currentOpacity/100;
		// the following is for KHTML Browsers, including Konqueror and Safari
		img.style.KhtmlOpacity = currentOpacity/100;
		// the following is for CSS3 standard browser not covered by the previous 2
		img.style.Opacity = currentOpacity/100;
		
    }
	setTimeout('FadeImg();',speed);
}




