var count=0;
var timeout = 500;
var increments = new Array();
var defaultLink = "http://www.jackpotmania.com/";

/* Methods of jp object */
jp.prototype.setParameters = setParameters;
function setParameters(idx, size){
	this.size = size;
	//size 's' - small, 'l' - large
	if (size == "l") {
		this.w = "140";
		this.h = "115";
	} else 	{
		this.w = "100";
		this.h = "82";
	}
	this.currency = (this.currency == "US$" || this.currency == "$")? "$" : "£";	
}
jp.prototype.getHtml = getHtml 
function getHtml(idx, alink){
	if (document.forms[("formform" +idx)]) return '';	
	var theLink = ((alink == null) || (alink == ''))? defaultLink : alink;
	var html = '<form name="formform' +idx +'">';
	html += '<table cellpadding="0" cellspacing="0" border="0"><tr><td align="center">';
	
	html += '<input type="text" name="progressive" size="7" value="" class="jp">';
	html += '</td></tr></table>';
	html += '</form>';
	return html;
}
jp.prototype.rollJP = rollJP;
function rollJP(jackpot){
	var i = jackpot;
	var t =  String(Jackpots[i].previous_value + count*increments[i]);
	var obj = document.forms[("formform" +i)].elements['progressive'];	
	if (parseFloat(t) >0) {
		var dotPos = t.indexOf('.');
		if (dotPos > 0)	{
				t +='00';
				t = t.substring(0,dotPos +=3);
			} else t = t + '.00';		
		if (obj) obj.value = Jackpots[i].currency + insertComma(t);
	} else {
		if (obj) obj.value = '    - - - - -';
	}
	count++;
	window.setTimeout("rollJP("+i+")",timeout);	
}

function insertComma(data){
	var dotPos = data.indexOf('.');
	var tmp ="";

	for (var i = dotPos; i>=0; i=i-3)
	{		
		tmp = (i-3>0)? ',' + data.substring(i-3,i) + tmp : data.substring(i-3,i) + tmp;		
	}
	tmp += data.substring(dotPos,data.length);
	return tmp;
}
/* end jp methods */


function DisplayJackpot(game, size, alink){
	// all_us -> all games with US$, all_uk -> all games with British pound
	if (game == 'all_us') jackpot = new Array(0,1,2,3,4,5,6,7);
	else if (game == 'all_uk') jackpot = new Array(8,9,10,11,12,13,14,15);
	else jackpot = new Array(game.toString()); 
	
	for (var i=0; i < jackpot.length; i++) { 
		var idx = jackpot[i];
		Jackpots[idx].setParameters(idx, size);		
		document.write( Jackpots[idx].getHtml(idx, alink) );		
		var steps = Jackpots[idx].interval/(timeout/1000);
		increments[idx] = (Jackpots[idx].current_value - Jackpots[idx].previous_value)/steps;
		Jackpots[idx].rollJP(idx);		
	}
}	





