/**************************************************************************
*
*
*
**************************************************************************/
function showFeature(feature_id, link_num) { 
var rotatorNode = window.document.getElementById(feature_id).parentNode.firstChild;

while ( rotatorNode != null ) {
	
	/* Get the current height of the rotator div */
	
	/* Get the new height of the rotator div */
	
	/* Modify the height of the div */ 
	
	
	/* Check if the tag is actually a div */ 
	if ( rotatorNode.tagName == "DIV" && rotatorNode.id != feature_id && rotatorNode.className != "rot_controller"){
		
		/* Hide all Feature Items */ 
		
											
		
		rotatorNode.className = "rot_container_hidden"; 
		
	} 
	else if (rotatorNode.id == feature_id)
	{
		/* Show the current Feature Item */ 

		rotatorNode.className = "rot_container";
		
	}
	else if (rotatorNode.tagName == "DIV" && rotatorNode.className == "rot_controller"){
		var linkNode = rotatorNode.firstChild;
		while (linkNode != null) {
			if(linkNode.tagName == "UL"){
				var listNode = linkNode.firstChild;
				while(listNode != null)	{
					if(listNode.tagName == "LI"){
						if(listNode.firstChild.tagName=="A" && listNode.firstChild.innerHTML == link_num){
							listNode.firstChild.className = "selected";
						}
						else if(listNode.firstChild.tagName=="A"){
							listNode.firstChild.className = null;
						}
					}
					listNode = listNode.nextSibling;
				}
			}
			linkNode = linkNode.nextSibling;
		}
	}
	
	/* Move to the next node */ 
	rotatorNode = rotatorNode.nextSibling; 				
}

}

/**************************************************************************
*
*
*
**************************************************************************/
function rotatorFeatureCount(rotatorWrapperId) { 

this.numberOfFeatures = 0;

this.rotatorFeatures = new Array(0);


this.rotatorWrapperNode = window.document.getElementById(rotatorWrapperId); 

if(this.rotatorWrapperNode == null)
return null;

var rotatorNode = this.rotatorWrapperNode.firstChild 

/* Walk through the children of the parent container */ 
while ( rotatorNode != null ) {
	
	/* Check if the tag is actually a div */ 
	if ( rotatorNode.tagName == "DIV" ){
		/*Assign element object to array*/
		rotatorFeatures[rotatorFeatures.length] = window.document.getElementById(rotatorNode.id);							
	} 
	
	/* Move to the next node */ 
	rotatorNode = rotatorNode.nextSibling; 				
}

return (this.rotatorFeatures); 
}

/**************************************************************************
*
*
*
**************************************************************************/
function initRotator(rotatorWrapperId, class_hidden, rot_controller, rot_content) { 

/* Variables */ 
if(rotatorWrapperId == null || class_hidden == null || rot_controller == null || rot_content== null)
	return;	


/* Count how many divs are in the parent */ 
var rotatorFeatures = rotatorFeatureCount(rotatorWrapperId); 

if ( rotatorFeatures.length == 0 || rotatorFeatures == null ) return;


/* Hide all but the first one */ 
for ( var x=1; x < rotatorFeatures.length; x++)
{
	/*Set class to hidden class*/
	rotatorFeatures[x].className = class_hidden;	
}


/* Create and display the controller */ 
this.controller_div = document.createElement("div");
this.controller_div.className = rot_controller;
this.list_ul = document.createElement("ul");

controller_div.appendChild(this.list_ul);

for ( var x=0; x < rotatorFeatures.length; x++ )
{
	var listItem_li = document.createElement("li");

	var featureLink = document.createElement("a"); 
	
	/* Set the href attribute so that you can tab on it */ 
	featureLink.setAttribute( 'href' , "javascript: showFeature('" + rotatorFeatures[x].id + "', + '" + (x+1) + "');" ); 
	
	if(x == 0)
		featureLink.className = "selected";
	
	var contentNodes = rotatorFeatures[x].firstChild;
	var title = null;
	 
	/* Walk through the children of the parent container */ 
	while ( contentNodes != null && title == null) {
		
		/* Check if the tag is actually a div */ 
		if ( contentNodes.tagName == "DIV" && contentNodes.className == rot_content ){
			var titleNode = contentNodes.firstChild;
			
			while ( titleNode != null && title == null) { 
				if ((titleNode.tagName == "H2" || titleNode.tagName == "H3") && title == null){
				title = titleNode.innerHTML;
				}
				
				titleNode = titleNode.nextSibling; 
				
			}
		} 
		
		/* Move to the next node */ 
		contentNodes = contentNodes.nextSibling; 				
	}
	
	if (title != null)
		featureLink.setAttribute( 'title' , title); 
	else
		featureLink.setAttribute( 'title' , "Click here to see feature item " + (x+1)); 
	
	/* Set the link text */ 
	featureLink.appendChild( document.createTextNode( x + 1 ) ); 
	/* Append the link to the list item */ 
	listItem_li.appendChild(featureLink); 

		
	
	this.list_ul.appendChild(listItem_li);
}


window.document.getElementById(rotatorWrapperId).appendChild(this.controller_div);


}
