/*
 * Nederpoker
 * (c) 2006-2009 Omines - www.omines.nl
 * All rights explicitly reserved - unauthorized reproduction strictly prohibited
*/

// Compatibility stuff
Element.implement({
	effect: function(property, options){
		return new Fx.Tween(this, $extend({property: property}, options));
	},
	effects: function(property, options){
		return new Fx.Tween(this, $extend({property: property}, options));
	},
	show: function() { this.setStyle('display',''); },
	hide: function() { this.setStyle('display','none'); }
});

var Logger = {
	initialize: function()
	{
		// Check if we can use console.log, assuming no
		this.console		= false;
		if (window.console && window.console.firebug != '')
			this.console	= true;
	},
	log: function(message, level)
	{
		if (!this.console)
			return;
		switch (level)
		{
			case 0:	console.log(message);	break;
			case 1:	console.info(message);	break;
			case 2: console.warn(message);	break;
			case 3: console.error(message);	break;
		}
	}
};

// Site class - main active content wrapper
var Site = {
	start: function()
	{
		Logger.initialize();
		this.externalLinks();
		new SmoothScroll({duration:300, transition:Fx.Transitions.Expo.easeOut});
		Ellipses.start();
		this.initPaging();
		var myTips = new Tips('.tooltip', {className:'tooltips'});

		PaymentTabs.initialize();
		Nederdollars.initialize();
		Shoutbox.initialize();
		//PreferenceToggle.initialize();
		FancyCheckboxes.initialize();
		Rating.initialize();

		if ($('videosearchform'))
			ListPages.initVideos();
		if ($('articlesearchform'))
			ListPages.initArticles();
		if ($('leftsidebar'))
			$('leftsidebar').setStyle('height', $('page').getStyle('height').toInt() + 2);
		if ($('watisnederpoker'))
		{
			$('watisnederpoker').setStyle('cursor','pointer');
			$('watisnederpoker').addEvent('click', function() { window.location = '/welkom'; });
		}
	},
	initPaging: function()
	{
		this.pagers = [];
		$$('.paging').each(function (el, idx) { this.pagers[idx] = new Pager(el); }.bind(this));
	},
	externalLinks: function()
	{
		$$('a').each(function(a) {
			if (a.get('href') != '' && a.get('rel') == 'external')
			a.set('target', '_blank');
		});
	}
};

//ListPages class - generic functionality on search pages
var ListPages = {
	init: function()
	{
		// Initialize sorting
		$$('#searchresults table th.sortable').each(function(el, idx) {
			var sorter = new Element('a',{'name' : el.title, 'title':'sorteer op '+el.get('text'), 'text':el.get('text')});
			el.set({'text':'','title':''});
			sorter.addEvent('click', this.sortChanged.bindWithEvent(this)).inject(el);
		}, this);
	},
	initVideos: function()
	{
		this.formtype = 'videos';
		this.prepareForm($('videosearchform'));
		this.init();
	},
	initArticles: function()
	{
		this.formtype = 'articles';
		this.prepareForm($('articlesearchform'));
		this.init();
	},
	initNews: function()
	{
		this.formtype	= 'news';
		this.prepareForm($('newssearchform'));
		this.init();
	},
	prepareForm: function(form)
	{
		this.searchForm = form;
		$$('#'+form.get('id')+' input[type=submit]').each(function(el) { el.dispose(); });
		$$('#'+form.get('id')+' select').each(function(el) { el.addEvent('change', this.formChanged.bind(this)); }.bind(this));
		$$('#'+form.get('id')+' input[type=checkbox]').each(function(el) { el.addEvent('change', this.formChanged.bind(this)); }.bind(this));
		$$('#'+form.get('id')+' input[type=text]').each(function(el) { el.addEvent('change', this.formChanged.bind(this)); }.bind(this));
	},
	clear: function()
	{
		$$('#searchresults table tr.result').each(function(el, idx) { el.dispose(); }, this);
	},
	newCell: function(row, content, spacer)
	{
		var newCell	= new Element('td', {'text':content}).inject(row);
		if(spacer)
			new Element('td', {'class':'space'}).inject(row);
	},
	refill: function(data)
	{
		this.clear();
		var targ = $('searchresults').getFirst('table').getFirst('tbody');
		data.each(function(r, idx) {
			var row = new Element('tr', {'class':'result'});
			//var img = new Asset.image('/static/img/search/'+r.Level+'.png', {'title':r.Level, 'alt':r.Level});
			var img = new Element('img', {'src': '/static/images/search/'+r.Level+'.png', 'title':'poker video '+r.Level, 'alt':r.Level});
			var leveltd	= new Element('td', {'class':'trans'}).adopt(img);
			leveltd.inject(row);
			new Element('td').adopt(new Element('a', {'href':r.Url,'title':r.Title+' door '+r.Author}).set('text',r.Title)).inject(row);
			new Element('td', {'class':'space'}).inject(row);
			this.newCell(row, r.Date, true);
			new Element('td').adopt(new Element('a', {'href':'/profiel/'+r.AuthorId+'/'+r.AuthorSlug+'.html', 'title':'Bekijk het profiel van '+r.Author}).set('text',r.Author)).inject(row);
			new Element('td', {'class':'space'}).inject(row);
			//this.newCell(row, r.Author, true);
			this.newCell(row, r.Views, true);
			this.newCell(row, r.Rating, true);
			this.newCell(row, r.Game, false);
			if(this.formtype != 'articles')
			{
				this.newCell(row, r.Type, false);
				this.newCell(row, r.Stakes, false);
				this.newCell(row, r.CreditPrice, false);
			}
			else
			{
				this.newCell(row, r.Category, false);
				this.newCell(row, r.Stakes, false);
			}
			row.addEvent('click', function(e, url) { window.location = url; }.bindWithEvent(this, r.Url));
			row.inject(targ);
		}.bind(this));
		this.request	= new Request({
			url			: '/json/'+this.formtype+'/filter/',
			method		: 'get',
			link		: 'cancel',
			onComplete	: function(response) {
				if (this.formtype == 'videos')
					response	= '/poker-videos/'+response;
				$('directlink-anchor').set('href', response);
			}.bind(this)
		}).send();
		$('searching').setStyle('display','none');
		//$('directlink').setStyle('display','');
	},
	sortChanged: function(e)
	{
		$$('#searchresults th a.sorted').each(function(el, idx) { el.removeClass('sorted'); });
		var targ = e.target;
		var orderBy = $('search-orderby');
		var orderDir = $('search-orderdir');
		if(orderBy.value == targ.name)
			orderDir.value = (orderDir.value == '1') ? '0' : '1';
		else
		{
			orderBy.value = targ.name;
			orderDir.value = 0;
		} 
		targ.addClass('sorted');
		this.formChanged();
		return false;
	},
	formChanged: function()
	{
		if(this.request)
			this.request.cancel();
		$('directlink').setStyle('display','none');
		$('searching').setStyle('display','');
		this.request = new Request.JSON({
			url			: '/json/'+this.formtype+'/',
			method		: 'post',
			data		: this.searchForm,
			onComplete	: function(jsonObj) {
				this.request = null;
//				$('searchresults').set('text',jsonObj);
				this.refill(jsonObj.data);
			}.bind(this)
		}).send();
	}
};

var Shoutbox = {
	initialize: function()
	{
		if (!$('shoutbox-output'))
			return;
		this.shoutbox	= $('shoutbox');
		this.outputBox	= $('shoutbox-output');
		this.inputBox	= $('shoutbox-input');
		if (hideShoutbox)
		{
			this.inputBox.set({'disabled':'disabled','value':'Uitgeschakeld'});
			this.inputBox.setStyle('color','#aaaaaa');
			this.outputBox.empty();
			var item = new Element('li', {'text':'Je hebt de shoutbox uitgezet. Chatten is niet mogelijk.'}).injectInside(this.outputBox);
			return;
		}
		if (this.shoutbox)
			this.shoutbox.setStyle('display', 'block');
		if (this.inputBox)
		{
			this.inputBox.addEvent('keyup', this.sendUpdate.bindWithEvent(this));
			this.inputBox.addEvent('focus', this.focusBox.bindWithEvent(this));
			this.inputBox.setStyle('color','#aaaaaa');
			this.inputBox.value = 'Shout mee!';
		}
		this.firstShout	= true;
		this.update();
		this.update.periodical(30000, this);
	},
	update: function()
	{
		this.request	= new Request.JSON({
		    method			: 'get',
		    link			: 'cancel',
		    url				: '/json/shoutbox/',
		    onSuccess		: function(responseJson) {
				this.refill(responseJson.data);
			}.bind(this)
		}).send();
		//this.request.startTimer();
	},
	refill: function(data)
	{
		this.outputBox.empty();
		data.each(function (r) {
			var item = new Element('li');
			item.set('html', '<strong class="time" title="'+r.FullDate+'">'+r.Time+'</strong> <strong class="author">'+r.Author+': </strong>'+r.Message);
			item.injectInside(this.outputBox);
		}.bind(this));
	},
	focusBox: function(e)
	{
		if (this.firstShout)
		{
			this.inputBox.setStyle('color', '');
			this.inputBox.value = '';
			this.firstShout = false;
		}
	},
	sendUpdate: function(e)
	{
		var event = new Event(e);
		var shout = e.target.value.trim(); 
		if (event.key != 'enter')
		{
			if (shout.length > 150)
			{
				var cursor = e.target.selectionStart; 
				e.target.value = shout.substring(0, 150);
				e.target.selectionStart = cursor;
			}
			return;
		}
		if (shout.length >= 1)
		{
			this.request = new Request({
				url			: '/json/shoutbox',
				method		: 'post',
			    link		: 'cancel',
				data		: {'message': shout},
				onSuccess	: function(jsonObj, bla) {
					this.request = null;
					this.update();
				}.bind(this),
				onFailure	: function(xhr) { console.log(xhr); }
			});
			this.request.send();
		}
		e.target.value = '';
		e.target.focus();
	}
};

// Pager class - controls Javascript paged elements
var Pager = new Class({
	initialize: function(element)
	{
		this.root = element;
		this.pages = element.getChildren('.page');
		this.active = 0;
		if(this.pages.length > 1)
			this.createPager();
		else
			this.root.setStyle('background-image','none');
	},	
	perform: function()
	{
		this.pages.each(function (el, idx) {
			if(idx != this.active)
				el.addClass('hidden');
			else
				el.removeClass('hidden');
		}, this);
		if(this.active == 0)
			this.previous.addClass('hidden');
		else
			this.previous.removeClass('hidden');
		if(this.active == this.pages.length-1)
			this.next.addClass('hidden');
		else
			this.next.removeClass('hidden');		
	},
	createPager: function(element)
	{
		this.pager = new Element('div', {'class':'page-selection'}).injectInside(this.root);
		this.previous = new Element('a', {'class':'hidden','href':'#'}).injectInside(new Element('div', {'class':'previous'}).injectInside(this.pager)).set('text','vorige').addEvent('click',this.prevClick.bindWithEvent(this));
		this.next = new Element('a',{'href':'#'}).injectInside(new Element('div', {'class':'next'}).injectInside(this.pager)).set('text','volgende').addEvent('click',this.nextClick.bindWithEvent(this));
		this.pagelinks = new Element('div', {'class':'pages'}).injectInside(this.pager);
		for(var i = 0; i != this.pages.length; i++)
		{
			if(i != 0)
				this.pagelinks.appendText(' | ');
			new Element('a',{'href':'#'}).set('text',i+1).injectInside(this.pagelinks).addEvent('click',this.pageClick.bindWithEvent(this));
		}
		this.perform();
	},
	pageClick: function(e)
	{
		this.active = e.target.get('text')-1;
		this.perform();
		e.stop();
	},
	nextClick: function(e)
	{
		this.active++;
		this.perform();
		e.stop();
	},
	prevClick: function(e)
	{
		this.active--;
		this.perform();
		e.stop();
	}
});

// Payment Tabs - used on the credits page
var PaymentTabs = {
	initialize: function()
	{
		if (!$('paymentmethods'))
			return;
		this.container	= $('paymentmethods');
		this.tablist	= new Element('ul', {'class':'tablist'}).inject(this.container, 'top');
		this.tabframe	= new Element('div', {'id':'tabframe','class':'tabframe'}).inject(this.tablist, 'after');
		this.container.getChildren('h3').each(function(h) {
			var id = h.get('id').replace('-header', '');
			if (h.getFirst('img'))
			{
				var li = new Element('li', {'id':id+'-tab'});
				li.grab(h.getFirst('img'));
				li.set('title', h.get('text').clean());
			}
			else
				var li = new Element('li', {'id':id+'-tab','text':h.get('text')});
			li.addEvent('click', function() {this.toggleTab(li);}.bind(this));
			li.inject(this.tablist);
			h.dispose();
			this.tabframe.grab($(id+'-content'));
			$(id+'-content').addClass('tabcontent');
			$(id+'-content').hide();
		}.bind(this));
		this.tablist.getFirst('li').addClass('first');
		this.tablist.getFirst('li').addClass('active');
		this.tabframe.getFirst('div').show();
	},
	toggleTab: function(li)
	{
		this.tablist.getChildren().each(function(tab){
			var id	= tab.get('id').replace('-tab', '');
			tab.removeClass('active');
			$(id+'-content').hide();
		});
		var id	= li.get('id').replace('-tab', '');
		li.addClass('active');
		$(id+'-content').show();
	}
};

// Ellipses class - controls ellipsis elements on the site
var Ellipses = {
	start: function()
	{
		this.boundmove = this.mousemove.bindWithEvent(this);
		this.boundout = this.mouseout.bindWithEvent(this);
		this.count = 1;
		this.lookup = new Array();
		this.hovertip = new Element('span', {'class':'ellipsisHover'}).injectInside(document.body);
		this.hovertip.addEvent('mouseleave', this.boundout).addEvent('mousemove', this.boundmove);
		$$('.ellipsis').each(this.prepare, this);
	},
	prepare: function(el)
	{	
		var parent = el.getParent();
		var clipWidth = parent.offsetWidth - (el.offsetLeft - parent.offsetLeft);
		if(el.offsetWidth > clipWidth)
		{
			el.addEvent('mouseenter', this.hover.bindWithEvent(this));
			if(el.id == '')
				el.id = 'ellipsis'+this.count++;
			var content = el.get('text');
			this.lookup[el.id] = content;
			el.title = '';
			if(!window.ie)
			{
				content = content.substring(0, (clipWidth / (el.offsetWidth)) * content.length);
				do {
					el.set('html', content+'&hellip;');
					content = content.substring(0, content.length - 1);
				} while(el.offsetWidth > clipWidth);
			}
		}
	},
	hover: function(e)
	{
		var el = e.target;
		var cnt = this.lookup[el.id];
		this.hovertip.setStyles(el.getStyles('font-size','font-style','color'));
		this.hovertip.setStyles({
			position:'absolute',
			left:el.getLeft()-2,
			top:el.getTop()-2,
			visibility:'hidden'
		});
		if(el.get('tag') == 'a')
			cnt = '<a href="'+el.href+'">'+cnt+'</a>';
		this.hovertip.set('html', cnt);
		el.addEvent('mouseleave', this.boundout).addEvent('mousemove', this.boundmove);
		if(this.fx) this.fx.cancel();
		this.show.delay(150, this);
		this.target = el;
	},
	mousemove: function(e)
	{
		$clear(this.timer);
	},
	mouseout: function(e)
	{
		var c = e.target.getCoordinates();
		if(c.left > e.client.x || c.right < e.client.x || c.top > e.client.y || c.bottom < e.client.y)
			this.timer = this.hide.delay(250, this);
	},
	show: function(e)
	{
		this.fx	= new Fx.Tween(this.hovertip, {duration:'short'});
		this.fx.start('opacity', 0.5, 1);
		//this.fx = new Fx.Style(this.hovertip, 'opacity').start(0.5, 1);
	},
	hide: function(e)
	{
		this.fx.cancel();
		this.hovertip.setStyle('visibility','hidden');
		if(this.target)
			this.target.removeEvent('mouseleave', this.boundout).removeEvent('mousemove', this.boundmove);
		this.target = null;
	}
};

// RailForum class
var RailForum = {
	initialize: function()
	{
		this.railForum	= $('forum-display');
		this.reloadBtn	= $('reload-forum');
		this.threadId	= $('forum-threadid').getText();
		this.checkForum.periodical(30*1000, this);
	},
	checkForum: function ()
	{
		if (this.rfrequest)
			this.rfrequest.cancel();
		var checkDate	= new Date();
		this.rfrequest = new Ajax('/postbacks/rail-forum.php?do=check&threadid=' + this.threadId + '&time=' + (checkDate.getTime()/1000.0), {
			method: 'get',
			onComplete: function (r) {
				if (r == 1)
					this.refillForum();
			}.bind(this)
		}).request();
	},
	refillForum: function ()
	{
		if (this.rfrequest)
			this.rfrequest.cancel();
		var checkDate	= new Date();
		this.rfrequest = new Ajax('/postbacks/rail-forum.php?do=reload&threadid=' + this.threadId + '&time=' + (checkDate.getTime()/1000.0), {
			method: 'get',
			onComplete: function(r) {
				this.rfrequest = null;
				this.railForum.innerHTML = r;
			}.bind(this)
		}).request();
	}
};

// Nederdollars class
var Nederdollars = {
	initialize: function()
	{
		if (!$('nederdollars'))
			return;
		this.toggleType('T');
		$('VerkoopT').addEvents({
			'keyup':	function()	{ this.recalcPrice(); }.bind(this),
			'focus':	function()	{ if (this.value == '0') this.value = ''; },
			'blur':		function()	{ if (this.value == '') this.value = '0'; }
		});
		$('VerkoopW').addEvents({
			'keyup':	function()	{ this.recalcPrice(); }.bind(this),
			'focus':	function()	{ if (this.value == '0') this.value = ''; },
			'blur':		function()	{ if (this.value == '') this.value = '0'; }
		});
		$('SellT').addEvent('change', function() { this.toggleType('T'); }.bind(this));
		$('SellW').addEvent('change', function() { this.toggleType('W'); }.bind(this));
	},
	toggleType: function(type)
	{
		$('VerkoopT').set({disabled:'disabled', value:'0'});
		$('VerkoopW').set({disabled:'disabled', value:'0'});
		$('TotaalPrijsT').set({disabled:'disabled', value:'0.00'});
		$('TotaalPrijsW').set({disabled:'disabled', value:'0.00'});
		
		
		$('Sell'+type).set('checked', 'checked');
		$('Verkoop'+type).erase('disabled');
		$('TotaalPrijs'+type).erase('disabled');
		
		this.recalcPrice();
	},
	recalcPrice: function()
	{
		var at	= $('VerkoopT').value.replace(/\D/g,"");
		var aw	= $('VerkoopW').value.replace(/\D/g,"");
		
		if ($('VerkoopT').get('disabled') == 'disabled')	{ at = 0; }
		if ($('VerkoopW').get('disabled') == 'disabled')	{ aw = 0; }
		
		$('VerkoopT').value	= at;
		$('VerkoopW').value	= aw;
		
		if (at == '') { at = 0; /*$('VerkoopT').set('value', 0);*/ }
		if (aw == '') { aw = 0; /*$('VerkoopW').set('value', 0);*/ }
							
		$('TotaalPrijsT').set('value', monetary(at * rateT));
		$('TotaalPrijsW').set('value', monetary(aw * rateW));
	}
};

var FancyCheckboxes = {
	initialize: function()
	{
		if ($$('.tickbox').length == 0)
			return;
		this.boxsets	= $$('.tickbox');
		this.boxsets.each(function(tbp) {
			if (tbp.getFirst('input[type=radio].toggler'))
				this.replaceRadio(tbp, false);
			else if (tbp.getFirst('input[type=checkbox].toggler'))
				this.replaceCheckbox(tbp, false);
			else if (tbp.getFirst('label') && tbp.getFirst('label').getFirst('input[type=radio].toggler'))
				this.replaceRadio(tbp, true);
			else if (tbp.getFirst('label') && tbp.getFirst('label').getFirst('input[type=checkbox].toggler'))
				this.replaceCheckbox(tbp, true);
		}.bind(this));
	},
	replaceCheckbox: function(p, hasLabel)
	{
		if (hasLabel)
			var o	= p.getFirst('label').getFirst('input');
		else
			var o	= p.getFirst('input');
		var oid		= o.get('id');
		var toggler	= new Element('img', {'id':'toggler-'+oid, 'class':'toggler', 'alt':'', 'src':'/static/images/icons/tick-off.png'}).inject(o, 'before');
		var hidden	= new Element('input', {'type':'hidden', 'id':oid, 'name':o.get('name'), 'value':'0'}).inject(o, 'before');
		if (o.get('checked'))
		{
			toggler.set('src', '/static/images/icons/tick.png');
			hidden.set('value', '1');
		}
		o.dispose();
		
		toggler.addEvent('click', function(){
			if (hidden.get('value') == 1)
			{
				hidden.set('value', '0');
				toggler.set('src', '/static/images/icons/tick-off.png');
			}
			else
			{
				hidden.set('value', '1');
				toggler.set('src', '/static/images/icons/tick.png');
			}
			toggler.highlight('#ddf');
		}.bind(this));
	},
	replaceRadio: function(p, hasLabel)
	{
		p.addClass('tickbox-radio');
		var togglers	= new Array();
		var radios		= new Array();
		if (hasLabel)
		{
			var base	= p.getFirst('label').getFirst('input[type=radio].toggler');
			p.getChildren('label').each(function(label) { radios.include(label.getFirst('input[type=radio].toggler')); });
		}
		else
		{
			var base	= p.getFirst('input[type=radio].toggler');
			radios		= p.getChildren('input[type=radio].toggler');
		}
		var baseId	= base.get('id').replace('-'+base.get('value'), '');
		var hidden	= new Element('input', {'type':'hidden', 'id':baseId, 'name':base.get('name'), 'value':''}).inject(p, 'bottom');
		radios.each(function(o){
			var oid		= o.get('id');
			var toggler	= new Element('img', {'id':'toggler-'+oid, 'class':'toggler', 'alt':o.get('value'), 'src':'/static/images/icons/tick-off.png'}).inject(o, 'before');
			if (o.get('checked'))
			{
				toggler.set('src', '/static/images/icons/tick.png');
				hidden.set('value', '1');
			}
			o.dispose();
			togglers.include(toggler);
			
			toggler.addEvent('click', function(){
				togglers.each(function(r){
					r.set('src', '/static/images/icons/tick-off.png');
				}.bind(this));
				hidden.set('value', toggler.get('alt'));
				toggler.set('src', '/static/images/icons/tick.png');
				toggler.highlight('#ddf');
			}.bind(this));
		}.bind(this));
		if (hidden.get('value') == '')
			togglers[0].fireEvent('click');
	}
};

var Rating = {
	initialize: function()
	{
		if (!$('rating-block'))
			return;
		this.average		= $('rating-average');
		this.counter		= $('rating-votes');
		this.current		= $('rating-current');
		this.loader			= $('rating-loader');
		
		this.loader.setStyle('display', 'none');
		this.loader.set('text', 'Bezig met verzenden...');
		this.loader.set('tween', {duration:350, link:'chain'});
		
		$$('.rating-star').each(function(star) {
			star.addEvent('click', function(){
				var idParts	= star.id.split('-');
				this.send(idParts[1], idParts[2], idParts[3]);
				return false;
			}.bind(this));
		}.bind(this));
	},
	send: function(type, target, rating)
	{
		this.loader.setStyle('display', 'block');
		this.request	= new Request.JSON({
			url:		'/json/rating/',
			link:		'cancel',
			method:		'post',
			onComplete:	function (result) { this.postProcess(result); }.bind(this)
		}).send('type='+type+'&target='+target+'&rating='+rating);
	},
	postProcess: function(json)
	{
		this.loader.set('text', json.data.msg);
		this.average.set('text', json.data.avg);
		this.counter.set('text', json.data.votes);
		this.current.setStyle('width', json.data.pct+'%');
		
		var loaderFade	= new Fx.Tween(this.loader, {
			duration:	2500,
			link:		'ignore',
			onComplete:	function(){ this.loader.setStyle('display','none'); this.loader.setStyle('opacity','1'); }.bind(this)
		});
		var origColor	= this.loader.getStyle('background-color');
		this.loader.tween('background-color', '#ffffff');
		this.loader.tween('background-color', origColor);
		this.loader.tween('background-color', '#ffffff');
		this.loader.tween('background-color', origColor);
		this.loader.tween('background-color', '#ffffff');
		this.loader.tween('background-color', origColor);
		loaderFade.start('opacity', 0);
	}
};

function monetary(amount)
{
	if (amount == 0)	{ return '0.00'; }
	if (amount < 0)		{ amount	= amount * -1; }
	var iAmount	= amount.toInt();
	var iRem	= ((amount - iAmount) * 100).round();
	if (iRem < 10)		{ iRem	= '0'.iRem; }
	if (typeof iRem == 'undefined')	{ return iAmount+'.00'; }
	return iAmount+'.'+iRem;
}

function OpenVideo(target, width, height)
{
	var origWidth	= width;
	var origHeight	= height;
	
	if (screen.height > 0)
	{
		if (height > screen.height)
		{
			height	= screen.height - 20;
			width	= width * (height / origHeight);
		}
		else if (width > screen.width)
		{
			width	= screen.width - 10;
			height	= height * (width / origWidth);
		}
		
		if (height != origHeight || width != origWidth)
		{
			height	= Math.round(height);
			width	= Math.round(width);
			height	= height + 40;
		}
	}
	window.open(target, 'NederpokerVideo', 'width=' + width + ',height=' + height + ',menu=0,scrollbar=0,resizable=1,status=1');
}

// Set event to start running active content when DOM is loaded
window.addEvent('domready', function() { Site.start(); });

function CreateMP3Player(file, title)
{
	AC_FL_RunContent(
		"src", '/static/xspf/xspf_player_slim',
		"FlashVars", "song_url="+file+'&song_title='+title+'&player_title='+title,
		"menu","false",
		"width", 400,
		"height", 15,
		"align", "middle",
		"id", 'NederpokerMP3',
		"quality", "high",
		"bgcolor", '#D8E8F6',
		"name", 'NederpokerMP3',
		"allowFullScreen","false",
		"allowScriptAccess","always",
		"type", "application/x-shockwave-flash",
		'codebase', 'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',
		"pluginspage", "http://www.adobe.com/go/getflashplayer"
	);
}