var tickspeed=5000 //ms

var selectedDiv = 0
var totalDivs = 0
var timerId = 0
var started = 0

if (window.addEventListener)
	window.addEventListener("load", startSlider, false)
else if (window.attachEvent)
	window.attachEvent("onload", startSlider)
else if (document.getElementById)
	window.onload = startSlider
	

function getElementbyClass(classname)
{
	divArray=new Array()
	var count = 0
	var tags = document.all? document.all.tags("DIV") : document.getElementsByTagName("*")

	// store all content
	for(i = 0; i < tags.length; i++)
	{
		if (tags[i].className == classname)
			divArray[count++] = tags[i]
	}
}
function getElementbyIdName(id)
{
	var count = 0
	idArray = document.getElementsByName(id)
}

function hideAllContent()
{
	var index = 0
	
	// hide all content
	while (divArray[index])
	{
		divArray[index].style.display="none"
		index++
	}
}

function showContent()
{
	var selectedDivObj = divArray[selectedDiv]
	hideAllContent()
	selectedDivObj.style.display="block"
	selectedDiv=(selectedDiv < totalDivs-1) ? selectedDiv+1 : 0
	
	if(started == 1)
		timerId = setTimeout("showContent()",tickspeed)
}
function selectContent(num)
{
	if(started == 1)
		clearTimeout(timerId)
		
	selectedDiv = num
	showContent()
}

function startSlider()
{
	getElementbyClass("mostPopularContainer")
	totalDivs = divArray.length
	started = 1
	showContent()
}
function pauseContent()
{
	started = 0
	clearTimeout(timerId)
}
function playContent()
{
	if(started != 1)
	{
		if(selectedDiv != 0)
			selectedDiv -= 1
			
		started = 1
		showContent()	
	}
}
function pauseAll()
{
	for(i = 1; i <= 6; i++)
	{
		document.getElementById('pauseplayButton' + i).innerHTML = '||';
	}
	/*for(i = 0; i < idArray.length; i++)
	{
		idArray[i].innerHTML = '||';
	}*/
}
function playAll()
{
	for(i = 1; i <= 6; i++)
	{
		document.getElementById('pauseplayButton' + i).innerHTML = '\u25BA';
	}
	
	/*for(i = 0; i < idArray.length; i++)
	{
		idArray[i].innerHTML = '\u25BA';
	}*/
}
function togglePausePlayButton()
{
	//getElementbyIdName('pauseplayButton')
	
	if(document.getElementById('pauseplayButton1').innerHTML == '\u25BA')
	{
		pauseAll()
		playContent()
	}
	else
	{
		playAll()
		pauseContent()
	}
	
	/*if(idArray[selectedDiv].innerHTML == '\u25BA')
	{
		pauseAll()
		playContent()	
	}
	else
	{
		playAll()
		pauseContent()
	}*/
}
