
var loop = true;
var totalPanels = 4;
var currentPanel = 1;
var timeOut1 = 2000;
var timeOut2 = 4000;
var fadeMillisec = 1000;

function stopLoop()
{
	loop = false;
}
function clickPause()
{
	stopLoop();
}
function clickRight()
{
	stopLoop();
	var nextPanel;
	if(currentPanel<totalPanels)
	{
		nextPanel = currentPanel + 1;
	}
	else
	{
		nextPanel = 1;
	}
	
	showPanel(nextPanel);
}
function clickLeft()
{
	stopLoop();
		
	var nextPanel;
	if(currentPanel==1)
	{
		nextPanel = totalPanels;
	}
	else
	{
		nextPanel = currentPanel - 1;
	}

	showPanel(nextPanel);
}

function startShow()
{
	document.getElementById('display').innerHTML = document.getElementById('flippy1').innerHTML;
	document.getElementById('spanTotalPanels').innerHTML = totalPanels;
	setTimeout("flippyflip2009()",timeOut2);
}

function stopShow()
{
	stopLoop();
}

function flippyflip2009()
{
	//load panel1
	//document.all.display.innerHTML = document.all.panel1.innerHTML;
	loop = true;
	opacity('display', 99, 0, fadeMillisec);
	setTimeout("showPanel(2)",timeOut1);
}


function showPanel(num)
{
	currentPanel = num;
	document.getElementById('spanCurrentPanel').innerHTML = currentPanel;
	
	document.getElementById('display').innerHTML = document.getElementById('flippy'+num).innerHTML;
	opacity('display', 0, 99, fadeMillisec);
	if(loop == true)
	{
		setTimeout("hidePanel(" + num + ")",timeOut2);
	}
}

function hidePanel(num)
{
	var next = num + 1;
	if(next == totalPanels + 1)
	{
		next = 1;
	}
	if(loop == true)
	{
		opacity('display', 99, 0, fadeMillisec);
		setTimeout("showPanel(" + next + ")",timeOut1);	
	}
}


function flippyflip()
{
	//load panel1
	//document.all.display.innerHTML = document.all.panel1.innerHTML;
	loop = true;
	opacity('display', 99, 0, 500);
	setTimeout("showPanel2()",1000);
}

function showPanel1()
{
	document.all.display.innerHTML = document.all.panel1.innerHTML;
	opacity('display', 0, 99, 500);
	if(loop == true)
	{
		setTimeout("hidePanel1()",3000);
	}
}
function hidePanel1()
{
	if(loop == true)
	{
		opacity('display', 99, 0, 500);
		setTimeout("showPanel2()",1000);	
	}
}

function showPanel2()
{
	document.all.display.innerHTML = document.all.panel2.innerHTML;
	opacity('display', 0, 99, 500);
	if(loop == true)
	{
		setTimeout("hidePanel2()",3000);
	}
}
function hidePanel2()
{
	if(loop == true)
	{
		opacity('display', 99, 0, 500);
		setTimeout("showPanel3()",1000);	
	}
}

function showPanel3()
{
	document.all.display.innerHTML = document.all.panel3.innerHTML;
	opacity('display', 0, 99, 500);
	if(loop == true)
	{
		setTimeout("hidePanel3()",3000);
	}

}
function hidePanel3()
{
	if(loop == true)
	{
		opacity('display', 99, 0, 500);
		setTimeout("showPanel4()",1000);	
	}
}

function showPanel4()
{
	document.all.display.innerHTML = document.all.panel4.innerHTML;
	opacity('display', 0, 99, 500);
	if(loop == true)
	{
		setTimeout("hidePanel4()",3000);
	}

}
function hidePanel4()
{
	if(loop == true)
	{
		opacity('display', 99, 0, 500);
		setTimeout("showPanel1()",1000);	
	}
}
