
/* Slides */
var slideTimer = 0;
var lastShownStor = 1;
var ShownStor = 1;
var maxStor = 4;

/* Fade */
var fadeTimer = 0;

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

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+1;
    	
    	//Next slide : show but behind
    	if (slideNum == ShownStor)
    	{
    		div.style.zIndex = "1";
    		div.style.display = "block";
    	}
    	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 clip()
{
	document.write('<object type="application/x-shockwave-flash" autoplay="true" data="images/interface/video_mdj_new.swf?3" width="400" height="300">');
	document.write('<param name="movie" value="images/interface/video_mdj_new.swf?3" />');
	document.write('<embed src="images/interface/video_mdj_new.swf?3" autoplay="true" quality="high" bgcolor="#000" width="400" height="300" name="home" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
	
}
	
