// JavaScript Document
var xmlHttp=null;
var pList_State="1";
var pList_Type="Dailys1";
var pUrl;
var pRawTextResult;
var pStartTime;
var col=0;

function ajaxFunction()
{

		try
		  {
		  // Firefox, Opera 8.0+, Safari
		  xmlHttp=new XMLHttpRequest();
		  }
		catch (e)
		  {
		  // Internet Explorer
		  try
			{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
		  catch (e)
			{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		  }
 
	   
	xmlHttp.onreadystatechange=GetTopLIST;
	xmlHttp.open("GET",pUrl,true);
	xmlHttp.send(null);      
   
}   

function GetTopLIST() 
{ 
//document.write(xmlHttp.readyState);
	if (xmlHttp.readyState==4)
	{ 
		switch (pList_State)
		{
			case "1-2":
				pRawTextResult = xmlHttp.responseText;
				pList_State = "1-3";
			break;
		}


		
		
	}
}



function DisplayTopLists() 
{
//document.write("<p>"+ pList_State);
	switch (pList_State)
	{
		case "1":
			

			var random_num = Math.floor(Math.random()*9999 );			
		
			switch (pList_Type) {
				
				case "Dailys1":
					pUrl = "../feeds/SocioTownDailyTopLists.txt?rm="+random_num; 			
				break;
				case "Dailys2":
					pUrl = "../feeds/SocioTownDailyTopLists.txt?rm="+random_num; 			
				break;
				case "Dailys3":
					pUrl = "../feeds/SocioTownDailyTopLists.txt?rm="+random_num; 			
				break;
				case "Online":
					pUrl = "../feeds/SocioTownOnlineNowLists.txt?rm="+random_num; 				
				break;				
				
			}
		
			ajaxFunction()
			pList_State = "1-2";
		break;
		case "1-3":
				col = 255;
				document.getElementById("toplist").style.color="rgb(" + col + "," + col + "," + col + ")"; 		

        			switch (pList_Type) {
        				
        				case "Dailys1":
        					GenerateListWithoutLinks(0,2) 					
        				break;
        				case "Dailys2":
        					GenerateListWithoutLinks(3,3) 					
        				break;
        				case "Dailys3":
        					GenerateListWithoutLinks(4,4) 					
        				break;
        				case "Online":
        					GenerateListWithoutLinks(0,2) 							
        				break;				
        				
        			}									
				fadeIn()
				pList_State = "1-4";			
		break;
		case "1-4":
						// Fade In
				if (col == 0) {
				pList_State = "2";
				}
		break;
		case "2":

			
			switch (pList_Type) {
				
				case "Dailys1":
					GenerateListWithLinks(0,2) 					
				break;
				case "Dailys2":
					GenerateListWithLinks(3,3) 					
				break;
				case "Dailys3":
					GenerateListWithLinks(4,4) 					
				break;
				case "Online":
					GenerateListWithLinks(0,2) 							
				break;				
				
			}
			pList_State = "2-2";
					
		break;
		
		case "2-2":
		
			// Fade In
				var DateObj = new Date();

				pStartTime = DateObj.getTime();
				pList_State = "2-3";


		break;

		case "2-3":		

			var DateObj = new Date();		
			
			var elapsed_time = DateObj.getTime() - pStartTime
		
			if (elapsed_time > 10000) {

				
        			switch (pList_Type) {
        				
        				case "Dailys1":
        					GenerateListWithoutLinks(0,2) 					
        				break;
        				case "Dailys2":
        					GenerateListWithoutLinks(3,3) 					
        				break;
        				case "Dailys3":
        					GenerateListWithoutLinks(4,4) 					
        				break;
        				case "Online":
        					GenerateListWithoutLinks(0,2) 							
        				break;				
        				
        			}						
				
				
				fadeOut()
				pList_State = "2-4";
			}
			
		break;
		
		case "2-4":
				// Fade Out
				if (col == 255) {
				document.getElementById('toplist').innerHTML= ""; 
				col = 0;
				document.getElementById("toplist").style.color="rgb(" + col + "," + col + "," + col + ")"; 
				pList_State = "3";
				}
		break;	
		
		
		case "3":
		
		
			switch (pList_Type) {
				
				case "Dailys1":
					pList_Type = "Dailys2";	
					pList_State = "1";					
				break;
				case "Dailys2":
					pList_Type = "Dailys3";	
					pList_State = "1";					
				break;
				case "Dailys3":
					pList_Type = "Online";	
					pList_State = "1";					
				break;
				case "Online":
					pList_Type = "Dailys1";			
					pList_State = "1";							
				break;				
				
			}		


		break;
		
		
	}	


}

function GenerateListWithLinks(start, end) 
{

		document.getElementById('toplist').innerHTML= ""; 
		
		var raw_text = pRawTextResult;
		
		
		var the_lists = raw_text.split("\n");
		
		for (var i = start; i < end+1; i++) {
			var top_list = the_lists[i].split("/");
			
				var list_name = top_list[0]
				document.getElementById("toplist").innerHTML += "<p><strong><span class='style50'>"+list_name+"</span></strong></p>";		
				
				for (var n = 1; n < top_list.length; n++) {
					if (n <= 5) {					
						var player_name = top_list[n]				
						document.getElementById("toplist").innerHTML += "<span class='style50'><a href='../profile.html?u="+player_name+"' target='_blank'>"+player_name+"</a></span><br>";									
					}
				}
			
		}				


}

function GenerateListWithoutLinks(start, end)
{

		document.getElementById('toplist').innerHTML= ""; 
		
		var raw_text = pRawTextResult;
		
		
		var the_lists = raw_text.split("\n");
		
		for (var i = start; i < end+1; i++) {
			

				var top_list = the_lists[i].split("/");
				
					var list_name = top_list[0]
					document.getElementById("toplist").innerHTML += "<p><strong><span class='style50'>"+list_name+"</span></strong></p>";		
					
					for (var n = 1; n < top_list.length; n++) {
						if (n <= 5) {
							var player_name = top_list[n]				
							document.getElementById("toplist").innerHTML += "<span class='style50'>"+player_name+"</span><br>";									
						}
					}
			
		}	

}


function fadeOut() { 
document.getElementById("toplist").style.color="rgb(" + col + "," + col + "," + col + ")"; 
col+=15; 
	if(col<255) {
	setTimeout('fadeOut()', 50) 
	} else { col = 255; }
}

function fadeIn() { 
document.getElementById("toplist").style.color="rgb(" + col + "," + col + "," + col + ")"; 
col-=15; 
	if(col>0) {
	setTimeout('fadeIn()', 50) 
	} else { col = 0; }
}

