
/* Slides */
var slideTimer = 0;
var lastShownStor = 1;
var ShownStor = 1;
var maxStor = 4;
var num = 6; //numéro du carousel
/* Fade */
var fadeTimer = 0;

function starthome()
{
	slideTimer = setTimeout('runSlideshow();', 1000);
}

function runSlideshow()
{
	showNext();
	slideTimer = setTimeout('runSlideshow();', 4000);
}


function fade(myItemId, newFrontItem, fast)
{
	if (fast) delay = 18; else delay = 50; 
	myItem = document.getElementById(myItemId);
	myItem2 = document.getElementById(newFrontItem);
	if (myItem.style.opacity == "")
	{
		myItem.style.opacity = "1.0";
		MyOpacity = 100; 
	}
	if (myItem.style.opacity > 0.005)
	{
		//standard
		myItem.style.opacity = myItem.style.opacity-0.05;
		
		//IE 8
		MyOpacity = Math.round(myItem.style.opacity*100);
		myItem.style.MsFilter = "progid:DXImageTransform.Microsoft.Alpha(Opacity="+MyOpacity+")";
		//IE 5-7
		myItem.style.filter = "alpha(opacity="+MyOpacity+")";
		fadeTimer = setTimeout('fade(\''+myItemId+'\',\''+newFrontItem+'\','+fast+');', delay);
	}
	//Opacity == 0 => fade is over
	else
	{
		clearTimeout(fadeTimer);
		myItem.style.zIndex = "1";
		myItem2.style.zIndex = "2";
	}
}

function rotateDiv(ShownStor, fast)
{
	var divs = document.getElementById("carousel_image_contener").getElementsByTagName("div");
	if (ShownStor == lastShownStor)
		return;
	
	clearTimeout(fadeTimer);
	for (var i=0; i < divs.length; i++ )
  {
  	var div = divs[i];
  	 if (div.id != "")
    {
    	slideNum = i/2+1;

    	//Next slide : show but behind
    	if (slideNum == ShownStor)
    	{
    		div.style.zIndex = "1";
    		div.style.display = "block";
    	}
    	//Just shown slide
    	else if(slideNum == lastShownStor)
			{
				div.style.display = "block";
				div.style.zIndex = "2";
			}
			//Hide and put behind all the others
			else
			{
				div.style.display = "none";
				div.style.zIndex = "1";
			}
			
			//standard
			div.style.opacity = "1";
		
			//IE 8
			div.style.MsFilter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
			//IE 5-7
			div.style.filter = "alpha(opacity=100)"; 
		}
		
		//Tabs
		if (slideNum != ShownStor)
		{
			document.getElementById('tab'+slideNum).className = "t"+slideNum;
		}
		else
		{
			document.getElementById('tab'+slideNum).className = "t"+slideNum+"a";
		}
	}
	
	document.getElementById('carousel_image'+lastShownStor).style.zIndex = "2";
	document.getElementById('carousel_image'+lastShownStor).style.opacity = "1.0";
	
	fade('carousel_image'+lastShownStor, 'carousel_image'+ShownStor, fast);
	
	//document.getElementById('carousel_image'+ShownStor).style.zIndex = "1";
	document.getElementById('carousel_image'+ShownStor).style.display = "block"; 
	
	lastShownStor = ShownStor;
	//debug
	//document.getElementById('debug').innerHTML = '1:'+document.getElementById('carousel_image1').style.zIndex+'<br />2:'+document.getElementById('carousel_image2').style.zIndex+'<br />3:'+document.getElementById('carousel_image3').style.zIndex+'<br />4:'+document.getElementById('carousel_image4').style.zIndex+'last:'+lastShownStor;
}

function showNext()
{ 
	if(ShownStor < maxStor)
		ShownStor++;
	else
		ShownStor=1;

	rotateDiv(ShownStor);
}

function stopSlideshow() {
	clearTimeout(slideTimer);
}

function restartSlideshow() {
	slideTimer = setTimeout('runSlideshow();', 2000);
}

function playclip(){
	
	stopSlideshow();
	document.getElementById('carousel_image'+num).style.textAlign= "center";
	//document.getElementById('carousel_image4').style.paddingTop= "0px";
	document.getElementById('carousel_image'+num).style.background= "#000";
	document.getElementById('carousel_image'+num).innerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" autoplay="true"  width="430" height="293"><param name="movie" value="images/i/video_fjv.swf?2" />	<embed src="images/i/video_fjv.swf?2" autoplay="false" quality="high" bgcolor="#000" width="430" height="293" name="home" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object><div id=""></div>';
	//document.getElementById('carousel_image4').innerHTML='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="320" HEIGHT="190" id="myMovieName"><PARAM NAME=movie VALUE="images/i/video_fjv.swf"><PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF><EMBED href="images/i/video_fjv.swf" quality=high bgcolor=#FFFFFF WIDTH="320" HEIGHT="190" NAME="myMovieName" ALIGN="middle" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT> ';
}
function backrotateDiv(store,fast){
	
	rotateDiv(store,fast);
	document.getElementById('carousel_image'+num).innerHTML='<img onclick="playclip()" src="images/i/transp_carousel.png" alt="play" style="cursor:pointer;"/><div class="carousel_text"><span>Vid&eacute;o du Festival 2009</span></div>';
	document.getElementById('carousel_image'+num).style.background="url(\"../images/i/carousel3.jpg\") no-repeat";
	document.getElementById('carousel_image'+num).style.textAlign= "";
//	document.getElementById('carousel_image4').style.paddingTop= "";
	/*
		carousel4 = document.getElementById('carousel_image4')
	 	if (carousel4.style.background == "#000";)
		{
		document.getElementById('carousel_image4').innerHTML='<img onclick="playclip()" src="images/i/transp_carousel.png" alt="play" style="cursor:pointer;"/><div class="carousel_text"><a href="">Movie of the Festival</a></div>';
		document.getElementById('carousel_image4').setAttribute("style", 'background= url("../images/i/carousel4.jpg") no-repeat;');
		} */
	
}

