
/****************************************
 ** Feature Rotator
 ** 01/17/2008
 ** Sunil Karve, on behalf of LexisNexis
 ****************************************/

var rotateImageID; // ID of the image to be rotated; set in the <head> of the calling document
var featImg; // Reference to the rotating image
var featLink; // Reference to the target url of rotating image
var rotateInterval = 5000; // Rotation delay period in milliseconds, defaults to 5 seconds
var featCounter = 0;  // Index of current feature

function initFeature() { // Load JS and check compatibility

	if(!document.getElementById) { return; } // Stop execution if getElementById not supported

	featImg = document.getElementById( rotateImageID ); // Get reference to specified image
	if (featImg == null) { return; }
	
	if( featImg.parentNode.nodeName == "A") { // Check if rotating image is hyperlinked and get reference to the link
		featLink = featImg.parentNode;		
	}
	
	preloadRotateImages(); // Preload all images for quick response

	
	rotateFeature(); // Begin initial rotation
	var rotateTimer = setInterval("rotateFeature()", rotateInterval); //  Repeat at specified interval

}

function rotateFeature() { // Change attributes of rotating image, and its link target if available

		featImg.setAttribute("src", featureArray[featCounter][0]);
		featImg.setAttribute("alt", featureArray[featCounter][1]);
		
		if( featLink != null ) { // Assign stored href to parent node (if it exists)
			featLink.setAttribute("href", featureArray[featCounter][2]);
		}

	featCounter++;
	
	// Reset rotation index if end of list reached
    if( featCounter == featureArray.length ) { featCounter = 0 };

}

function preloadRotateImages() {
	
	var preloadArray = new Array();
	for( var k=0; k < featureArray.length; k++ ) {
		preloadArray[k] = new Image();
		preloadArray[k].src = featureArray[k][2];
	} 
}