var current = 1;
var games=[];
var currentMoviesCatagory="P_newest0";
var moviesValues=[];
var currentMovieValue=[];
var downloadsValues=[];
var currentDownloadsValue=[];
var currentFunnyCatagory="newest0";
var funnyValues=[];
var currentFunnyValue=[];
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 changeMoviesCatagory(catagory){
	document.getElementById("catagoryMovies_"+currentMoviesCatagory).className = "clipsbuttonoff";
	document.getElementById("catagoryMovies_"+catagory).className = "backgroundsbuttonon2";
	document.getElementById("blockMovies_"+currentMoviesCatagory).className = "hidden";
	document.getElementById("blockMovies_"+catagory).className = "shown";
	currentMoviesCatagory = catagory;
}
function changeMoviesInner(){
	if(xml.readyState == 4){
		if(xml.status == 200){
			moviesValues[currentMoviesCatagory][currentMovieValue[currentMoviesCatagory]] = xml.responseText;
			document.getElementById("blockMovies_"+currentMoviesCatagory).innerHTML = xml.responseText;
		}
	} 
}
function getMovies(direction){
	if(!currentMovieValue[currentMoviesCatagory]){
		currentMovieValue[currentMoviesCatagory] = 1;
	}
	if(!moviesValues[currentMoviesCatagory]){
		moviesValues[currentMoviesCatagory] = [];
		moviesValues[currentMoviesCatagory][1] = document.getElementById("blockMovies_"+currentMoviesCatagory).innerHTML;
	}
	if(direction == "right"){
		currentMovieValue[currentMoviesCatagory]--;
		if(currentMovieValue[currentMoviesCatagory] === 0){
			currentMovieValue[currentMoviesCatagory] = 3;
		}
	}else{
		currentMovieValue[currentMoviesCatagory]++;
		if(currentMovieValue[currentMoviesCatagory] == 4){
			currentMovieValue[currentMoviesCatagory] = 1;
		}
	}
	if(moviesValues[currentMoviesCatagory][currentMovieValue[currentMoviesCatagory]] !== undefined){
		document.getElementById("blockMovies_"+currentMoviesCatagory).innerHTML = moviesValues[currentMoviesCatagory][currentMovieValue[currentMoviesCatagory]];
	}else{
		if (currentMoviesCatagory == "P_newest0" || currentMoviesCatagory == "P_best0") {
			xmlRequest("post","http://www.vins.co.il/index.php?action=ajax","place=idx&requested=pictures&currentBlock="+currentMoviesCatagory+"&move="+direction+"&current="+currentMovieValue[currentMoviesCatagory],changeMoviesInner);
		}else{
			xmlRequest("post","http://www.vins.co.il/index.php?action=ajax","place=idx&requested=movies&currentBlock="+currentMoviesCatagory+"&move="+direction+"&current="+currentMovieValue[currentMoviesCatagory],changeMoviesInner);
		}
	}
}
function changePicturesCatagory(catagory){
	document.getElementById("catagoryPictures_"+currentFunnyCatagory).className = "backgroundsbuttonoff";
	document.getElementById("catagoryPictures_"+catagory).className = "backgroundsbuttonon2";
	document.getElementById("blockPictures_"+currentFunnyCatagory).className = "hidden";
	document.getElementById("blockPictures_"+catagory).className = "shown";
	currentFunnyCatagory = catagory;
}
function changePicturesInner(){
	if(xml.readyState == 4){
		if(xml.status == 200){
			funnyValues[currentFunnyCatagory][currentFunnyValue[currentFunnyCatagory]] = xml.responseText;
			document.getElementById("blockPictures_"+currentFunnyCatagory).innerHTML = xml.responseText;
		}
	} 
}
function getPictures(direction){
	if(!currentFunnyValue[currentFunnyCatagory]){
		currentFunnyValue[currentFunnyCatagory] = 1;
	}
	if(!funnyValues[currentFunnyCatagory]){
		funnyValues[currentFunnyCatagory] = [];
		funnyValues[currentFunnyCatagory][1] = document.getElementById("blockPictures_"+currentFunnyCatagory).innerHTML;
	}
	if(direction == "right"){
		currentFunnyValue[currentFunnyCatagory]--;
		if(currentFunnyValue[currentFunnyCatagory] === 0){
			currentFunnyValue[currentFunnyCatagory] = 3;
		}
	}else{
		currentFunnyValue[currentFunnyCatagory]++;
		if(currentFunnyValue[currentFunnyCatagory] == 4){
			currentFunnyValue[currentFunnyCatagory] = 1;
		}
	}
	if(funnyValues[currentFunnyCatagory][currentFunnyValue[currentFunnyCatagory]] !== undefined){
		document.getElementById("blockPictures_"+currentFunnyCatagory).innerHTML = funnyValues[currentFunnyCatagory][currentFunnyValue[currentFunnyCatagory]];
	}else{
		xmlRequest("post","http://www.vins.co.il/index.php?action=ajax","place=idx&requested=pictures&currentBlock="+currentFunnyCatagory+"&move="+direction+"&current="+currentFunnyValue[currentFunnyCatagory],changePicturesInner);
	}
}
function changeDownloadsCatagory(catagory){
	document.getElementById("catagoryDownloads_"+currentDownloadsCatagory).className = "clipsbuttonoff";
	document.getElementById("catagoryDownloads_"+catagory).className = "clipsbuttonon";
	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);
	}
}