

setTimeout('Main()',500);

var webGames_req = false;

function Main()
{
	
	prepareWebGamesData();
	
	
	showHotGamesContent();
	
	
	getAllCompanys("Cmps","companyTagContainer");
}



function inializeAllTags()
{
	initializeCharachtorTags();
	initializeCmpsTags();
	initializeGamesContent();
	initializeCmpGamesContent();
}


function initializeCharachtorTags()
{
	var objCharactors = document.getElementById('tagFrame').getElementsByTagName('li');
	
	for(i=0; i<objCharactors.length; i++)
	{
		if(i==0)
		{
			objCharactors[i].className="list2_Off";
		}
		else if(deletedSpacechar(objCharactors[i].innerHTML) == "网页游戏")
		{
			objCharactors[i].className="list2_Off";
		}
		else if(deletedSpacechar(objCharactors[i].innerHTML) == "Z")
		{
			objCharactors[i].className="list_Off rightLine";
		}
		else
		{
			objCharactors[i].className = "list_Off";
		}
	}
}


function initializeCmpsTags()
{
	var objContainer = document.getElementById('companyTagContainer').getElementsByTagName('li');
	for(i=0; i<objContainer.length; i++)
	{
		objContainer[i].style.color="#0066cc";
	}
}


function initializeGamesContent()
{
	var objContainer = document.getElementById('gContainer').getElementsByTagName('div');
	for(i=0; i<objContainer.length; i++)
	{
		objContainer[i].style.display="none";
	}
}


function initializeCmpGamesContent()
{
	var objContainer = document.getElementById('companyGContainer').getElementsByTagName('div');
	for(i=0; i<objContainer.length; i++)
	{
		objContainer[i].style.display="none";
	}
}



function settingCurrentStyle(_currentObj)
{
	var currentText = deletedSpacechar(_currentObj.innerHTML);
	if(currentText == "热门游戏")
	{
		_currentObj.className = "list2_On";
	}
	else if(currentText == "网页游戏")
	{
		_currentObj.className = "list2_On";
	}
	else if(currentText == "z" || currentText=="Z")
	{
		_currentObj.className = "list_On rightLine";
	}
	else
	{
		_currentObj.className = "list_On";
	}
}


function settingCmpsCurrentStyle(_currentObj)
{
	
	_currentObj.style.color = "#ff6600";
}


function hideCompanysTag(_currentObj)
{	
	var obj = document.getElementById('companyTagContainer');
	
	var _innerText = deletedSpacechar(_currentObj.innerHTML);
	if(_innerText == "热门游戏")
	{
		obj.style.display = "block";
	}
	else
	{
		obj.style.display = "none";
	}
}


function prepareWebGamesData()
{
	webGames_req = getRequestInstance();
	webGames_req.onreadystatechange = onWebGamesCallback;
	var u = encodeURIComponent("http://www.5173.com/ajax.axd?methodName=GETWWWWEBGAMES");
	webGames_req.open("POST", '/Controls/Common/Proxy.aspx?url=' +u, true);
	webGames_req.send("");
}


function onWebGamesCallback()
{
	if(webGames_req.readyState == 4)
	{
		if(webGames_req.status == 200)
		{
			var str = webGames_req.responseText.split("$")[0];
			var objContainer = document.getElementById('gContainer');
			
			objContainer.innerHTML += str;
		}
	}
}


 function getAllCompanys(preTag, container)
 {
	
	
	var companys ="";
	
	var compsValue = splitDetailDatas(preTag);
	if(compsValue)
	{
		
		companys = compsValue;
		productCompanysHTML(preTag,companys,container);
	}
 }

 
 function showTagDetail(_event)
 {
    _event = window.event ||  _event;
    
 	
 	inializeAllTags();
	
 	var getGamesTag = "";
	var divId = "";
	;
 	var objCurrent = _event.srcElement || _event.target;
 	var currentId = objCurrent.id;
	var currentClass = objCurrent.className;
	var currentText = objCurrent.textContent || objCurrent.innerText;
    currentText = deletedSpacechar(currentText);
	
	switch(currentText)
	{
		case "热门游戏":
			divId = "layerHot";
			getGamesTag = "hotG";
			getGamesList(divId,getGamesTag,objCurrent);
			break;
		case "网页游戏":
			divId = "Divwg";
			getGamesTag = "Divwg";
			setWebGamesLayer();      
			break;
		default:    
			divId = "layer" + currentText;
			getGamesTag = currentText.toLowerCase();
			getGamesList(divId,getGamesTag,objCurrent);
			break;
	}
	
	
	document.getElementById(divId).style.display="block";
	settingCurrentStyle(objCurrent);
	hideCompanysTag(objCurrent);
 }
 
  
 function showCompanyDetail(_event)
 {
    _event = window.event || _event;
     
 	
 	inializeAllTags();
	
 	
	var objCurrent = _event.srcElement || _event.target;
	var currentText = deletedSpacechar(objCurrent.innerHTML);

	var gamesInstance = splitDetailDatas('CompG');
	var games = getEachGamesDetail(currentText,gamesInstance);
	
	
	productCmpGamesHtml(objCurrent,currentText,games);
	
	
	settingCmpsCurrentStyle(objCurrent);
 }
 
 
 
 function showHotGamesContent()
 {
	var divId = "layerHot";
	var getGamesTag = "hotG";
	var m_objLi = document.getElementById('tagFrame').getElementsByTagName('ul')[0];
	var objCurrent = m_objLi.getElementsByTagName('li')[0];  
	getGamesList(divId,getGamesTag,objCurrent);
 }
 
 
 
 
 function getEachGamesDetail(cmpName,tagValue)
 {
	var ret = "";
	
	var allValues = tagValue;
	
	var objCmpGs = allValues.split('&');
	if(objCmpGs)
	{
		for(i=0; i<objCmpGs.length; i++)
		{
			if(objCmpGs[i])
			{
				if(objCmpGs[i] != "")
				{
					var tagCmpNameIns = objCmpGs[i].split(',');
					if(tagCmpNameIns)
					{
						for(j = 0; j<tagCmpNameIns.length; j++)
						{
							var eachGame = tagCmpNameIns[j].split('#');
							if(deletedSpacechar(eachGame[0]) == deletedSpacechar(cmpName))
							{
								ret += eachGame[1] + ",";
							}
						}
					}
				}
			}
		}

	}
	return ret;
 }
 

 
 function getGamesList(_divId,_getGamesTag,_currentObj)
 {
 	var games = splitDetailDatas(_getGamesTag);
	if(games !="")
	{
		
		var targetObj = document.getElementById(_divId);
		if(targetObj)
		{
			if(targetObj.innerHTML !="")
			{
				targetObj.style.display = "block";
			}
		}
		else
		{
			productGamesHTML(_divId,_getGamesTag,games,_currentObj);
		}
	}
	else
	{
		
		inializeAllTags();
		
		
		
		if(document.getElementById(_divId))
		{
			document.getElementById(_divId).style.display = "block";
		}
		else
		{
			var tipDiv = document.createElement("div");
			tipDiv.id= _divId;
			tipDiv.innerHTML="该字母下暂时没有游戏!";
			tipDiv.style.textAlign="center";
			tipDiv.style.display="block";
			document.getElementById("gContainer").appendChild(tipDiv);
		}
	}
 }
 
 
 
 function setWebGamesLayer()
 {
 	var objWebGame = document.getElementById("Divwg");
	if(objWebGame)
	{
		objWebGame.style.display = "block";
	}
	else
	{
		
		prepareWebGamesData();
		document.getElementById("Divwg").style.display='block';
	}
 }


 
 function splitDetailDatas(prefix)
 {
	var ret = "";
	
	var allGamesContent = golabelParams;
	
	var m_tagObjs = allGamesContent.split(';');
	if(m_tagObjs)
	{
		for(i=0; i<m_tagObjs.length; i++)
		{
			if(m_tagObjs[i] && m_tagObjs[i] !="")
			{
				var tagObjPrefix = m_tagObjs[i].split(':')[0];
				if(tagObjPrefix)
				{
					if(deletedSpacechar(tagObjPrefix) == deletedSpacechar(prefix))
					{
						ret = m_tagObjs[i].split(':')[1];
						break;
					}
				}
			}
		}
	}
	
	return ret;
 }
 
 
 
 function productCompanysHTML(prefix,_games,_container)
 {
	var objContainer = document.getElementById(_container);
	var oUl = document.createElement('ul');

	if(objContainer)
	{
		
		objContainer.innerHTML = "";
		
		var m_collection = _games.split(",");
		if(m_collection)
		{
			for(i=0; i<m_collection.length; i++)
			{
				if(m_collection[i] != "")
				{
					var oLi = document.createElement('li');
					oLi.id = "tagCmp" + i;
					oLi.innerHTML = deletedSpacechar(m_collection[i]);
					oLi.onclick = function(e){
					    e = window.event || e;
					    showCompanyDetail(e);};
					    
					oUl.appendChild(oLi);
				}
			}
		}
		
		objContainer.appendChild(oUl);
	}
 }
 
  
 
 function productGamesHTML(_divId,_getGamesTag,games,_currentObj)
 {
	
	var objContainer = document.getElementById('gContainer');
	
	var oDiv = document.createElement("div");
	oDiv.className = "homeGameListBox";
	oDiv.style.display = "block";
	oDiv.id = _divId;
	
	var oUl = document.createElement("ul");
   
	var oFrag = document.createDocumentFragment();
	var notHotFrag = document.createDocumentFragment();
	
	
	var m_games = games.split(',');
	if(m_games)
	{
		for(i=0; i<m_games.length; i++)
		{
			var oLi = document.createElement("li");
			var oA = document.createElement("a");
			var oText = document.createTextNode("| ");
			
			
			var notHotLi = document.createElement("li");
			var notHotA = document.createElement("a");
			
			
			
			if (_getGamesTag == "hotG") {
				
				if(m_games[i] !="")
				{
					oLi.appendChild(oText);
					oLi.className = "orange";
					oA.title = deletedSpacechar(m_games[i]);
					oA.innerHTML = deletedSpacechar(m_games[i]);
					oA.target = "_blank";
					oA.href = "http://trading.5173.com/" + deletedSpacechar(m_games[i]) + ".shtml";
					
					oLi.appendChild(oA);
					oFrag.appendChild(oLi);
					
					oLi.appendChild(oA);
					oFrag.appendChild(oLi);
				}
			}
			else {
				
				var tempName = m_games[i].split('#');
				if (tempName.length > 1) {
					
					if(tempName[1] !="")
					{
						oLi.appendChild(oText);
						oLi.className = "orange";
						oA.title = deletedSpacechar(tempName[1]);
						oA.innerHTML = deletedSpacechar(tempName[1]);
						oA.target = "_blank";
						oA.href = "http://trading.5173.com/" + deletedSpacechar(tempName[1]) + ".shtml";
						
						oLi.appendChild(oA);
						oFrag.appendChild(oLi);
					}
				}
				else {
					
					if(m_games[i] !="")
					{
						notHotLi.appendChild(oText);
						notHotLi.className = "";
						notHotA.title = deletedSpacechar(m_games[i]);
						notHotA.innerHTML  = deletedSpacechar(m_games[i]);
						notHotA.target = "_blank";
						notHotA.href = "http://trading.5173.com/" + deletedSpacechar(m_games[i]) + ".shtml";
						
						notHotLi.appendChild(notHotA);
						notHotFrag.appendChild(notHotLi);
					}
				}
			}
		}
	}
	oUl.appendChild(oFrag);
	
	
	oUl.appendChild(notHotFrag);
	
	oDiv.appendChild(oUl);
	objContainer.appendChild(oDiv);
}



 function productCmpGamesHtml(_objCurrent,_currentText,_games)
 {
 	var objContainer = document.getElementById('companyGContainer');
	
	
	objContainer.innerHTML = "";
	
	var oDiv = document.createElement("div");
	oDiv.className = "homeGameListBox";
	oDiv.style.display="block";
	
	var oUl = document.createElement("oli");
	var oFrag = document.createDocumentFragment();
	
	var m_games=_games.split(',');
	if(m_games)
	{
		for(i=0; i<m_games.length; i++)
		{
			var oLi = document.createElement("li");
			var oA = document.createElement("a");
			var oText = document.createTextNode("| ");
	
			
			var gameName = deletedSpacechar(m_games[i]);
			if(gameName !="")
			{
			    oLi.appendChild(oText);
				oA.title = gameName;
				oA.target = "_blank";
				oA.innerHTML = gameName;
				oA.href = "http://trading.5173.com/" + gameName + ".shtml";
				
				oLi.appendChild(oA);
				oFrag.appendChild(oLi);
			}
		}
		
		oUl.appendChild(oFrag);
		oDiv.appendChild(oUl);
		objContainer.appendChild(oDiv);
	}
	
 }

 
 function deletedSpacechar(str)
 {
 	return str = str.replace(/(^\s*|\s*$)/g,"")
 }
 
 
 
function getRequestInstance()
{
	var request;
	
	if(window.XMLHttpRequest) { 
		request = new XMLHttpRequest();
		if (request.overrideMimeType) {
			request.overrideMimeType("text/xml");
		}
	}
	else if (window.ActiveXObject) { 
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!request) { 
		window.alert("不能创建XMLHttpRequest 对象实例.");
		return false;
	}
	
	return request;
}


