
function OnButtonOver(button, switchImage) {
	if (switchImage != false)
		button.style.backgroundImage = 'url("images/button-up-' + button.id + '.png")';
	button.style.cursor = 'pointer';
}

function OnButtonLeave(button, switchImage) {
	if (switchImage != false)
		button.style.backgroundImage = 'url("images/button-n-' + button.id + '.png")';
	button.style.cursor = '';
}

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all ? true : false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var mouseX = 0
var mouseY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		mouseX = event.clientX + document.body.scrollLeft
		mouseY = event.clientY + document.body.scrollTop
	} else {  // grab the x-y pos.s if browser is NS
		mouseX = e.pageX
		mouseY = e.pageY
	}

	// catch possible negative values in NS4
	if (mouseX < 0) mouseX = 0;
	if (mouseY < 0) mouseY = 0;

	if (tooltip.style.visibility != 'hidden') {
		tooltip.style.left = mouseX;
		tooltip.style.top = mouseY + 24;
	}

	return true;
}

var gameTitles = [];
gameTitles["labyrinthGame"] = "Labyrinth";
gameTitles["puzzlesGame"] = "Puzzles";
gameTitles["roachesGame"] = "Roach Attack";
gameTitles["clickGame"] = "Click And Destroy";
gameTitles["gallowsGame"] = "Gallows";

// Language-specific texts
// English

var labyrinthGameDescription = "Give yourself a great break with FusionGames' Labyrinth game. \
The rules are simple: navigate the figure with keyboard arrows or the mouse. The aim is to get \
to the labyrinth's exit in the down right corner. You have two options: to play the game for a \
given time (e.g. Marathon) or play it as long as you wish (&quot;Labyrinth&quot;). Once finished \
you can go to the next level - there are 50 of them.<p />If you are playing Marathon: if you \
finish e level before time is up the remaining time is added to the time for the next level.";

var puzzlesGameDescription = "Puzzles is a free online game for all puzzle-lovers. It allows \
adjustable level difficulty, rotation of puzzle pieces, ghost image of the picture, shadows for \
the pieces and more. A timer and reshuffle buttons are also available.";

var roachesGameDescription = "Get in the role of a cockroach exterminator in this fun and \
addictive game. Use your ammunitions wisely to deliver the world from the cockroach invaders and \
their evil mastermind - the hideous Shash'kun.";

var clickGameDescription = "Click and destroy is a simple yet very fun game, which trains \
associative memory and logic. The game does not require reflexes or speed. It offers 15 levels \
of increasing difficulty and many hours of entertainment.";

var gallowsGameDescription = "Counltess hours of fun are guaranteed with this remake of \
the popular gallows game. English and dutch words are supported as well as adjustable difficulty.";

var gameDescriptions = [];
gameDescriptions["labyrinthGame"] = labyrinthGameDescription;
gameDescriptions["puzzlesGame"] = puzzlesGameDescription;
gameDescriptions["roachesGame"] = roachesGameDescription;
gameDescriptions["clickGame"] = clickGameDescription;
gameDescriptions["gallowsGame"] = gallowsGameDescription;


function OnGameOver(game) {
	game.style.backgroundColor = '#999933';
	game.style.borderColor = '#cccc66';

	tooltipTitle.innerHTML = gameTitles[game.id];
	tooltipContent.innerHTML = gameDescriptions[game.id];
	tooltip.style.left = mouseX;
	tooltip.style.top = mouseY + 24;
	tooltip.style.visibility = '';

	on = game;
}

var toClose = [];
var on;

function OnGameLeave(game) {
	toClose.push(game);
	on = null;
	setTimeout("closeAll()", 100);
}

function closeAll() {
	for (var i = 0; i < toClose.length; i++) {
		if (toClose[i] != on) {
			toClose[i].style.backgroundColor = '';
			toClose[i].style.borderColor = '';
		}
	}
	
	if (on == null)
		tooltip.style.visibility = 'hidden';
		
	toClose = [];
	if (on != null)
		toClose.push(on);
}

function reload() {
	location.reload(true);
}

function followLink(url) {
	window.location.href = url;
}

function closing() {
	// If a game is in progress give the user a chance to save it
	var puzzleMania = document.getElementById("puzzleMania");
	puzzleMania.Content.Game.Closing();
}

