/********** Top Tens Click Handlers Start *********/
$(document).ready(function()
{
	if($('#toptenheader').length)
	{	
		var tabArray = $('#toptenheader h2');
		var contentArray = $('#handsetscontainer div');
		
		//the top ten tabs onClick handler
		$('#toptenheader h2').click(function()
		{	
			//remove tabon classes and content
			$('#toptenheader h2').removeClass("tabOn");	
			
			
			//set last tab id back to last tab
			if($('#lastTabOn').length)
			{
				$('#lastTabOn').attr("id", "lastTab");
			}		
			
			if($(this).attr("id") == "lastTab")
			{
				$('#lastTab').attr("id", "lastTabOn");
				//on last tab change id to last tab on
			}
			else
			{		
				//add class tabon to (this) element
				$(this).addClass("tabOn");
			}
			
			var tabKey = getArrayKey(tabArray, $(this).text());		
			
			if(tabKey != -1)
			{
				if ($(contentArray[tabKey]).length)
				{
					$('#handsetscontainer div').removeClass("curTopTen");
					$(contentArray[tabKey]).addClass("curTopTen");
				}
			}
			
		});
	}
});

function getArrayKey(array, value)
{
	var result = -1;
	var arrayLen = array.length;
	
	if(arrayLen > 0)
	{
		for(var a = 0; a < arrayLen; a++)
		{			
			if ($(array[a]).text() == value)
			{				
				result = a;				
				break;
			}
		}
	}
	
	return result;
}

/*********** Top Tens Click Handlers End **********/