// JavaScript Document
var currentArticle=1;
var MAXARTS=10;
var timeout1, timeout2;
var paused=false;
var transMutex=false;
var DUR=10000; // 10 seconds

//////////////////////////////////////

function startSlideShow()
{
	for(i=1;i<MAXARTS;i++)
	{
		temp=document.getElementById("article"+i);
		if(temp)
		{
			temp.style.opacity=0;
			temp.style.filter="alpha(opacity=0)";
			temp.style.filter="'alpha(opacity=0)'";
			temp.style.display='none';
		}
	}
	temp=document.getElementById("article1");
	currentArticle=1;
	transMutex=true;
	fadeIn("'article1'", 0);
	setInterval(changeArticle, DUR);
}
function pauseResumeSlideShow()
{
	paused=!paused;
	if(paused)
	{
		document.getElementById("pauseBut").style.display='none';
		document.getElementById("resumeBut").style.display='';
	}
	else
	{
		document.getElementById("resumeBut").style.display='none';
		document.getElementById("pauseBut").style.display='';
	}
}
function nextArticle()
{
	if(transMutex)
	{
		return;
	}
	transMutex=true;
	var prevArt=currentArticle;
	if(currentArticle<MAXARTS)
		currentArticle++;
	else
		currentArticle=1;
	artDiv=document.getElementById('article'+currentArticle);
	if(!artDiv)
		currentArticle=1;
	oldDiv=document.getElementById('article'+prevArt);
	oldDiv.style.opacity=0;
	oldDiv.style.filter="alpha(opacity=0)";
	oldDiv.style.filter="'alpha(opacity=0)'";
	fadeOut("'article"+prevArt+"'", 60);
	
	setTimeout("fadeIn('article"+ currentArticle+"', "+ 0 +")", 200);
}

function prevArticle()
{
	if(transMutex)
	{
		//alert("mutex="+transMutex);
		return;
	}

	var prevArt=currentArticle;
	currentArticle--;
	if(currentArticle<=0)
		currentArticle=MAXARTS;
	var temp=document.getElementById('article'+currentArticle);
	while(!temp)
	{
		currentArticle--;
		temp=document.getElementById('article'+currentArticle);
	}
	
	oldDiv=document.getElementById('article'+prevArt);
	oldDiv.style.opacity=0;
	oldDiv.style.filter="alpha(opacity=0)";
	oldDiv.style.filter="'alpha(opacity=0)'";

	fadeOut("'article"+prevArt+"'", 60);
	//nextArticle();
	setTimeout("fadeIn('article"+ currentArticle+"', "+ 0 +")", 300);
}
function changeArticle()
{
	//alert("changing..."+transMutex);
	if(paused)
		return;
	nextArticle();
	
}

function fadeOut(elementID, op)
{
	if(elementID.charAt(0)=='\'')
		elementID=elementID.substring(1, elementID.length-1);//strip quotes
	artDiv=document.getElementById(elementID);
	if(op<=5)
	{
		artDiv.style.opacity=0;
		artDiv.style.filter="alpha(opacity=0)";
		artDiv.style.filter="'alpha(opacity=0)'";
		artDiv.style.display='none';
		transMutex=false;
		clearTimeout(timeout1);
		
		//alert("end fade out...."+transMutex);
		return;
	}
	if(op>=60)	transMutex=true;
	//firefox
	fract=op/100;
	artDiv.style.opacity=fract;
	//ie
	artDiv.style.filter = 'alpha(opacity = ' + op + ')';
	op-=5;
	timeout1=setTimeout("fadeOut('"+ elementID +"', "+ op +")", 10);
}
function fadeIn(elementID, op)
{
	

	if(op==0)	transMutex=true;
	if(elementID.charAt(0)=='\'')
		elementID=elementID.substring(1, elementID.length-1);//strip quotes
	artDiv=document.getElementById(elementID);
	if(op>=95)
	{
		transMutex=false;
		clearTimeout(timeout2);
		artDiv.style.opacity=1;
		artDiv.style.filter="alpha(opacity=100)";
		artDiv.style.filter="'alpha(opacity=100)'";
		//alert("end fade in......"+transMutex);
		return;
	}
	if(op==0)//first time
		document.getElementById(elementID).style.display='';
	//firefox
	fract=op/100;
	artDiv.style.opacity=fract;
	//ie
	artDiv.style.filter = 'alpha(opacity = ' + op + ')';
	op+=5;
	timeout2=setTimeout("fadeIn('"+ elementID +"', "+ op +")", 20);
}