$(document).ready(function() {
	// Start updating pl credits
	if (global.bIsPlLogged) {
		$("#spanShowCredits").html("Loading...");
		GetPlCredits(true, false, OnGetCredits);
	}
});

var plCreditsTimer = -1;

function OnGetCredits(credits) {
	if (credits != "") {
		// Successfull call, continue getting credits
		if (plCreditsTimer == -1) {
			// First call, start timer
			plCreditsTimer = self.setInterval(function() {
				GetPlCredits(true, false, OnGetCredits);
			}, global.tsMoney);
		}
		// Update money
		$("#spanShowCredits").html(credits);
	} else {
		// Stop timer
		if (plCreditsTimer != -1) {
			window.clearInterval(plCreditsTimer);
		}
		$("#spanShowCredits").html("N/A");
	}
}

function LoadJackpotMovie(idJp, idPackage, color, currency) {
	id = GetJackpotMovieName(idJp, idPackage);

	var url = global.siteGroupURL + 'WebPageJP?' +
	    'color=' + color +	    
	    '&currency=' + currency +
	    '&idCustomer=' + global.idCustomer +
	    '&strNameSpace=' + 'http://tempuri.org/' +
	    '&idPackage=' + idPackage +
	    '&idJackpot=' + idJp +
	    '&urlPath=' + global.siteURL + '/Services/Misc.asmx';
	    
	AC_FL_RunContent(
		'codebase', GetHttpOrHttps() + '://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
		'width', '100',
		'height', '20',
		'src', url,
		'quality', 'high',
		'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
		'align', 'middle',
		'play', 'true',
		'loop', 'true',
		'scale', 'showall',
		'wmode', 'Transparent',
		'devicefont', 'false',
		'id', id,
		'bgcolor', '#ffffff',
		'name', id,
		'menu', 'true',
		'allowFullScreen', 'false',
		'allowScriptAccess', 'allowAll',
		'movie', url,
		'salign', '');

	// Save object
	window[id] = document.getElementById(id);
}

function GetJackpotMovieName(idJp, idPackage) {
	return "jackpot_" + idJp + "_" + idPackage;
}

function over_menu(image) {
	image.src = image.src.substr(0, image.src.length - 6) + "Ov.gif";
	return true;
}

function out_menu(image) {
	image.src = image.src.substr(0, image.src.length - 6) + "Ot.gif";
	return true;
}

function addToFavorites() {
	AddToFav();
}

function UpdateLast5Played() {
	if (global.bIsPlLogged) {
		var cookies = document.cookie;

		if (cookies.indexOf(global.Latest5Cookie) != -1) {

			var startpos = cookies.indexOf(global.Latest5Cookie) + global.Latest5Cookie.length + 1;
			var endpos = cookies.indexOf(";", startpos) - 1;

			if (endpos == -2) endpos = cookies.length;

			var games = unescape(cookies.substring(startpos, endpos)).split(",");

			$("#recentGames").html("");

			$.each(eval(games), function(i, el) {
				var html = $("#" + el).parent().html();
				if (html != null) {
					$("#recentGames").append("<tr><td>" + html + "</td></tr>");
				}
			});
		}
	}
}