
/* REF */
pos = 0;
refTimer = 0;
rollWidth = 3800;

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

/* Fade */
var fadeTimer = 0;

function starthome()
{
	refTimer = setTimeout('refroll();', 500);
	slideTimer = setTimeout('runSlideshow();', 1500);
}
function startact()
{
	slideTimer = setTimeout('runSlideshow();', 1500);
}

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

function refroll()
{
	pos = pos-1;
	if (pos==-rollWidth) pos = 0;
	document.getElementById('logo_ref').style.backgroundPosition = pos + 'px';
	refTimer = setTimeout('refroll();', 30);
}
function refstop()
{
	clearTimeout(refTimer);
}


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.05)
	{
		//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
	{
		myItem.style.opacity = 0;
		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";
    	}
    	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.display = "block"; 
	
	lastShownStor = ShownStor;
}


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

	rotateDiv(ShownStor);
}

function stopSlideshow() {
	clearTimeout(slideTimer);
}

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

function togglediv(DivId)
{
	if (document.getElementById(DivId).style.display == 'none')
	{
		document.getElementById(DivId).style.display = 'block';
		document.getElementById(DivId+'_bullet').src = '/images/pink-minus-bullet.gif';
	}
	else
	{
		document.getElementById(DivId).style.display = 'none';
		document.getElementById(DivId+'_bullet').src = '/images/pink-plus-bullet.gif';
	}
}



