	var standard_rate_index = 0;
	var voted = 0;
	function setRateText(id) {
		if (voted == 0) {
			var ratingText = Array();
			ratingText[0]='';
			ratingText[1]='Terrible';
			ratingText[2]='Do not like it';
			ratingText[3]='It is OK';
			ratingText[4]='Great';
			ratingText[5]='Excellent';
			var ratingTextDiv = document.getElementById("ratingText");
			ratingTextDiv.innerHTML = ratingText[id];
		}
	}

	function setStickRateText(id, gameid) {
		if (voted == 0) {
			standard_rate_index = id;
			var percentage = (id*20);
			document.getElementById("ratingstarsli").style.width=percentage+"%";
			setRateText(id);

			var outURL = "http://www.gamesxl.com/includes/vote.php?do=vote&rating="+(id*2)+"&gameid="+gameid;
			window.hiddenframe.location.href = outURL;
			for (var i = 1; i<=5; i++) {
				document.getElementById("ratingstar"+i).className = "no-stars";
			}
			voted = 1;
		}
	}

	function addEvents(gameid, multiplayer) {
		var loadrules = true;
		if (multiplayer == undefined) {
			loadrules = false;
		}
		window.addEvent('domready', function(){
			if ($('submitSendToFriend')) {
				$('submitSendToFriend').addEvent('click', function(e) {
					e = new Event(e).stop();
					var popupWidth=325;
					var popupHeight=200;
					var popupTop = e.page.y-popupHeight+110;
					var popupLeft = e.page.x-popupWidth-100;
					var url = 'tellafriend.php?gameid='+gameid;
					new Ajax(url, {
						method: 'get',
						update: $('sendToFriend'),
						evalScripts:true,
						onComplete:function(){
							$('sendToFriend').setStyles({
								width: popupWidth,
								height: popupHeight,
								top:popupTop,
								left:popupLeft
							});
						}
					}).request();
				});
			}
			
			if (loadrules) {
				$('rules').addEvent('click', function(e) {
					e = new Event(e).stop();
					var popupWidth=900;
					var popupHeight=180;
					//var popupTop = e.page.y-popupHeight-200;
					var popupTop = 25;
					//var popupLeft = e.page.x-(popupWidth/2);
					var popupLeft = (getWidth()/2)-(popupWidth/2);
					var url = 'rules.php';
					new Ajax(url, {
						method: 'get',
						update: $('rulesPopup'),
						evalScripts:true,
						onComplete:function(){					
							$('rulesPopup').setStyles({
								width: popupWidth,
								height: popupHeight,
								top:popupTop,
								left:popupLeft
							});
						}
					}).request();
				});
			}
		});
	}
	
	var open_game = 0;
	var open_image = 0;
	var open_pl = 0;
	var default_game_width = 0;
	var default_game_height = 0;
	function showGame() {
		if (open_game == 0) {
			if (document.getElementById("customImage") != undefined) {
				document.getElementById("customImage").style.visibility = "hidden";
				document.getElementById("customImage").style.position = "absolute";
				document.getElementById("customImage").style.top = "0px";
				document.getElementById("customImage").style.left = "0px";
				document.getElementById("customImage").style.width = "0px";
				document.getElementById("customImage").style.height = "0px";
			}
			if (document.getElementById("adContainerBig") != undefined) {
				document.getElementById("adContainerBig").style.visibility = "hidden";
				document.getElementById("adContainerBig").style.position = "absolute";
				document.getElementById("adContainerBig").style.top = "0px";
				document.getElementById("adContainerBig").style.left = "0px";
				document.getElementById("adContainerBig").style.width = "0px";
				document.getElementById("adContainerBig").style.height = "0px";
			}
			if (document.getElementById("gameWrapper") != undefined) {
				if (default_game_height < 450) {
					document.getElementById("gameWrapper").style.width = default_game_width+"px";
				}
				if (default_game_height < 400) {
					document.getElementById("gameWrapper").style.height = (default_game_height)+"px";
				}
			}
			if (document.getElementById("gameSource") != undefined) {
				document.getElementById("gameSource").style.width = "100%";
				document.getElementById("gameSource").style.height = "100%";
				document.getElementById("gameSource").style.border = "1px solid #372519";
			}
			if (document.getElementById("gamePlayerContainer") != undefined) {
				document.getElementById("gamePlayerContainer").style.visibility = "visible";
				document.getElementById("gamePlayerContainer").style.width = "100%";
				document.getElementById("gamePlayerContainer").style.height = "100%";
			}
			open_game = 1;
			open_image = 1;
		}
	}	

	function showImage() {
		if (open_image == 0) {
			if (document.getElementById("customImage") != undefined) {
				document.getElementById("customImage").style.visibility = "visible";
				document.getElementById("customImage").style.width = "100%";
				document.getElementById("customImage").style.height = "100%";
			}
			open_image = 1;
		}
	}
	
	function showPL() {
		if (open_pl == 0) {
			if (document.getElementById("gameSource") != undefined) {
				document.getElementById("gameSource").style.borderStyle = "none";
			}
			if (document.getElementById("gamePlayerContainer") != undefined) {
				document.getElementById("gamePlayerContainer").style.visibility = "visible";
				document.getElementById("gamePlayerContainer").style.width = "100%";
			}
			if (document.getElementById("adContainerBig") != undefined) {
				document.getElementById("adContainerBig").style.visibility = "visible";
				if (default_game_width < 450) {
					document.getElementById("adContainerBig").style.width = "450px";
				} else {
					document.getElementById("adContainerBig").style.width = default_game_width+"px";
				}
				if (default_game_height < 400) {
					document.getElementById("adContainerBig").style.height = "400px";
				} else {
					document.getElementById("adContainerBig").style.height = (default_game_height)+"px";
				}
			}
			if (document.getElementById("gameWrapper") != undefined) {
				document.getElementById("gameWrapper").style.visibility = "visible";
				if (default_game_width < 450) {
					document.getElementById("gameWrapper").style.width = "450px";
				} else {
					document.getElementById("gameWrapper").style.width = default_game_width+"px";
				}
				if (default_game_height < 425) {
					document.getElementById("gameWrapper").style.height = "425px";
				} else {
					document.getElementById("gameWrapper").style.height = (default_game_height)+"px";
				}
			}
			if (document.getElementById("adContainer") != undefined) {
				document.getElementById("adContainer").style.width = "336px";
				document.getElementById("adContainer").style.height = "330px";
			}
			open_pl = 1;
		}
	}
	
	function resizeGame(change_width,change_height) {
		if (default_game_width < 350 || default_game_height < 350) {
			if (document.getElementById("gamePlayerContainer") != undefined) {
				document.getElementById("gamePlayerContainer").style.width = "100%";
				document.getElementById("gamePlayerContainer").style.height = "100%";
			}
			if (document.getElementById("gameWrapper") != undefined) {
				document.getElementById("gameWrapper").style.width = change_width+"px";
				document.getElementById("gameWrapper").style.height = change_height+"px";
			}
		}
	}
	
	function initializePLCounter(amount) {
		if ( document.getElementById('plcounter') != undefined ) {
			document.getElementById('plcounter').innerHTML = amount;
		}
	}
	
	function setPLCounter() {
		if ( document.getElementById('plcounter') != undefined && document.getElementById('plcounter').innerHTML > 0 ) {
			document.getElementById('plcounter').innerHTML = document.getElementById('plcounter').innerHTML-1;
			setTimeout("setPLCounter()", 1000);
		}
	}

	function hideSlider() {
	    if (document.getElementById('gameSliderContainer')) {
			document.getElementById('gameSliderContainer').style.visibility='hidden';
	    }
	}

	function showSlider() {
	    if (document.getElementById('gameSliderContainer')) {
			document.getElementById('gameSliderContainer').style.visibility='visible';
	    }
	}

	function updateSlider() {

	    if ($("gameSliderContainer")) {
			$("gameSliderContainer").empty().replaceWith(
				new Element('div', {
					'id': 'gameSliderContainer',
					'styles': {
						'width': (sliderWidth+'px')
					}
				})
			);
			if ($("gameSliderContainer")) {
				new Element('div', {
					'id': 'gameSlider'
				}).injectInside(
					$("gameSliderContainer")
				);
			}
			if ($("gameSlider")) {
				new Element('div', {
					'id': 'gameSliderButton'
				}).injectInside(
					$("gameSlider")
				);
			}
	    }

		if($('gameSlider')) {
			var sTop = $('top').getStyle('width').toInt();
			var sMainRightFix = $('mainRightFix').getStyle('width').toInt();
			var sBlockTop = $('blockTop').getStyle('width').toInt();
			var sGameSliderContainer = $('gameSliderContainer').getStyle('width').toInt();
			var sGame = $('game').getStyle('width').toInt();
			var sGameContainerW = $('gameWrapper').getStyle('width').toInt();
			var sGameContainerH = $('gameWrapper').getStyle('height').toInt();
			var sBlock = $('block').getStyle('width').toInt();

			var top = new Fx.Style('top','width');
			var mainRightFix = new Fx.Style('mainRightFix','width');
			var blockTop = new Fx.Style('blockTop','width');
			var gameSliderContainer = new Fx.Style('gameSliderContainer','width');
			var game = new Fx.Style('game','width');
			var gameContainerW = new Fx.Style('gameWrapper','width');
			var gameContainerH = new Fx.Style('gameWrapper','height');
			var block = new Fx.Style('block','width');

			var slider = new Slider($('gameSlider'), $('gameSliderButton'), {
				steps:10,
				offset:0,
				onChange: function(pos){
					oriPos = pos;
					pos = pos-5;
					var add = 0;
					add=pos*50;
					var math = (100/sGameContainerW)*(sGameContainerW+add);

					if(oriPos>=5) {
						top.set(sTop+add);
						mainRightFix.set(sMainRightFix+add);
						blockTop.set(sBlockTop+add);
						gameSliderContainer.set(sGameSliderContainer+add);
						game.set(sGame+add);
						block.set(sBlock+add);
					}
					gameContainerW.set(sGameContainerW+add);
					gameContainerH.set(sGameContainerH*(math/100));
				}
			}).set(5);
		}
	}

	var aftText = "";
	var alternativeGameStarted = false;
	var sliderWidth = 820;
	function updateDiv() {

	    if ($("gamePlayerContainer")) {
			$("gamePlayerContainer").empty().replaceWith(
				new Element('div', {
				'styles': {
					'width': '100%',
					'height': '100%',
					'border-width': '0px',
					'visibility': 'visible'
				},
					'id': 'gamePlayerContainer'
				}).setHTML(
					aftText
				)
			);
	    }

	    updateDivStyle();
	}

	function updateDivStyle(pre) {
	    var wrapWidth = default_game_width;
	    var wrapHeight = default_game_height;
	    var playerWidth = '100%';
	    var playerHeight = '100%';
	    var adWidth = 480;
	    var adHeight = 435;

	    if (pre != undefined) {
			wrapWidth = 530;
			wrapHeight = 510;
			playerWidth = wrapWidth;
			playerHeight = (wrapHeight-25);
	    }
	    if ($('gameWrapper')) {
			$('gameWrapper').setStyles({
				visibility: 'visible',
				width: wrapWidth,
				height: wrapHeight
			});
			}
	    if ($("gamePlayerContainer")) {
			if (pre != undefined) {
				$('gamePlayerContainer').setStyles({
					visibility: 'visible',
					border: '1px solid #6D4D26',
					'background-color': '#24160C',
					width: playerWidth,
					height: playerHeight
				});
			} else {
				$('gamePlayerContainer').setStyles({
					visibility: 'visible',
					width: playerWidth,
					height: playerHeight
				});
			}
	    }
	    if ($("adContainer")) {
			$('adContainer').setStyles({
				visibility: 'visible',
				width: adWidth,
				height: adHeight
			});
			$("adContainer").setStyle('margin-top','15px');
	    }

	    if (pre != undefined) {
			setTimeout("showButton()",5000);
			setTimeout("autoShowGame()",15000);
	    }
	}

	var videoStatus = false;
	function PrepareBigAd() {
	    videoStatus = true;
	}

	function ForwardToGame() {
	    updateDiv();
	    updateSlider();
	    showSlider();
		alternativeGameStarted = true;
	}

	function showButton() {
	    if (!videoStatus) {
			if ($("forwardButton")) {
				$("forwardButton").setStyle('visibility','visible');
			}
	    }
	}

	function autoShowGame() {
	    if (!videoStatus && !alternativeGameStarted) {
			ForwardToGame();
	    }
	}