var bIsSet = false;
bStart = false;
var bShowDia = true;
var interval = 8000;//Milliseconds 
var startTime = 0;
var endTime   = interval+1;
var objTimeout = null;

var aImages   = new Array(6);

aImages[0] = "bg-home-1.jpg";
aImages[1] = "bg-home-2.jpg";
aImages[2] = "bg-home-3.jpg";
aImages[3] = "bg-home-4.jpg";
aImages[4] = "bg-home-5.jpg";
//aImages[5] = "bg-home-6.jpg";
aImages[5] = "bg-home-7.jpg";

var iCurrentIndex = 0;
var sCurrentShown = "bg_current";//bg_current -> bg_next ->bg_prev -> bg_current
var bCurrent = true;
var imgPath = root_dir +"/images/bg_start/";

function doLoad()
 {
	 if (bShowDia )
	 {
		 nextImage();
		 objTimeout = setTimeout("doLoad()", interval);
	 }
 }
function start(lang)
{
//	alert(root_dir);
  
	bStart = true; 
	//new Effect.BlindUp('olivenoel',{duration: 0.1});
	//new Effect.BlindUp('geschichte',{duration: 0.1});
	
	//activateAll();
	
	if (lang!="") {
	  imgPath = imgPath + lang + "/";
	}
	bShowDia = true;
	//nextImage();
	//if(endTime-startTime>interval)
	//{
	doLoad();
//	}	
}

 
function stop()
{
	if (bShowDia)
	{
		
		new Effect.Opacity('bg_current',{duration:0.1,transition:Effect.Transitions.linear,from:1.0,to:0.0});
		new Effect.Opacity('bg_next',{duration:0.1,transition:Effect.Transitions.linear,from:1.0,to:0.0});
		document.getElementById("bg_next").style.display='none';
		document.getElementById("bg_current").style.display='none';
	}
	
	
	bShowDia = false;
	clearTimeout(objTimeout);
	document.getElementById("bottle").style.display= 'block';
	document.getElementById("oil_description").style.display= 'block';
	
		
	//else 
		//new Effect.Opacity('bg_prev',{duration:0.1,transition:Effect.Transitions.linear,from:1.0,to:0.0});
//	colorize('#666666');
	
}
 
function nextImage()
{
   iCurrentIndex = getNextIndex();
  // alert(iCurrentIndex);
   if(bCurrent)
   {
	   document.getElementById("bg_next").style.background = getImage(iCurrentIndex);
	   document.getElementById("bg_next").style.zIndex=2;
	   document.getElementById("bg_current").style.zIndex=3;
	   document.getElementById("bg_next").style.display="inline";
	   
//	   alert("Hier");
	   
	   new Effect.Opacity('bg_next',{duration:3.0,transition:Effect.Transitions.linear,from:0.0,to:1.0});
	   new Effect.Opacity('bg_current',{duration:3.0,transition:Effect.Transitions.linear,from:1.0,to:0.0});
//	   alert("Hier2");
	   //document.getElementById("bg_current").style.display="none";
	   bCurrent = false;
   }
   else
   {
	   document.getElementById("bg_current").style.background = getImage(iCurrentIndex);
	   document.getElementById("bg_current").style.zIndex=2;
	   document.getElementById("bg_next").style.zIndex=3;
	   document.getElementById("bg_current").style.display="inline";
	   
	   new Effect.Opacity('bg_current',{duration:3.0,transition:Effect.Transitions.linear,from:0.0,to:1.0});
	   new Effect.Opacity('bg_next',{duration:3.0,transition:Effect.Transitions.linear,from:1.0,to:0.0});
	   
	   //document.getElementById("bg_next").style.display="none";
	   bCurrent = true;
   }
}

 
function activateAll()
{
	// document.getElementById("bg_prev").style.display = 'inline';
	 //document.getElementById("bg_next").style.display = 'inline';
	 //document.getElementById("bg_current").style.display = 'inline';
	setOpacity("bg_current",1.0);
	setOpacity("bg_next",0.0);
}
 
function getNextIndex()
{
	if (iCurrentIndex >= aImages.length-1)
	{
		iCurrentIndex = 0;
	}
	else 
	{
		iCurrentIndex++;
	}
	return iCurrentIndex;
}
 
function getImage(index)
{
	//if(index  >= aImages.length)
		//index = 0;
	return 'url("' + imgPath + aImages[index] +'") top no-repeat scroll';
}
 
 function setNextImages()
 {
	 document.getElementById("bg_prev").style.background = 'url("images/impression1_opt.jpg") top left no-repeat scroll';
	 document.getElementById("bg_current").style.background = 'url("images/impression1_opt.jpg") top left no-repeat scroll';
	 document.getElementById("bg_next").style.background = 'url("images/impression1_opt.jpg") top left no-repeat scroll';
 }
 
 function setOpacity(id, val)
 {
	 document.getElementById(id).style.opacity = val;
 }

