function showgame(){
	document.getElementById("gameloader").style.display="none";
	document.getElementById("flashgame").style.visibility="visible";
	document.getElementById("flashgame").style.display="block";
}
setTimeout("showgame()", 10000);

function Zoom(d) {
	obj = elm("flash_game_object");
	embed = elm("flash_game_embed");
	
	if (obj == null || embed == null)
	{
		alert("לא ניתן לבצע זום במשחק זה");	
		return;
	}
		
	var width = parseInt(obj.width);
	
	if (d == 1 && width < 890)
	{
		width += 70;
		if (width > 620)
		{
			elm("large_block_1").setAttribute("class", "");
			elm("large_block_2").setAttribute("class", "right");
			elm("large_block_3").setAttribute("class", "left_block");
			elm("large_block_4").setAttribute("class", "game_left");
			elm("large_block_5").setAttribute("class", "hidden");
			if (elm("large_block_6") != null)
				elm("large_block_6").setAttribute("class", "hidden");
			if (elm("large_block_7") != null)
				elm("large_block_7").setAttribute("class", "hidden");
		}
	}
	else if (d == 0 && width > 500)
	{
		width -= 70;
		if (width < 620)
		{
			elm("large_block_1").setAttribute("class", "game_left");
			elm("large_block_2").setAttribute("class", "");
			elm("large_block_3").setAttribute("class", "hidden");
			elm("large_block_4").setAttribute("class", "");
			elm("large_block_5").setAttribute("class", "block ad");
			if (elm("large_block_6") != null)
				elm("large_block_6").setAttribute("class", "block blue");
			if (elm("large_block_7") != null)
				elm("large_block_7").setAttribute("class", "block ad");
		}
	}
	var ratio = parseInt(obj.height) / parseInt(obj.width);
	var height = width * ratio;
	obj.width = width;
	obj.height = height;
	embed.width = width;
	embed.height = height;
}
function voteToInner()
{
	if ((xml.readyState == 4) && (xml.status == 200)) {
		var code =  xml.responseText;
		if (code == "NOTLOGGED")
			alert("רק משתמשים רשומים יכולים להגיב");
		else if (code == "NOTACTIVATED")
			alert("אנא אשר תחילה את חשבונך");
		else if(code == "BANNED")
			alert("הורחקת מהאתר צור קשר עם הנהלת האתר על מנת לקבל פרטים נוספים");
		else if(code == "NOGAMEID")
			alert("ארעה שגיאה, אם שגיאה זו חוזרת על עצמה אנא צור קשר עם הנהלת האתר");
		else if(code == "NOGAME")
			alert("המשחק שהינך מדרג אינו קיים במערכת");
		else if(code == "VOTED")
			alert("דירגת משחק זה בעבר");
		else
		{
			elm("rateDiv").innerHTML = code;
			var width = elm("bar").getAttribute("newwidth");
			var old_width = parseInt(elm("bar").style.width);
			if (width > old_width)
				$("#bar").animate({"width": "+="+(width-old_width)+"%"}, "slow");
			else
				$("#bar").animate({"width": "-="+(old_width-width)+"%"}, "slow");
		}
	}
}
function voteTo(game,vote){
	xmlRequest("post","http://www.vins.co.il/index.php?action=ajax","place=game&requested=vote&game="+game+"&vote="+vote,voteToInner);
}
var messageCounter = 0;
function copyCode(message) {
	var text2copy = document.getElementById("textCode").value;
	if(window.clipboardData){
		window.clipboardData.setData("Text",text2copy);
		alert(message);
	}else{
		var flashcopier = 'flashcopier';
    	if(!document.getElementById(flashcopier)){
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}
    	document.getElementById(flashcopier).innerHTML = '';
    	var divinfo = '<embed src="http://www.vins.co.il/style/_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    	document.getElementById(flashcopier).innerHTML = divinfo;
    	if(messageCounter == 0){
    		alert(message);
    		messageCounter = 1;
    	}else{
    		messageCounter = 0;
    	}
  	}
}
function changeGameInner(){
	if(xml.readyState == 4){
		if(xml.status == 200){
			if(xml.responseText != ""){
				var values = xml.responseText.split(";;;");
				document.title = values[0];
				document.getElementById("mainBigTitle").innerHTML = values[0];
				document.getElementById("gameSummery").innerHTML = values[1];
				document.getElementById("rateDiv").innerHTML = values[2];
				document.getElementById("gameCodes").innerHTML = values[3];
				document.getElementById("gameObjectDiv").innerHTML = values[4];
				times=0;
			}
		}
	}
}
function changeGame(game,where){
	xmlRequest("post","http://www.vins.co.il/index.php?action=ajax","place=game&requested=game&game="+game+"&where="+where,changeGameInner);
}

function refreshTopListAction(){
	if(xml.readyState == 4){
		if(xml.status == 200){
			if(xml.responseText == "ERROR"){
				alert("שגיאה");
			}else{
				document.getElementById("toplist").innerHTML =  xml.responseText;
			}
		}
	}
}
function refreshTopList(game,type){
	xmlRequest("post","http://www.vins.co.il/index.php?action=ajax","place=game&requested=toplist&game="+game+"&type="+type,refreshTopListAction);
}

var lastCatagory = "sameGames";
var lastFullList=1;
var catagoriesValues = [];
var currentInCatagories = [];
function changeCatagory(catagory,number){
	if(catagory != lastCatagory){
		document.getElementById("catagory_"+lastCatagory).className = "clipsbuttonoff";
		document.getElementById("catagory_"+catagory).className = "clipsbuttonon";
		document.getElementById("div_"+lastCatagory).className = "hidden";
		document.getElementById("div_"+catagory).className = "shown";
		if(lastFullList != number){
			document.getElementById("fullList"+lastFullList).className = "hidden";
			document.getElementById("fullList"+number).className = "fulllink2";
			lastFullList = number;
		}
		lastCatagory = catagory;
	}
}
function makeMoveButtomInner(){
	if(xml.readyState == 4){
		if(xml.status == 200){
			catagoriesValues[lastCatagory][currentInCatagories[lastCatagory]] = xml.responseText;
			document.getElementById("div_"+lastCatagory).innerHTML = xml.responseText;
		}
	}
}
function makeMoveButtom(where,catagory,keywords,id){
	if(currentInCatagories[lastCatagory] === undefined || currentInCatagories[lastCatagory] === 0){
		currentInCatagories[lastCatagory] = 1;
		catagoriesValues[lastCatagory] = [];
		catagoriesValues[lastCatagory][0] = document.getElementById("div_"+lastCatagory).innerHTML;
	}
	if(where == "right"){
		currentInCatagories[lastCatagory]--;
		if(currentInCatagories[lastCatagory] === 0){
			currentInCatagories[lastCatagory] = 3;
		}
	}else{
		currentInCatagories[lastCatagory]++;
		if(currentInCatagories[lastCatagory] == 4){
			currentInCatagories[lastCatagory] = 1;
		}
	}
	if(catagoriesValues[lastCatagory][currentInCatagories[lastCatagory]] !== undefined && catagoriesValues[lastCatagory][currentInCatagories[lastCatagory]] !== 0){
		document.getElementById("div_"+lastCatagory).innerHTML = catagoriesValues[lastCatagory][currentInCatagories[lastCatagory]];
	}else{
		xmlRequest("post","http://www.vins.co.il/index.php?action=ajax","place=game&requested=buttom&id="+id+"&keywords="+keywords+"&catagory="+catagory+"&type="+lastCatagory+"&current="+currentInCatagories[lastCatagory],makeMoveButtomInner);
	}
}

function OpenScorePlug (){
	window.open ("http://www.scoreplug.com");
}


function ChangeComments(game,type)
{
	type = (typeof(type) != 'undefined') ? type : "vins";
	xmlRequest("post","http://www.vins.co.il/index.php?action=ajax","place=game&requested=comments_block&game="+game+"&type="+type,ChangeCommentsAction);
}

function ChangeCommentsAction() {
	if ((xml.readyState == 4) && (xml.status == 200)) {
		elm("comments_block").innerHTML = xml.responseText;
		if (elm("facebook_comments") != null)
			FB.XFBML.parse(elm('facebook_comments'));
	}
}
var ReportedComment = null;
function Report(comment)
{
	ReportedComment = comment;
	xmlRequest("post","http://www.vins.co.il/index.php?action=ajax","place=game&requested=report&comment="+comment,ReportAction);
}

function ReportAction() {
	if ((xml.readyState == 4) && (xml.status == 200)) {
		var code = xml.responseText;
		if (code == "ERROR")
			alert("ארעה שגיאה, אם שגיאה זו חוזרת אנא דווח להנהלת האתר");
		else if (code == "REPORTED")
		{
			alert("תודה, אך תגובה זאת דווחה בעבר.");
			elm("report_"+ReportedComment).innerHTML = "דווח";
		}
		else
		{
			alert("תודה, הדיווח נשלח.");
			elm("report_"+ReportedComment).innerHTML = "דווח";
		}
	}
}
