// JavaScript Document
function onlyOne()
{
	// first load hide everything but #1
	for(i=2; i<6; i++)
	{
		if(document.getElementById("Feat_"+i))
		{
			document.getElementById("Feat_"+i).style.display = 'none';
		}
	}
	
	timeIt();
}

function timeIt()
{
	var t=setTimeout("nextOne()",10000);
}

function nextOne()
{
	//loop it and find current active and how manies
	for(i=1; i<6; i++)
	{
		if(document.getElementById("Feat_"+i))
		{
			if(document.getElementById("Feat_"+i).style.display != 'none')
			{
				var active = i;
			}
			var last = i;
		}
	}
	
	// cat_id of last shown
	var lastBlock = active;
	var lastCat = document.getElementById("cat_"+lastBlock).value;
	
	// now set it 
	if(active === last)
	{
		var active = 1;
	}
	else
	{
		var active = parseInt(active) + 1;
	}
	
	// loop and set
	for(i=1; i<6; i++)
	{
		if(document.getElementById("Feat_"+i))
		{
			if(parseInt(active) != i)
			{
				document.getElementById("Feat_"+i).style.display = 'none';
			}
			else
			{
				document.getElementById("Feat_"+i).style.display = '';
			}
		}
	}
	
	// reset the props in the previous block
	freshProps(lastBlock,lastCat);
	
	// do it again
	timeIt();	
}

function freshProps(lastBlock,lastCat)
{
	//alert(lastBlock+" : "+lastCat);
	var uts = Math.round((new Date()).getTime() / 1000);
	var ajax = new ajaxRequest();
	ajax.onreadystatechange = function()
	{
		if(ajax.readyState == 4)
		{
			if(ajax.status==200 || window.location.href.indexOf("http")==-1)
			{
				var res = ajax.responseText;
				if(res != 'fail')
				{
					document.getElementById("catProps_"+lastBlock).innerHTML = res;
				}
				else
				{
					alert(res);
				}
			}
		}
	}
	//var bVal=encodeURIComponent(lastBlock);
	//var cVal=encodeURIComponent(lastCat);
	var uRl = "/js/aj/feat_cat_props.php?b="+lastBlock+"&c="+lastCat+"&fie="+uts;
	ajax.open("GET", uRl, true);
	ajax.send(null);
}

DomReady.ready(function() {
			onlyOne();
		});
