Event.observe(window, 'load', function() 
{  	
	$('rotatorpanel').hide();
	// Calls the content manager here...
	manageContent('rotatorpanel');
});

// Some event driven rotator on a timer goes here?
// Starts at 1, goes through to the last one, then starts again. Fades in/out, based on vars I guess. Must start hidden...
function manageContent(targetID)
{    
	////Get the start value, HC for now... [If you have a set of html pages, this is a less messy way of doing it. This gets a hidden field from the form and gets dynamic names from that. Would work for php etc too, obviously. 
	//var startVal = 1;
	//var endVal = 3;
	
	var timeVal = 0;
	var timeIncrement = 12;
	var fadeDuration = 2.0;
	
	var iLen = 1;
	
	if(document.forms[0].elements['rp'].length != undefined)
	{
	    iLen = document.forms[0].elements['rp'].length;
	}
	
	for (var x = 0; x < iLen; x++)
	{
	    // alert('Length is: ' + document.forms[0].elements['rp'].length + ' and Value is: ' + eval("document.forms[0].elements['rp[" + x + "]'].value"));	
	    
//	    var cid = 'Rotator.aspx?contentpage=' + eval("document.forms[0].elements['rp[" + x + "]'].value");
//	    
//	    alert(cid);
	    	
		getRotatorContent.delay(timeVal, targetID, 'Rotator.ashx?contentpage=' + eval("document.forms[0].elements['rp[" + x + "]'].value"), fadeDuration, timeIncrement); // HC until we can add the vars we need dynamically?
		timeVal += timeIncrement;
	}
	
	// Try to effect the z-index?
	// $(targetID).setZIndex(0);
	
	// Set a delay before calling the whole manager again...
	manageContent.delay(timeVal, targetID);
}

function getRotatorContent(targetID, contentID, fadeDuration, timeIncrement)
{
    // Call the AJAX content. Usual fayre.
	var url = contentID;

	var myAjax = new Ajax.Updater(
		targetID, 
		url, 
		{
			method: 'get'
		});
	
	//Show this content...
	showFade(targetID, fadeDuration);
	// Set it to hide this content...
	var fadeValue = timeIncrement - fadeDuration;
	// alert(fadeValue);
	hideFade.delay(fadeValue, targetID, fadeDuration);
}

function showFade(targetID, fadeDuration)
{
	Effect.Appear(targetID, { duration: fadeDuration, from: 0.01, to: 1 }); // <- This can't fade to zero, or else it drops the element from the DOM and you lose content. 0.01 is almost invisible, so that's cool... 
}

function hideFade(targetID, fadeDuration)
{
	Effect.Fade(targetID, { duration: fadeDuration, from: 1, to: 0.01 });
}