function format2currency(a) {
	a = a.split("").reverse().join("");
	a = a.replace(/([0-9]{3})(?=[0-9]+)/g, "$1,");
	return a.split("").reverse().join("")
}
var JackpotManager = {
	jackpots: new Array(),
	updateInterval: 2000,
	queue: new Array()
};
JackpotManager.add = function (d, b, c) {
	var a = new Ticker(d);
	a.SetCurrencySign(d.sign);
	if (typeof(d.currency) != "undefined") a.currency = d.currency.toLowerCase();
	a.attachToTextBox(b, c);
	a.tick();
	this.jackpots.push(a)
};
JackpotManager.register = function (a) {
	this.queue.push(a)
};
JackpotManager.start = function () {
	this.run()
};
JackpotManager.run = function () {
	var b = new Array();
	for (var a = 0; a < JackpotManager.queue.length; a++) {
		b.push(JackpotManager.queue[a])
	}
	JackpotManager.queue = new Array();
	for (var a = 0; a < b.length; a++) {
		b[a]()
	}
	window.setTimeout(JackpotManager.run, JackpotManager.updateInterval)
};
var scripts = document.getElementsByTagName("script");
var myscript = scripts[scripts.length - 1];
var TickerList = [];
var EmptyFunc = function () {};
var Class = {
	create: function () {
		return (function () {
			if (this.initialize) {
				this.initialize.apply(this, arguments)
			}
		})
	}
};
Function.prototype.bind = function (c) {
	var d = this;
	return (function () {
		d.apply(c, arguments)
	})
};
 
function $1() {
	var f = [];
	for (var d = 0; d < arguments.length; d++) {
		var e = arguments[d];
		if (typeof e == "string") {
			e = document.getElementById(e)
		}
		if (arguments.length == 1) {
			return e
		}
		f[f.length] = e
	}
	return f
}
if (typeof Function.prototype.apply == undefined) {
	Function.prototype.apply = function (object, parameters) {
		var parameterStrings = [];
		if (!object) {
			object = window
		}
		if (!parameters) {
			parameters = []
		}
		for (var i = 0; i < parameters.length; i++) {
			parameterStrings[i] = "parameters[" + i + "]"
		}
		object.__apply__ = this;
		var result = eval("object.__apply__(" + parameterStrings.join(", ") + ")");
		object.__apply__ = null;
		return result
	}
}
var HLComm = Class.create();
HLComm.prototype = {
	initialize: function (url) {
		var frame, container;
		if ("".replace(/^$/, function () {
			return "x"
		}) != "x") {
			var div = document.createElement("div");
			with(div.style) {
				height = width = border = "0px";
				visibility = "hidden";
				position = "absolute"
			}
			document.body.appendChild(div);
			div.innerHTML = '<iframe src=""></iframe>';
			frame = div.firstChild;
			container = div
		} else {
			frame = document.createElement("iframe");
			document.body.appendChild(frame);
			container = frame
		}
		with(container.style) {
			height = width = border = "0px";
			visibility = "hidden";
			position = "absolute"
		}
		for (var i = 0; i < window.frames.length; i++) {
			if (window.frames[i] == frame) {
				frame = window.frames[i];
				break
			}
		}
		this.frame = frame;
		this.url = url
	},
	sendRealRequest: function (e) {
		var f = this.frame;
		var d;
		if (f.contentDocument) {
			d = f.contentDocument
		} else {
			if (f.contentWindow) {
				d = f.contentWindow.document
			} else {
				if (f.document) {
					d = f.document
				}
			}
		}
		if (!d) {
			setTimeout(function () {
				arguments.callee(e)
			},
			100);
			return
		}
		d.open();
		d.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><script type="text/javascript" >var xmlstring = {};<\/script><script type="text/javascript" src="' + this.url + "\"><\/script></head><body onLoad=\"var d='';try{d=xmlstring}catch(e){}window.parent.TickerList[" + e + '].handleResponse(d);"></body></html>');
		d.close()
	}
};
var Ticker = Class.create();
Ticker.prototype = {
	tickingPeriod: 120 * 1000,
	downloadInterval: 119 * 1000,
	updateInterval: 2000,
	startPercent: 99,
	tickStep: 0,
	tickerStartSum: 0,
	tickerEndSum: 0,
	tickerStartTime: 0,
	ticking: true,
	counter: 0,
	errmsg: "-",
	xml: "",
	downloadTime: 0,
	setup: false,
	initialize: function (b) {
		if (!b.info) {
			return
		}
console.info("in initialize: "+b.currency);
		this.currency = (b.currency ? b.currency.toLowerCase() : "usd");
		this.info = b.info;
		if (b.root_url) {
			this.xml = b.root_url
		} else {
			this.xml = "http://tickers.playtech.com/"
		}
		this.xml += "jpdata/datalink/";
		switch (b.info) {
		case 1:
			if (!b.game || (b.local == 1 && !b.casino)) {
				return
			}
			this.countElement = "game";
			if (b.casino) {
				this.casino = b.casino.toLowerCase()
			}
			this.game = b.game.toLowerCase();
			this.xml += (b.local == 1 ? (this.casino + "_") : "");
			this.xml += this.game;
			this.setup = true;
			break;
		case 2:
			if (!b.casino) {
				return
			}
			this.countElement = "casinototal";
			this.casino = b.casino.toLowerCase();
			this.xml += this.casino;
			this.setup = true;
			break;
		case 4:
			this.xml += "casinostotal";
			this.local = (b.local == 1 || b.local == 0 ? b.local : 2);
			this.setup = true;
			break;
		case 5:
			if (!b.group) {
				return
			}
			this.countElement = "game";
			this.group = b.group.toLowerCase();
			this.xml += "group_" + this.group;
			this.setup = true;
			break;
		default:
			return
		}
		this.xml += ".xml.js";
		this.setup = true;
		if (b.type == "count" || b.type == "sum") {
			this.ticking = false;
			this.type = b.type;
			if (this.type == "count") {
				this.sign = "";
				this.signpos = ""
			}
		}
		this.comm = new HLComm(this.xml);
		this.name = window.TickerList.length;
		window.TickerList[window.TickerList.length] = this
	},
	attachToTextBox: function (c, d) {
		this.textboxformatter = (typeof(d) != "undefined") ? d : false;
		this.textbox = $1(c)
console.info("sign:"+this.sign);
	},
	debugTextBox: function (b) {
		this.debug = $1(b)
	},
	SetCurrencySign: function (b) {
		if (this.type != "count") {
			this.sign = b
		}
	},
	SetCurrencyPos: function (b) {
		if (this.type != "count") {
			this.signpos = b
		}
	},
	requestJackpot: function () {
		this.comm.sendRealRequest(this.name)
	},
	handleResponse: function (s) {
		this.errmsg = "-";
		var t = this.tickerEndSum;
		var p = 0;
		var v = 0;
		var i, o;
		var r = (s.endTime - s.startTime) + (s.execInterval * 60) + 180;
		this.downloadInterval = r * 1000;
		this.tickingPeriod = this.downloadInterval + 60000;
		i = this.parseFromString(s.jpxml);
		if (i) {
			if (this.info == 4 && this.local == 2) {
				var n = this.findTargetNodes(i);
				if (n && n.length > 0) {
					t = 0;
					for (var q = 0; q < n.length; q++) {
						var u = n[q];
						var m = 0;
						if (this.type == "sum") {
							m = parseFloat(u.getAttribute("wins"), 10)
						} else {
							if (this.type == "count") {
								m = parseFloat(u.getAttribute("winc"), 10)
							} else {
								if (u.firstChild && u.firstChild.nodeValue) {
									m = parseFloat(u.firstChild.nodeValue, 10)
								}
							}
						}
						if (!isNaN(m)) {
							t += m
						}
						p += (isNaN(parseFloat(u.getAttribute("seed"), 10)) ? 0 : parseFloat(u.getAttribute("seed"), 10));
						v += (isNaN(parseFloat(u.getAttribute("step"), 10)) ? 0 : parseFloat(u.getAttribute("step"), 10)) 
					}
					if (t == 0) {
						t = this.tickerEndSum
					}
					if (typeof this.sign == "undefined") {
						this.sign = n[0].getAttribute("sign");
						if (this.sign.length > 1) {
							this.sign = " " + this.currency.toUpperCase();
							this.signpos = 1
						}
					}
					if (typeof this.signpos == "undefined") {
						this.signpos = n[0].getAttribute("pos")
					}
				}
			} else {
				o = this.findTargetNode(i);
				if (o) {
					if (this.type == "sum") {
						t = parseFloat(o.getAttribute("wins"), 10)
					} else {
						if (this.type == "count") {
							t = parseFloat(o.getAttribute("winc"), 10)
						} else {
							if (o.firstChild && o.firstChild.nodeValue) {
								t = parseFloat(o.firstChild.nodeValue, 10)
							}
						}
					}
					if (isNaN(t)) {
						t = this.tickerEndSum
					}
					if (typeof this.sign == "undefined") {
						this.sign = o.getAttribute("sign");
						if (this.sign.length > 1) {
							this.sign = " " + this.currency.toUpperCase();
							this.signpos = 1
						}
					}
					if (typeof this.signpos == "undefined") {
						this.signpos = o.getAttribute("pos")
					}
					p = parseFloat(o.getAttribute("seed"), 10);
					v = parseFloat(o.getAttribute("step"), 10);
					if (isNaN(p)) {
						p = 0
					}
					if (isNaN(v)) {
						v = 0
					}
				}
			}
		}
		this.setJackpot(t, p, v)
	},
	findTargetNodes: function (g) {
		var h = g;
		var f = [];
		if (this.type == "count") {
			return g.getElementsByTagName("total")
		}
		var j = h.getElementsByTagName("amount");
		for (var i = 0; i < j.length; i++) {
			if (j[i].getAttribute("currency").toLowerCase() == this.currency) {
				f.push(j[i])
			}
		}
		return f
	},
	findTargetNode: function (h) {
		var l = h;
		var j;
		if (this.info == 4) {
			var k = false;
			var i = h.getElementsByTagName("total");
			for (var m = 0; m < i.length; m++) {
				if (i[m].getAttribute("local") == this.local) {
					l = i[m];
					k = true
				}
			}
			if (!k) {
				return false
			}
			if (this.type == "count") {
				return l
			}
		}
		if (this.type == "count") {
			j = l.getElementsByTagName(this.countElement)[0]
		} else {
			var n = l.getElementsByTagName("amount");
			for (var m = 0; m < n.length; m++) {
				if (n[m].getAttribute("currency").toLowerCase() == this.currency) {
					j = n[m];
					break
				}
			}
		}
		return j
	},
	parseFromString: function (f) {
		var e = {};
		if (typeof(DOMParser) != "undefined") {
			var e = (new DOMParser()).parseFromString(f, "text/xml")
		} else {
			try {
				e = new ActiveXObject("Microsoft.XMLDOM");
				e.async = false;
				e.loadXML(f)
			} catch(d) {
				e.err = 1;
				e.errmsg = d
			}
		}
		if (f == "" || e.err == 1) {
			this.errormsg = e.errmsg;
			return false
		}
		return e
	},
	setJackpot: function (k, l, j) {
		this.tickerEndSum = k;
		var g = this.getJackpot();
		var h = Math.round((this.tickingPeriod / this.updateInterval) * 100000000000) / 100000000000;
		if (j > 0) {
			this.tickerStartSum = Math.max(this.tickerEndSum - j * this.tickingPeriod / 1000, this.tickerEndSum * this.startPercent / 100, l);
			this.tickerStartSum = Math.max(this.tickerStartSum, g);
			this.tickStep = Math.min(j, (this.tickerEndSum - this.tickerStartSum) / h)
		} else {
			this.tickerStartSum = this.tickerEndSum * this.startPercent / 100;
			this.tickerStartSum = Math.max(this.tickerStartSum, g);
			this.tickStep = (this.tickerEndSum - this.tickerStartSum) / h
		}
		this.tickerStartTime = (new Date()).getTime();
		if (this.debug) {
			var i = "";
			if (this.info == 1) {
				i += "GameTicker: " + this.game + "/" + (this.casino ? this.casino : "global") + "/" + this.currency
			}
			if (this.info == 2) {
				i += "CasinoTicker: " + this.casino + "/" + this.currency
			}
			if (this.info == 4) {
				i += "TotalTicker: " + (this.local == 2 ? "(local+global) " : (this.local == 1 ? "(local) " : "global ")) + this.currency
			}
			if (this.info == 5) {
				i += "GroupTicker: " + this.group + "/" + this.currency
			}
			if (this.type) {
				i += " - " + this.type
			}
			if (this.errmsg == "-") {
				this.debug.innerHTML = i + "<br>StartSum: " + this.tickerStartSum + "<br>EndSum: " + this.tickerEndSum + "<br>TickingPeriod: " + this.tickingPeriod + "<br>TickingStep: " + this.tickStep + "<br>" + this.xml
			} else {
				this.debug.innerHTML = i + "<br>" + this.errmsg + "<br>counter: " + this.counter
			}
		}
	},
	getJackpot: function () {
		var c = (new Date()).getTime();
		if (this.tickerStartTime == 0) {
			return 0
		}
		if (!this.ticking) {
			return this.tickerEndSum
		}
		var d = (c - this.tickerStartTime) / this.updateInterval;
		return this.tickerStartSum + d * this.tickStep
	},
	updateJackpot: function () {
		var b = (new Date()).getTime();
		if (this.counter == 0) {
			if (navigator && navigator.userAgent && ((navigator.userAgent.toLowerCase()).indexOf("opera") != -1)) {
				setTimeout(this.requestJackpot.bind(this), 100)
			}
			this.counter = this.counter + 1;
			this.downloadTime = b;
			this.requestJackpot();
			return
		}
		if (b > this.downloadTime + this.downloadInterval) {
			this.counter = this.counter + 1;
			this.downloadTime = b;
			this.requestJackpot();
			return
		}
		return false
	},
	showJackpot: function () {
		var d = this.getJackpot();
		if (this.type != "count") {
			d = Math.round(d * 100) / 100 + "";
			if (d.match(/^\d+\.\d$/)) {
				d = d + "0"
			}
			if (d.match(/^\d+$/)) {
				d = d + ".00"
			}
		}
		var c = "UPDATING";
		if (d > 0) {
			c = (this.signpos != 0 ? d + this.sign : this.sign + d)
		}
		if (d > 0 && this.type == "count") {
			c = d
		}
		this.textbox.innerHTML = this.textboxformatter ? this.textboxformatter(c) : c
	},
	tick: function () {
		if (!this.setup || !this.textbox) {
			return false
		}
		if (this.tickerStartTime != 0 && !this.ticking) {
			this.showJackpot();
			return false
		}
		this.updateJackpot();
		this.showJackpot();
		JackpotManager.register(this.tick.bind(this))
	}
};
