var tabIndexauto = 0;
var rotatorauto;
var currentauto = 0;
var timerRunningauto=false;
var tabCountauto = 0;
var continuousHeroTabsAuto;																		// Total number of modules

document.getElementsByClassName = function(clsName){											// Utility function to get elements by class name
    var retVal = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++){
        if(elements[i].className.indexOf(" ") >= 0){
            var classes = elements[i].className.split(" ");
            for(var j = 0;j < classes.length;j++){
                if(classes[j] == clsName)
                    retVal.push(elements[i]);
            }
        }
        else if(elements[i].className == clsName)
            retVal.push(elements[i]);
    }
    return retVal;
}

function showHeroTabauto(tabId) {
	/*If play/pause element is not found on page return*/
	if(!(document.getElementById("playPauseImageIdauto")))
		return;
	
		var tabHeader = document.getElementById("tab-listauto").getElementsByTagName("LI");
		for (var i=0; i<tabHeader.length; i++) {
			tabHeader[i].className = null;
		}
		var heroV4 =YAHOO.util.Dom.getElementsByClassName("subtemplateP1autoEnt");
		for( var i = 0; i<heroV4.length; i++ ) {                       
			if(i==tabId){
				heroV4[i].style.display = "block";
				// Added  on 24 Feb 2009 - ShowHearoTab Rotate - Start
				currentauto = i;
				// Added  on 24 Feb 2009 - ShowHearoTab Rotate - End
			}else{
				heroV4[i].style.display = "none";                                                                                                                                                                                                                              // Hide all divs
			}
		}
		tabHeader[tabId].className = "selected";
		heroV4[tabId].style.display = "block";
		timerRunningauto = false;
		clearTimeout(rotatorauto);
		
		// Added  on 24 Feb 2009 - ShowHearoTab Rotate - Start
		var img = document.getElementById("playPauseImageIdauto").src;
		img = img.replace("pause_btn","play_btn");
		document.getElementById("playPauseImageIdauto").src = img; 
		// Added  on 24 Feb 2009 - ShowHearoTab Rotate - End
};

// Pause auto rotate
function playPauseHeroTabRotatorauto()
{
	if(tabCountauto.length==undefined)
	{
		return;
	}
	// Added  on 24 Feb 2009 - Play and Pause button function - Start
	var tempImg = document.getElementById("playPauseImageIdauto").src;
	if(tempImg.indexOf('play_btn') != -1)			
	// Added  on 24 Feb 2009 - Play and Pause button function - End
	
	// Commented  on 24 Feb 200
	//if(timerRunningauto == false)
	{
		timerRunningauto = true;																	// set flag to true...
		rotatorauto = setTimeout("tabRotatorauto()", 7000);											// start timer
		var img = document.getElementById("playPauseImageIdauto").src;
		img = img.replace("play_btn","pause_btn");				
		document.getElementById("playPauseImageIdauto").src = img;								// Change image to paused
	} 
	// Added  on 24 Feb 2009 - Play and Pause button function - else part - Start
	else if(tempImg.indexOf('pause_btn') != -1)	
	// Added  on 24 Feb 2009 - Play and Pause button function - else part - End
	
	// Commented  on 24 Feb 2009
	//else if(timerRunningauto == true)
	{
		timerRunningauto = false;																	// set flag to false...
		clearTimeout(rotatorauto);																	// stop timer
		var img = document.getElementById("playPauseImageIdauto").src;
		img = img.replace("pause_btn","play_btn");
		document.getElementById("playPauseImageIdauto").src = img;								// Change image to play
	}
};


function nextHeroTabauto()
{

	if(tabCountauto.length==undefined)
	{
		return;
	}
	// Added  on 24 Feb 2009 - Next button function - Start
	currentauto++;
	if( currentauto > ( tabCountauto.length - 1 ) )
		currentauto = 0;
	// Added  on 24 Feb 2009 - Next button function - Start
	
	// Commented  on 24 Feb 2009
	/*
	if( currentauto >= ( tabCountauto.length - 1 ) )
		currentauto = 0;
	else
		currentauto++;
	*/	
	var tabHeader = document.getElementById("tab-listauto").getElementsByTagName("LI");
	for (var i=0; i<tabHeader.length; i++) {
		tabHeader[i].className = null;
	}
	
	tabHeader[currentauto].className = "selected";
	var heroV4 =YAHOO.util.Dom.getElementsByClassName("subtemplateP1autoEnt");
	for( var i = 0; i<heroV4.length; i++ ) {
		if(i==currentauto){
			heroV4[i].style.display = "block";														
		}else{
			heroV4[i].style.display = "none";														// Hide all divs
		}
	}
	
	// Added  on 24 Feb 2009 - Next button function - Start
	var img = document.getElementById("playPauseImageIdauto").src;
	img = img.replace("play_btn","pause_btn");
	document.getElementById("playPauseImageIdauto").src = img;	
	// Added  on 24 Feb 2009 - Next button function - End
	
	timerRunningauto = false;
	clearTimeout(rotatorauto);
	
	// To view slide show of tabs even after clicking next, uncomment below 4 lines and comment line #116 to #118
	rotatorauto = setTimeout("tabRotatorauto()", 7000); 
	//var img = document.getElementById("playPauseImageIdauto").src;
	//img = img.replace("play_btn","pause_btn");
	//document.getElementById("playPauseImageIdauto").src = img;	
};


function previousHeroTabauto()
{

	if(tabCountauto.length==undefined)
	{
		return;
	}
	var tabHeader = document.getElementById("tab-listauto").getElementsByTagName("LI");
	for (var i=0; i<tabHeader.length; i++) {
		tabHeader[i].className = null;
	}
	var heroV4 =YAHOO.util.Dom.getElementsByClassName("subtemplateP1autoEnt");

	for( var i = 0; i < heroV4.length; i++ )
	{
		if(heroV4[i].style.display == "block")
			currentauto = i;
	}
	currentauto--;
	if( currentauto <0 )
	{
		currentauto = ( tabCountauto.length - 1 );
	}
	for( var i = 0; i<heroV4.length; i++ ) {		
		
		if(i==currentauto){
			heroV4[i].style.display = "block";														
		}else{
			heroV4[i].style.display = "none";														// Hide all divs
		}
		
	}
	
	// Added  on 24 Feb 2009 - Previous button function - Start
	var img = document.getElementById("playPauseImageIdauto").src;
	img = img.replace("play_btn","pause_btn");
	document.getElementById("playPauseImageIdauto").src = img; 
	// Added  on 24 Feb 2009 - Previous button function - End
	
	tabHeader[currentauto].className = "selected";
	heroV4[currentauto].style.display = "block";
	timerRunningauto = false;
	clearTimeout(rotatorauto);
	
	// To view slide show of tabs even after clicking previous, uncomment below 4 lines and comment line #161 to #163
	rotatorauto = setTimeout("tabRotatorauto()", 7000); 
	//var img = document.getElementById("playPauseImageIdauto").src;
	//img = img.replace("play_btn","pause_btn");
	//document.getElementById("playPauseImageIdauto").src = img;
};


function tabRotatorauto(){

	currentauto++;
	if( currentauto > ( tabCountauto.length - 1 ) )
		currentauto = 0;

	var tabHeader = document.getElementById("tab-listauto").getElementsByTagName("LI");

	for (var i=0; i<tabHeader.length; i++) {
		tabHeader[i].className = null;
	}
	tabHeader[currentauto].className = "selected";

	
	var heroV4 = YAHOO.util.Dom.getElementsByClassName("subtemplateP1autoEnt");
	
	for( var i = 0; i<heroV4.length; i++ ) {
		if(i==currentauto){
			heroV4[i].style.display = "block";														
		}else{
			heroV4[i].style.display = "none";														// Hide all divs
		}
	}
	
	timerRunningauto = true;
	rotatorauto = setTimeout("tabRotatorauto()", 7000);
};

function initTabRotatorauto() {

	tabCountauto = YAHOO.util.Dom.getElementsByClassName("subtemplateP1autoEnt");									// Get count of total number of modules
	try {
		// Added  on 24 Feb 2009 - tab Rotate - Start
		currentauto--;
		// Added  on 24 Feb 2009 - Tab Rotate - End
		tabRotatorauto();
	} catch(ex) {
		return;
	}
}


function repeatTabsAuto(direction)
{
	if( direction == "previous" )
	{
		previousHeroTabauto();
		continuousHeroTabsAuto = setTimeout("repeatTabsAuto('previous')", 400);
	}
	else if( direction == "next" )
	{
		nextHeroTabauto();
		continuousHeroTabsAuto = setTimeout("repeatTabsAuto('next')", 400);
	}
}

function clearFWDBCKBtnHeldTimerAuto() {
	clearTimeout(continuousHeroTabsAuto);
}

YAHOO.util.Event.addListener(window, "load", initTabRotatorauto);