// JavaScript Document
var cIndex = 0;
var autoTmr;
var loading = false;
function loadSlide(index)
{
	if(loading==false)
	{
		loading = true;
		slideTmrStop();
		try
		{
			var firstSlide = false;
			if(cIndex==index)
			{
				return;	
			}
			if(!cIndex) { firstSlide = true; }
			cIndex = index;
			var xmlhttp;
			if(window.XMLHttpRequest)
			{
				xmlhttp=new XMLHttpRequest();
			}
			else if(window.ActiveXObject)
			{
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange=function()
			{
				if(xmlhttp.readyState==4)
				{	
					var response = xmlhttp.responseText;
					updateBtns(cIndex);			
					if(!firstSlide)
					{
						document.getElementById('slides').innerHTML = response;
						loading = false;
						/*
						$('#slides').animate({ opacity: 0.0 }, 250);
						$('#slide2').animate({ opacity: 1.0, top: '-=350' }, 500, function() {
						  $('#slide2').animate({ opacity: 0.0 }, 1);
						  $('#slides').animate({ opacity: 1.0 },250,function() { loading = false; });
						  document.getElementById('slides').innerHTML = document.getElementById('slide2').innerHTML;
						  $('#slide2').animate({ top: '+=350' });
						});
						*/
					}
					else
					{
						document.getElementById('slides').innerHTML = response;
						loading = false;
					}
					slideTmrStart();
				}
			}
			xmlhttp.open("GET","/slides/"+index+".php",true);
			xmlhttp.send(null);
		}
		catch(err) { void(0); }
	}
}
function updateBtns(index)
{
	document.getElementById('slideBtn_01').className = 'slideBtn';
	document.getElementById('slideBtn_02').className = 'slideBtn';
	document.getElementById('slideBtn_03').className = 'slideBtn';
	document.getElementById('slideBtn_04').className = 'slideBtn';	
	var dynName = "slideBtn_0" + index;
	document.getElementById(dynName).className = 'slideBtnSelected';
}
function loadNextSlide()
{
	slideTmrStop();
	nIndex = parseInt(cIndex)+1;
	if(nIndex > 4) { nIndex = 1; }
	loadSlide(nIndex);
}
function slideTmrStart()
{
	clearTimeout(autoTmr);
	autoTmr = setTimeout("loadNextSlide()",5000);
}
function slideTmrStop()
{
	clearTimeout(autoTmr);	
}
loadSlide(1);
