﻿//HTML List Rotation (with image banners)
//Copyright: Polk County BoCC, Information Technology
//COMMENTS: list is generated by featureditems.xsl

//default list item with image value; initial increment moves to array 0
var thisItem = -1;
//boolean to start rotation; default is 1 or true
var blnRotate = 1;
//time between image rotation - miliseconds
var intRotationTime = 5000;
//object var to store setTimeout values
var objTimeOut = '';

//main - starts the display of the banners
function fnFeaturedItems()
{
	//***** BEGIN ACCESSIBILITY ITEMS *****
	//display banner controls; they are hidden by default in case JS is disabled
	var bnrCtrls = document.getElementById('controls');
	bnrCtrls.style.display = "block";
	// capture the UL that holds the list of featured item images
	var itemsUL = document.getElementById('content_featured');
	// array of LI tags within the UL that holds the list of images
	var itemLI = itemsUL.getElementsByTagName('li');
	//if JS enabled, hide all images in list;
	for(var i = 0; i < itemLI.length; i++){itemLI[i].style.display = "none";}
	//***** END ACCESSIBILITY ITEMS *****
	
	//if JS is enable banner rotation will start
	if(document.getElementById || document.all){fnRotate();}else{alert('Your browser does not support the Featured Items rotating banner.');}
	
}

//fnRotate: handles rotation of images
function fnRotate(){if (blnRotate){fnDisplayItem("rotate");}objTimeOut = setTimeout("fnRotate()",intRotationTime);}

//fnDisplayItem: handles display/hide if list elements with images
function fnDisplayItem(strAction)
{	
	// capture the UL that holds the list of featured item images
	var itemsDIV = document.getElementById('banners');
	// capture the UL that holds the list of featured item images
	var itemsUL = document.getElementById('content_featured');
	// array of LI tags within the UL that holds the list of images
	var itemLI = itemsUL.getElementsByTagName('li');
	//chg button state
	if (strAction == 'prev' || strAction == 'next'){blnRotate = 1;fnStartStop();}
	
	if (strAction == 'prev')
	{
		//decrement if less than array length
		if (thisItem < itemLI.length){thisItem--;}
		//reset to last item in array		
		if (thisItem < 0){thisItem=itemLI.length-1;}
	}
	
	if (strAction == 'rotate' || strAction == 'next')
	{
		//increment if less than array length
		if (thisItem < itemLI.length){thisItem++}
		//reset to 0 if greater than length		
		if (thisItem >= itemLI.length){thisItem=0}	
	}
	
	//loop over array of list items and display or hide based on thisItem
	for(var i = 0; i < itemLI.length; i++)	
	{
		//display matching list item
		if (thisItem == i){itemLI[i].style.display = "block"}
		//hide unmathced items
		else{itemLI[i].style.display = "none"}
	}
}
//starts and stops the scrolling
function fnStartStop()
{
	if(blnRotate)
	{
		//stop rotation
		blnRotate = 0;
		document.images['scrollAction'].src = 'images/btn_bannerstart.jpg';
		clearTimeout(objTimeOut);		
	}	
	else
	{
		//start rotation
		blnRotate = 1;
		document.images['scrollAction'].src = 'images/btn_bannerstop.jpg';
		fnRotate();
	}
}