// ROTATOR
// Rotates sets of images for Education InMotion home page
// Developed by: Terradon Communications Group (http://www.ewiz.biz/)
// Utilizing: script.aculo.us (http://script.aculo.us/)
// Worked on by: 03/26/2007 - Nick Slate - Intial development

// PARAMETERS - defaults, can be overridden on page
var pauseSec = 10; // seconds a set of images are displayed
var delaySec = 2; // seconds of delay between stes of images
var fadeSec = 1; // seconds to fade a set of images in or out

// IMAGE SETS
var rotator = new Array();
rotator[0] = { href: '', tabSrc: '/common/images/spacer.gif', tabAlt: '', calloutSrc: '/common/images/spacer.gif', calloutAlt: '', contentSrc: '/common/images/spacer.gif', contentAlt: '', target: '' };
rotator[1] = { 
	href: '/emotional_intelligence/default.aspx', 
	tabSrc: '/shared/images/Rotator/eqi-tab.gif', 
	tabAlt: 'Take the EQ-i now!', 
	calloutSrc: '/shared/images/Rotator/eqi-callout.gif', 
	calloutAlt: 'You may have a high IQ, but what\'s your EQ?', 
	contentSrc: '/shared/images/Rotator/eqi-content.gif', 
	contentAlt: '411 - Get the DL on EQI (Take the test now)',
	target: '_self' 
	};
rotator[2] = { 
	href: '/shared/Dwyer_Workshop/index.htm', 
	tabSrc: '/shared/images/Rotator/tour-tab.gif', 
	tabAlt: 'Take a web tour now!', 
	calloutSrc: '/shared/images/Rotator/tour-callout.gif', 
	calloutAlt: '30% of all freshmen drop out the first year...', 
	contentSrc: '/shared/images/Rotator/tour-content.gif', 
	contentAlt: 'Are you prepared? (Take the tour now)',
	target: '_new' 
	};
	
// INITIALIZE ROTATOR
var curRotator = 0;

// Advance rotator to next set of images, display them, and hide them
function advanceRotator() {
	// Increment current rotator index
	curRotator++;
	if (curRotator >= rotator.length) curRotator = 0;
	// Set rotator element attributes
	setRotator(curRotator);
	
	// If not the "null" image set
	if (curRotator > 0) {
		// Appear the rotator elements
		new Effect.Parallel(
			[ new Effect.Appear('RotatorTab', { sync: true, duration: fadeSec }), 
			new Effect.Appear('RotatorCallout', { sync: true, duration: fadeSec }), 
			new Effect.Appear('RotatorContent', { sync: true, duration: fadeSec }) ],
			{ duration: fadeSec, 
			afterFinish: function(effect)
				// Set timer to fade rotator elements
				{ window.setTimeout('fadeRotator()', pauseSec*1000); } 
			}
		);
	}
	else {
		// Set timer for next rotator advance
		window.setTimeout('advanceRotator()', (fadeSec+pauseSec+fadeSec+delaySec)*1000);
	}
	
}

// Utility function for advanceRotator(), fades all rotator elements
function fadeRotator() {
	// Fade the rotator elements
	new Effect.Parallel(
		[ new Effect.Fade('RotatorTab', { sync: true }), 
		new Effect.Fade('RotatorContent', { sync: true }), 
		new Effect.Fade('RotatorCallout', { sync: true }) ],
		{ duration: fadeSec , 
		afterFinish: function(effect)
			// Set timer for next rotator advance
			{ window.setTimeout('advanceRotator()', delaySec*1000); } 
		}
	);	
}


// Sets appropriate HTML element attributes to the object attributes at the matching index in the rotator array
function setRotator(index) {
	if (index > 0) {
		$('RotatorTabImg').src = rotator[index].tabSrc;
		$('RotatorTabImg').alt = rotator[index].tabAlt;
		$('RotatorTabLink').href = rotator[index].href;
		$('RotatorTabLink').title = rotator[index].tabAlt;
		$('RotatorTabLink').target = rotator[index].target;
			
		$('RotatorCalloutImg').src = rotator[index].calloutSrc;
		$('RotatorCalloutImg').alt = rotator[index].calloutAlt;
		$('RotatorCalloutLink').href = rotator[index].href;
		$('RotatorCalloutLink').title = rotator[index].calloutAlt;
		$('RotatorCalloutLink').target = rotator[index].target;
		
		$('RotatorContentImg').src = rotator[index].contentSrc;
		$('RotatorContentImg').alt = rotator[index].contentAlt;
		$('RotatorContentLink').href = rotator[index].href;
		$('RotatorContentLink').title = rotator[index].contentAlt;
		$('RotatorContentLink').target = rotator[index].target;
	}
	else {
		$('RotatorTab').hide();
		$('RotatorCallout').hide();
		$('RotatorContent').hide();
	}
}