var current = 1;
var games=[];
var downloadsValues=[];
var currentDownloadsValue=[];
var currentDownloadsCatagory="newest0";
var mostValues=[];
var currentMost=-1;
function changeNewGamesInner(){
	if(xml.readyState == 4){
		if(xml.status == 200){
			games[current] = xml.responseText; 
			document.getElementById("newgamesReal").innerHTML = games[current];
		}
	}
}
function changeNewGames(where){
	if(games[current] === undefined){
		games[current] = document.getElementById("newgamesReal").innerHTML;
	}
	if(where == "right"){
		current--;
		if(current <= 0){
			current = 3;
		}
	}else{
		current++;
		if(current > 3){
			current = 1;
		}
	}
	if(games[current] !== undefined){
		document.getElementById("newgamesReal").innerHTML = games[current];
	}else{
		xmlRequest("post","http://www.vins.co.il/index.php?action=ajax","place=idx&requested=newgames&move="+where+"&current="+current,changeNewGamesInner);
	}
}
function changeRequstedGamesInner(){
	if(xml.readyState == 4){
		if(xml.status == 200){
			document.getElementById("hotgames").innerHTML = xml.responseText;
			mostValues[currentMost] = xml.responseText;
		}
	}
}
function changeRequestedGames(where , place){
	if(place != undefined){
		currentMost = parseInt(place);
	}
	//if(mostValues[currentMost] === undefined){
	//	mostValues[currentMost] = document.getElementById("hotgames").innerHTML;
	//}
	if(where == "right"){
		currentMost--;
		if(currentMost == 0){
			currentMost = 7;
		}
	}else{
		currentMost++;
		if(currentMost > 7){
			currentMost = 1;
		}
	}
	if(mostValues[currentMost] !== undefined){
		document.getElementById("hotgames").innerHTML = mostValues[currentMost];
	}else{
		xmlRequest("post","http://www.vins.co.il/index.php?action=ajax","place=idx&requested=requestedGames&move="+where+"&current="+currentMost,changeRequstedGamesInner);
	}
}
function changeDownloadsCatagory(catagory){
	document.getElementById("catagoryDownloads_"+currentDownloadsCatagory).className = "backgroundsbuttonoff";
	document.getElementById("catagoryDownloads_"+catagory).className = "backgroundsbuttonon2";
	document.getElementById("blockDownloads_"+currentDownloadsCatagory).className = "hidden";
	document.getElementById("blockDownloads_"+catagory).className = "shown";
	currentDownloadsCatagory = catagory;
}
function changeDownloadsInner(){
	if(xml.readyState == 4){
		if(xml.status == 200){
			downloadsValues[currentDownloadsCatagory][currentDownloadsValue[currentDownloadsCatagory]] = xml.responseText;
			document.getElementById("blockDownloads_"+currentDownloadsCatagory).innerHTML = xml.responseText;
		}
	} 
}
function getDownloads(direction){
	if(!currentDownloadsValue[currentDownloadsCatagory]){
		currentDownloadsValue[currentDownloadsCatagory] = 1;
	}
	if(!downloadsValues[currentDownloadsCatagory]){
		downloadsValues[currentDownloadsCatagory] = [];
		downloadsValues[currentDownloadsCatagory][1] = document.getElementById("blockDownloads_"+currentDownloadsCatagory).innerHTML;
	}
	if(direction == "right"){
		currentDownloadsValue[currentDownloadsCatagory]--;
		if(currentDownloadsValue[currentDownloadsCatagory] === 0){
			currentDownloadsValue[currentDownloadsCatagory] = 3;
		}
	}else{
		currentDownloadsValue[currentDownloadsCatagory]++;
		if(currentDownloadsValue[currentDownloadsCatagory] == 4){
			currentDownloadsValue[currentDownloadsCatagory] = 1;
		}
	}
	if(downloadsValues[currentDownloadsCatagory][currentDownloadsValue[currentDownloadsCatagory]] !== undefined){
		document.getElementById("blockDownloads_"+currentDownloadsCatagory).innerHTML = downloadsValues[currentDownloadsCatagory][currentDownloadsValue[currentDownloadsCatagory]];
	}else{
		xmlRequest("post","http://www.vins.co.il/index.php?action=ajax","place=idx&requested=downloads&currentBlock="+currentDownloadsCatagory+"&move="+direction+"&current="+currentDownloadsValue[currentDownloadsCatagory],changeDownloadsInner);
	}
}
