document.observe('dom:loaded', loadItems);

function loadItems() {
	if ($('menu')) Menu.init();
	if ($('topline')) Flag.init();
	if ($('list')) Dropdown.init();
	if ($('tournaments-table')) Tournaments.init();
	if ($('beginners-table')) Beginners.init();
	if ($('room-details')) Details.init();
	if ($('iframe')) Iframe.init();
	if ($('bonus-codes')) BonusCodes.init();
	if ($('steps')) RuleSteps.init();
	if ($('search-results')) AjaxFunctions.loadSearch();
	if ($('player-gallery')) Galery.init();
	/*Track.init('center');*/
}

var Menu = {
	timeouts: null,

	init: function() {
		var items = Element.childElements($('menu'));
		Menu.timeouts = new Array(items.length);
		for (var i = 0; i < items.length; i++) {
			items[i].name = i;
			Event.observe(items[i], "mouseover", Menu.show);
			Event.observe(items[i], "mouseout", Menu.startCount);
		}
	},

	show: function() {
		var items = Element.childElements($('menu'));
		for (var i = 0; i < items.length; i++) {
			if (Element.hasClassName(items[i], 'active')) Element.removeClassName(items[i], 'active');
		}
		Element.addClassName(this, 'active');
		if (Menu.timeouts[this.name]) {
			clearTimeout(Menu.timeouts[this.name]);
			Menu.timeouts[this.name] = null;
		}
	},

	startCount: function() {
		if (!Menu.timeouts[this.name]) {
			Menu.timeouts[this.name]=setTimeout('Menu.hide('+this.name+')', 500);
		}
	},
	
	stopCount: function() {
		if (Menu.timeouts[this.name]) {
			clearTimeout(Menu.timeouts[this.name]);
			Menu.timeouts[this.name] = null;
		}
	},
	
	hide: function(name) {
		var items = Element.childElements($('menu'));
		for (var i = 0; i < items.length; i++) {
			if (items[i].name == name) {
				if (Element.hasClassName(items[i], 'active')) Element.removeClassName(items[i], 'active');
			}
		}
		Menu.timeouts[name] = null;
	}
}

var News = {
	
	click: function(link) {
		if (Element.hasClassName(link, 'active')) return true;
		var parent = link.parentNode;
		var items = parent.getElementsByTagName('ul');
		for (var i=0; i<items.length; i++) {
			if (Element.hasClassName(items[i], 'active')) Element.removeClassName(items[i], 'active');
		}
		items = parent.getElementsByTagName('a');
		for (i=0; i<items.length; i++) {
			if (Element.hasClassName(items[i], 'active')) Element.removeClassName(items[i], 'active');
		}
		Element.addClassName(link.next(), 'active');
		Element.addClassName(link, 'active');
		return false;
	},

}


var AjaxFunctions = {
	loader: null,
	overlay: null,
	holder: null,
	lock: false,
	
/* forum */	
	
	login: function(page) {
		if (!AjaxFunctions.lock) {
			AjaxFunctions.lock = true;
			if ($('username') && $('password')) {
				new Ajax.Request('login.html', {
					method: 'post',
					parameters: {username: $('username').getValue(), password: $('password').getValue()},
					onCreate: function() {
						AjaxFunctions.showSplashScreen('popup');
					},
					onComplete: function(transport) {
						if (transport.responseText == 'reload') window.location=window.location;
						else {
							AjaxFunctions.hideSplashScreen();
							AjaxFunctions.showPopUp(transport.responseText);
						}
					}
				})
			} else {
				new Ajax.Request('login.html', {
					onCreate: function() {
						AjaxFunctions.showSplashScreen(page);
					},
					onComplete: function(transport) {
						AjaxFunctions.hideSplashScreen();
						AjaxFunctions.showPopUp(transport.responseText);
					}
				})
			}
		}
	},
	
	register: function() {
		if (!AjaxFunctions.lock) {
			AjaxFunctions.lock = true;
			if ($('password2')){
				new Ajax.Request('register.html', {
					method: 'post',
					parameters: {
						username: $('username').getValue(),
						password: $('password').getValue(),
						password2: $('password2').getValue(),
						mail: $('mail').getValue()},
					onCreate: function() {
						AjaxFunctions.showSplashScreen('popup');
					},
					onComplete: function(transport) {
						AjaxFunctions.hideSplashScreen();
						AjaxFunctions.showPopUp(transport.responseText);
					}
				})
			} else {
				new Ajax.Request('register.html', {
					onCreate: function() {
						AjaxFunctions.showSplashScreen();
					},
					onComplete: function(transport) {
						AjaxFunctions.hideSplashScreen();
						AjaxFunctions.showPopUp(transport.responseText);
					}
				})
			}
		}
	},

	forgot: function() {
		if (!AjaxFunctions.lock) {
			AjaxFunctions.lock = true;
			if ($('recover_email')){
				new Ajax.Request('forgot.html', {
					method: 'post',
					parameters: {
						username: $('recover_username').getValue(),
						email: $('recover_email').getValue()
					},
					onCreate: function() {
						AjaxFunctions.showSplashScreen('popup');
					},
					onComplete: function(transport) {
						AjaxFunctions.hideSplashScreen();
						AjaxFunctions.showPopUp(transport.responseText);
					}
				})
			}
			else {
				new Ajax.Request('forgot.html', {
					onCreate: function() {
						AjaxFunctions.showSplashScreen();
					},
					onComplete: function(transport) {
						AjaxFunctions.hideSplashScreen();
						AjaxFunctions.showPopUp(transport.responseText);
					}
				});
			}
		}
	},

	logout: function() {
		if (!AjaxFunctions.lock) {
			AjaxFunctions.lock = true;
			new Ajax.Request('logout.html', {
				onCreate: function() {
					AjaxFunctions.showSplashScreen();
				},
				onComplete: function(transport) {
					if (transport.responseText.match(/^location=/)) window.location=transport.responseText.match(/http.*/);
					else {
						AjaxFunctions.hideSplashScreen();
						AjaxFunctions.showPopUp(transport.responseText);
					}
				}
			})
		}
	},
	
	newTopic: function(category_id) {
		if (!AjaxFunctions.lock) {
			AjaxFunctions.lock = true;
			if (!category_id) {
				new Ajax.Request('forum/newtopic.html', {
					method: 'post',
					parameters: {category_id: $('category_id').getValue(), title: $('title').getValue(), content: $('textarea').getValue()},
					onCreate: function() {
						AjaxFunctions.showSplashScreen('forummessage');
					},
					onComplete: function(transport) {
						if (transport.responseText.match(/^location=/)) window.location=transport.responseText.match(/http.*/);
						else {
							AjaxFunctions.hideSplashScreen();
							AjaxFunctions.showPopUp(transport.responseText);
							Forum.init('textarea');
						}
					}
				})
			} else {
				new Ajax.Request('forum/newtopic.html', {
					method: 'post',
					parameters: {category_id: category_id},
					onCreate: function() {
						AjaxFunctions.showSplashScreen();
					},
					onComplete: function(transport) {
						AjaxFunctions.hideSplashScreen();
						AjaxFunctions.showPopUp(transport.responseText);
						Forum.init('textarea');
					}
				})
			}
		}
	},

	newPost: function(topic_id, post_id) {
		if (!AjaxFunctions.lock) {
			AjaxFunctions.lock = true;
			if (!topic_id) {
				new Ajax.Request('forum/newpost.html', {
					method: 'post',
					parameters: {topic_id: $('topic_id').getValue(), content: $('textarea').getValue()},
					onCreate: function() {
						AjaxFunctions.showSplashScreen('forummessage');
					},
					onComplete: function(transport) {
						if (transport.responseText.match(/^location=/)) window.location=transport.responseText.match(/http.*/);
						else {
							AjaxFunctions.hideSplashScreen();
							AjaxFunctions.showPopUp(transport.responseText);
							Forum.init('textarea');
						}
					}
				})
			} else {
				new Ajax.Request('forum/newpost.html', {
					method: 'post',
					parameters: {topic_id: topic_id, post_id: post_id},
					onCreate: function() {
						AjaxFunctions.showSplashScreen();
					},
					onComplete: function(transport) {
						AjaxFunctions.hideSplashScreen();
						AjaxFunctions.showPopUp(transport.responseText);
						Forum.init('textarea');
					}
				})
			}
		}
	},

	editPost: function(post_id) {
		if (!AjaxFunctions.lock) {
			AjaxFunctions.lock = true;
			if (!post_id) {
				new Ajax.Request('forum/editpost.html', {
					method: 'post',
					parameters: {post_id: $('post_id').getValue(), content: $('textarea').getValue()},
					onCreate: function() {
						AjaxFunctions.showSplashScreen('forummessage');
					},
					onComplete: function(transport) {
						if (transport.responseText.match(/^location=/)) window.location=transport.responseText.match(/http.*/);
						else {
							AjaxFunctions.hideSplashScreen();
							AjaxFunctions.showPopUp(transport.responseText);
							Forum.init('textarea');
						}
					}
				})
			} else {
				new Ajax.Request('forum/editpost.html', {
					method: 'post',
					parameters: {post_id: post_id},
					onCreate: function() {
						AjaxFunctions.showSplashScreen();
					},
					onComplete: function(transport) {
						AjaxFunctions.hideSplashScreen();
						AjaxFunctions.showPopUp(transport.responseText);
						Forum.init('textarea');
					}
				})
			}
		}
	},
	
	saveprofile: function() {
		if (!AjaxFunctions.lock) {
			AjaxFunctions.lock = true;
			new Ajax.Request('saveprofile.html', {
				method: 'post',	parameters: {
					form: $('editprofile').serialize()
				},
				onCreate: function() {
					AjaxFunctions.showSplashScreen();
				},
				onComplete: function(transport) {
					AjaxFunctions.hideSplashScreen();
					AjaxFunctions.showPopUp(transport.responseText);
				}
			})
		}
	},
	
	avatar: function() {
		if (!AjaxFunctions.lock) {
			AjaxFunctions.lock = true;
			new Ajax.Request('avatar.html', {
				onCreate: function() {
					AjaxFunctions.showSplashScreen();
				},
				onComplete: function(transport) {
					AjaxFunctions.hideSplashScreen();
					AjaxFunctions.showPopUp(transport.responseText);
				}
			})
		}		
	},
	
/* end forum */

/* promotions */
	
	tellafriend: function() {
		if (!AjaxFunctions.lock) {
			AjaxFunctions.lock = true;
			new Ajax.Request('tell-a-friend.html', {
				method: 'post',
				parameters: {
					my_name: $('my_name').getValue(),
					my_email: $('my_email').getValue(),
					friends_name: $('friends_name').getValue(),
					friends_email: $('friends_email').getValue()
				},
				onCreate: function() {
					AjaxFunctions.showSplashScreen();
				},
				onComplete: function(transport) {
					AjaxFunctions.hideSplashScreen();
					AjaxFunctions.showPopUp(transport.responseText);
				}
			})
		}
	},

	partypokerregister: function() {
		if (!AjaxFunctions.lock) {
			AjaxFunctions.lock = true;
			new Ajax.Request('party-poker-register.html', {
				method: 'post',
				parameters: {
					name: $('name').getValue(),
					lastname: $('lastname').getValue(),
					nickname: $('nickname').getValue(),
					email: $('email').getValue(),
					check: $('check').getValue()
				},
				onCreate: function() {
					AjaxFunctions.showSplashScreen();
				},
				onComplete: function(transport) {
					AjaxFunctions.hideSplashScreen();
					AjaxFunctions.showPopUp(transport.responseText);
				}
			})
		}
	},	
	

/* end of promotions */

	showPopUp: function(data) {
		if (!AjaxFunctions.overlay) {
			AjaxFunctions.overlay = document.createElement('div');
			AjaxFunctions.overlay.setAttribute('id', 'ajaxoverlay');
			AjaxFunctions.overlay.style.display = 'none';
			document.body.appendChild(AjaxFunctions.overlay);
			$('ajaxoverlay').style.width = AjaxFunctions.windowWidth()+'px';
			$('ajaxoverlay').style.height = AjaxFunctions.windowHeight()+'px';
			$('ajaxoverlay').style.zIndex = 100;
			if (AjaxFunctions.version() < 7) {
				$('ajaxoverlay').style.position = 'absolute';
				$('ajaxoverlay').style.top = AjaxFunctions.scrollTop()+'px';
			} else {
				$('ajaxoverlay').style.position = 'fixed';
				$('ajaxoverlay').style.top = '0px';
			}
			$('ajaxoverlay').style.left = '0px';
			
			AjaxFunctions.holder = document.createElement('div');
			AjaxFunctions.holder.setAttribute('id', 'ajaxholder');
			AjaxFunctions.holder.style.display = 'none';
			document.body.appendChild(AjaxFunctions.holder);
			$('ajaxholder').style.position = 'absolute';
			$('ajaxholder').style.zIndex = 150;
		}
		$('ajaxoverlay').style.display = 'block';
		$('ajaxholder').innerHTML = data;
		$('ajaxholder').style.display = 'block';
		$('ajaxholder').style.left = Math.round((AjaxFunctions.windowWidth()-$('ajaxholder').offsetWidth)/2)+'px';
		$('ajaxholder').style.top = (AjaxFunctions.scrollTop()+Math.round((AjaxFunctions.windowHeight()-$('ajaxholder').offsetHeight)/2))+'px';
	},
	
	hidePopUp: function() {
		$('ajaxoverlay').style.display = 'none';
		$('ajaxholder').style.display = 'none';
	},
	
	loadBonusTable: function() {
		if (!AjaxFunctions.lock) {
			AjaxFunctions.lock = true;
			new Ajax.Request('bonus-table.html', {
				method: 'post',
				parameters: {deposit: $('deposit').getValue()},
				onCreate: function() {
					AjaxFunctions.showSplashScreen('bonus-table');
				},
				onComplete: function(transport) {
					AjaxFunctions.hideSplashScreen();
					$('bonus-table').innerHTML = transport.responseText;
				}
			})
		}
	},

	loadSearch: function() {
		var items = $('search-results').getElementsByTagName('div');
		for (var i = 0; i < items.length; i++) {
			items[i].name = i;
			Event.observe(items[i], "click", function() {
				if (!AjaxFunctions.lock) {
					AjaxFunctions.lock = true;
					new Ajax.Request(window.location, {
						method: 'post',
						parameters: {type: this.id},
						onCreate: function() {
							AjaxFunctions.showSplashScreen('search-results');
						},
						onComplete: function(transport) {
							AjaxFunctions.hideSplashScreen();
							$('search-results').innerHTML = transport.responseText;
						}
					})
				}
			})
		}
	},
	
	loadCalendarTable: function(date) {
		if (!AjaxFunctions.lock) {
			AjaxFunctions.lock = true;
			new Ajax.Request('archive-table.html', {
				method: 'post',
				parameters: {date: date},
				onCreate: function() {
					AjaxFunctions.showSplashScreen('archive-table');
				},
				onComplete: function(transport) {
					AjaxFunctions.hideSplashScreen();
					$('archive-table').innerHTML = transport.responseText;
				}
			})
		}
	},
	
	subscribeNewsLetter: function() {
		if (!AjaxFunctions.lock) {
			AjaxFunctions.lock = true;
			new Ajax.Request('subscribe.html', {
				method: 'post',
				parameters: {name: $('name').getValue(), email: $('email').getValue()},
				onCreate: function() {
					AjaxFunctions.showSplashScreen('newsletter-table');
				},
				onComplete: function(transport) {
					var item = $('newsletter-table').getElementsByClassName('hidden');
					item[0].style.display = 'block';
					item = $('newsletter-table').getElementsByTagName('div');
					item[0].style.display = 'none';
					AjaxFunctions.hideSplashScreen();
					AjaxFunctions.lock = false;
					AjaxFunctions.scroll = false;
				}
			})
		}
	},
	
	showSplashScreen: function(element) {
		if (!AjaxFunctions.loader) {
			AjaxFunctions.loader = document.createElement('div');
			AjaxFunctions.loader.setAttribute('id', 'ajaxloader');
			AjaxFunctions.loader.style.display = 'none';
			document.body.appendChild(AjaxFunctions.loader);
			var ajaxbar = document.createElement('div');
			ajaxbar.setAttribute('id', 'ajaxbar');
			AjaxFunctions.loader.appendChild(ajaxbar);
		}
		if (!element) {
			AjaxFunctions.loader.width = AjaxFunctions.windowWidth();
			AjaxFunctions.loader.height = AjaxFunctions.windowHeight();
		} else {
			AjaxFunctions.loader.width = $(element).getWidth();
			AjaxFunctions.loader.height = $(element).getHeight();
		}
		$('ajaxloader').style.width = AjaxFunctions.loader.width+'px';
		$('ajaxloader').style.height = AjaxFunctions.loader.height+'px';
		swfobject.embedSWF("/img/preload.swf", "ajaxbar", AjaxFunctions.loader.width, AjaxFunctions.loader.height, "9.0.0", "expressInstall.swf", null, {quality:'high', scale:'noscale', wmode:'transparent', salign:'tl'});
		$('ajaxloader').style.display = 'block';
		$('ajaxloader').style.zIndex = 200;
		if (!element) {
			if (AjaxFunctions.version() < 7) {
				$('ajaxloader').style.position = 'absolute';
				$('ajaxloader').style.top = AjaxFunctions.scrollTop()+'px';
			} else {
				$('ajaxloader').style.position = 'fixed';
				$('ajaxloader').style.top = '0px';
			}
			$('ajaxloader').style.left = '0px';
		} else {
			$('ajaxloader').style.position = 'absolute';
			var poz = $(element).cumulativeOffset();
			$('ajaxloader').style.top = poz.top+'px';
			$('ajaxloader').style.left = poz.left+'px';
		}
	},
	
	hideSplashScreen: function() {
		$('ajaxloader').style.display = 'none';
		AjaxFunctions.lock = false;
	},

	scrollTop: function() {
		var result = window.pageYOffset?window.pageYOffset:0;
		result = (document.documentElement && result == 0)?document.documentElement.scrollTop:result;
		result = (document.body && result == 0)?document.body.scrollTop:result;
		return result;
	},

	windowWidth: function() {
		var result = window.innerWidth?window.innerWidth:0;
		result = (document.documentElement && result == 0)?document.documentElement.clientWidth:result;
		result = (document.body && result == 0)?document.body.clientWidth:result;
		return result;
	},

	windowHeight: function() {
		var result = window.innerHeight?window.innerHeight:0;
		result = (document.documentElement && result == 0)?document.documentElement.clientHeight:result;
		result = (document.body && result == 0)?document.body.clientHeight:result;
		return result;
	},

	version: function() {
		var version = 999;
		if (navigator.appVersion.indexOf("MSIE") != -1) version = parseFloat(navigator.appVersion.split("MSIE")[1]);
		return version;
	}
	
}

var Forum = {
	content: 'content',
	helpline: 'helpline',
	buttons: [
		{id: 'boldtext', title: 'Bold text: [b]text[/b]', opentag: '[b]', closetag: '[/b]', close: null},
		{id: 'italictext', title: 'Italic text: [i]text[/i]', opentag: '[i]', closetag: '[/i]', close: null},
		{id: 'underlinetext', title: 'Underline text: [u]text[/u]',	opentag: '[u]', closetag: '[/u]', close: null},
		{id: 'quotetext', title: 'Quote text: [quote]text[/quote]', opentag: '[quote]', closetag: '[/quote]', close: 'all'},
		{id: 'insertimage', title: 'Insert image: [img]http://image_url[/img]', opentag: '[img]', closetag: '[/img]', close: 'self'},
		{id: 'inserturl', title: 'Insert URL: [url]http://url[/url] or [url=title]http://url[/url]', opentag: '[url]', closetag: '[/url]', close: null},
		{id: 'closetag', title: 'Close open bbCode tag', opentag: null, closetag: null, close: ''}
	],
	opentags: Array(),
	selfclose: false,
	
	init: function(content, helpline) {
		if (content) Forum.content = content;
		if (helpline) Forum.helpline = helpline;
		for (i=0; i<Forum.buttons.length; i++) {
			$(Forum.buttons[i].id).name = i;
			Event.observe($(Forum.buttons[i].id), "mouseover", function() {
				$(Forum.helpline).value = Forum.buttons[this.name].title;
			});
			Event.observe($(Forum.buttons[i].id), "mouseout", function() {
				$(Forum.helpline).value = '';
			});
			Event.observe($(Forum.buttons[i].id), "click", Forum.addTag);
		}
	},
	
	addTag: function() {
		if (Forum.selfclose) {
			Forum.selfclose = false;
			$(Forum.content).value = $(Forum.content).value + Forum.buttons[Forum.opentags.last()].closetag;
			if (Forum.opentags.last() == this.name) {
				Forum.opentags.pop();
				$(Forum.content).focus();
				return;
			} else {
				Forum.opentags.pop();
			}
		}
		if (Forum.opentags.last() == this.name || Forum.buttons[this.name].opentag == null) {
			if (Forum.opentags.last() != 'undefined') {
				$(Forum.content).value = $(Forum.content).value + Forum.buttons[Forum.opentags.last()].closetag;
				Forum.opentags.pop();
			}
		} else if (Forum.buttons[this.name].close == 'all') {
			while (tag = Forum.opentags.pop()) {
				$(Forum.content).value = $(Forum.content).value + Forum.buttons[tag].closetag;
			}
			$(Forum.content).value = $(Forum.content).value + Forum.buttons[this.name].opentag;
			Forum.opentags.push(this.name);
		} else {
			if (Forum.buttons[this.name].close == 'self') Forum.selfclose = true;
			$(Forum.content).value = $(Forum.content).value + Forum.buttons[this.name].opentag;
			Forum.opentags.push(this.name);
		}
		$(Forum.content).focus();
		return;
	}
}

var Galery = {
	
	init: function() {
		var items = $('player-gallery').getElementsByTagName('li');
		for (var i = 0; i < items.length; i++) {
			items[i].name = i;
			Event.observe(items[i], "click", Galery.click);
		}
		if ($('previous')) {
			Event.observe($('previous'), "click", Galery.previous);
			Event.observe($('next'), "click", Galery.next);
		}
	},
	
	click: function() {
		var items = $('player-gallery').getElementsByTagName('img');
		for (var i = 0; i < items.length; i++) {
			if (Element.hasClassName(items[i], 'active')) Element.removeClassName(items[i], 'active');
		}
		Element.addClassName(items[this.name], 'active');
	},

	previous: function() {
		if (Element.hasClassName(this, 'disabled')) return 0;
		var items = $('player-gallery').getElementsByTagName('li');
		var active = 0;
		for (var i = 0; i < items.length; i++) {
			if (Element.hasClassName(items[i], 'active')) active = i;
		}
		Element.removeClassName(items[active], 'active');
		Element.addClassName(items[active-4], 'active');
		if (active-4 == 0) Element.addClassName(this, 'disabled');
		if (Element.hasClassName($('next'), 'disabled')) Element.removeClassName($('next'), 'disabled');
	},
	
	next: function() {
		if (Element.hasClassName(this, 'disabled')) return 0;
		var items = $('player-gallery').getElementsByTagName('li');
		var active = 0;
		for (var i = 0; i < items.length; i++) {
			if (Element.hasClassName(items[i], 'active')) active = i;
		}
		Element.removeClassName(items[active-3], 'active');
		Element.addClassName(items[active+1], 'active');
		if (active+2 == items.length) Element.addClassName(this, 'disabled');
		if (Element.hasClassName($('previous'), 'disabled')) Element.removeClassName($('previous'), 'disabled');
	}
}

var RuleSteps = {
	
	init: function() {
		var items = $('pages').getElementsByTagName('span');
		for (var i = 0; i < items.length; i++) {
			items[i].name = i;
			Event.observe(items[i], "click", RuleSteps.click);
		}
		Event.observe($('previous'), "click", RuleSteps.previous);
		Event.observe($('next'), "click", RuleSteps.next);
	},
	
	click: function() {
		if (Element.hasClassName(this, 'active')) return 0;
		var items = $('pages').getElementsByTagName('span');
		for (var i = 0; i < items.length; i++) {
			if (Element.hasClassName(items[i], 'active')) Element.removeClassName(items[i], 'active');
		}
		RuleSteps.updatePaging(this.name);
		RuleSteps.showPage(this.name);
		Element.addClassName(this, 'active');
	},
	
	previous: function() {
		if (Element.hasClassName(this, 'disabled')) return 0;
		var items = $('pages').getElementsByTagName('span');
		var active = 0;
		for (var i = 0; i < items.length; i++) {
			if (Element.hasClassName(items[i], 'active')) active = i;
		}
		Element.removeClassName(items[active], 'active');
		RuleSteps.updatePaging(active-1);
		RuleSteps.showPage(active-1);
		Element.addClassName(items[active-1], 'active');
	},

	next: function() {
		if (Element.hasClassName(this, 'disabled')) return 0;
		var items = $('pages').getElementsByTagName('span');
		var active = 0;
		for (var i = 0; i < items.length; i++) {
			if (Element.hasClassName(items[i], 'active')) active = i;
		}
		Element.removeClassName(items[active], 'active');
		RuleSteps.updatePaging(active+1);
		RuleSteps.showPage(active+1);
		Element.addClassName(items[active+1], 'active');
	},
	
	updatePaging: function(active) {
		if (Element.hasClassName($('previous'), 'disabled')) Element.removeClassName($('previous'), 'disabled');
		if (Element.hasClassName($('next'), 'disabled')) Element.removeClassName($('next'), 'disabled');
		var items = $('pages').getElementsByTagName('span');
		if (active == 0) Element.addClassName($('previous'), 'disabled');
		if (active == items.length - 1) Element.addClassName($('next'), 'disabled');
	},
	
	showPage: function(active) {
		var items = $('images').getElementsByTagName('li');
		for (var i = 0; i < items.length; i++) {
			if (Element.hasClassName(items[i], 'active')) Element.removeClassName(items[i], 'active');
		}
		Element.addClassName(items[active], 'active');
		items = $('texts').getElementsByTagName('li');
		for (var i = 0; i < items.length; i++) {
			if (Element.hasClassName(items[i], 'active')) Element.removeClassName(items[i], 'active');
		}
		Element.addClassName(items[active], 'active');
	}
}

var BonusCodes = {
	init: function() {
		var items = $('bonus-codes').getElementsByTagName('div');
		for (var i = 0; i < items.length; i++) {
			var tmp = items[i].parentNode;
			if (tmp.tagName == 'TD') {
				spans = Element.childElements(items[i]);
				Event.observe(spans[0], "click", BonusCodes.click);
			}
		}
	},
	
	click: function() {
		var tmp = this.parentNode;
		if (Element.hasClassName(tmp, 'active')) Element.removeClassName(tmp, 'active');
		else Element.addClassName(tmp, 'active');
	}
}

var Iframe = {
	init: function() {
		$('iframe').style.height = (AjaxFunctions.windowHeight() - 100) + 'px';
	}
}

var Details = {
	init: function() {
		var items = $('room-details').getElementsByTagName('h3');
		for (var i = 0; i < items.length; i++) {
			Event.observe(items[i], "click", Details.click);
		}
	},

	click: function() {
		var tmp = this.parentNode;
		if (Element.hasClassName(tmp, 'active')) Element.removeClassName(tmp, 'active');
		else Element.addClassName(tmp, 'active');
	}
}

var Beginners = {
	timeout: null,
	name: null,
	
	init: function() {
		var items = $('beginners-table').getElementsByTagName('li');
		for (var i = 0; i < items.length; i++) {
			if (Element.childElements(items[i]).length == 2) {
				items[i].name = i;
				Event.observe(items[i], "mouseover", Beginners.startCount);
				Event.observe(items[i], "mouseout", Beginners.stopCount);
			}
		}
	},
	
	startCount: function() {
		if (!Beginners.timeout) {
			Beginners.name = this.name;
			Beginners.timeout=setTimeout('Beginners.show()', 200);
		}
	},

	stopCount: function() {
		if (Beginners.timeout) {
			clearTimeout(Beginners.timeout);
			Beginners.timeout = null;
		}
	},

	show: function() {
		Beginners.timeout = null;
		var items = $('beginners-table').getElementsByTagName('li');
		for (var i = 0; i < items.length; i++) {
			if (Element.hasClassName(items[i], 'active')) Element.removeClassName(items[i], 'active');
			if (items[i].name == Beginners.name) Element.addClassName(items[i], 'active');
		}
	}
}

var Tournaments = {
	timeout: null,
	name: null,
	
	init: function() {
		var items = $('tournaments-table').getElementsByTagName('div');
		for (var i = 0; i < items.length; i++) {
			var tmp = items[i].parentNode;
			tmp.name = i;
			Event.observe(tmp, "mouseover", Tournaments.startCount);
			Event.observe(tmp, "mouseout", Tournaments.stopCount);
		}
	},

	startCount: function() {
		if (!Tournaments.timeout) {
			Tournaments.name = this.name;
			Tournaments.timeout=setTimeout('Tournaments.show()', 200);
		}
	},

	stopCount: function() {
		if (Tournaments.timeout) {
			clearTimeout(Tournaments.timeout);
			Tournaments.timeout = null;
		}
	},
	
	show: function() {
		Tournaments.timeout = null;
		var items = $('tournaments-table').getElementsByTagName('li');
		for (var i = 0; i < items.length; i++) {
			if (Element.hasClassName(items[i], 'active')) Element.removeClassName(items[i], 'active');
			if (items[i].name == Tournaments.name) Element.addClassName(items[i], 'active');
		}
	}
}

var Flag = {
	timeout: null,
	
	init: function() {
		var items = $('topline').getElementsByTagName('DIV');
		var poz = Element.cumulativeOffset(items[0]);
		$('languages').style.left = (poz.left-4)+'px';
		$('languages').style.top = (poz.top+16)+'px';
		Event.observe(items[0], "mouseover", Flag.show);
		Event.observe(items[0], "mouseout", Flag.startCount);
		Event.observe($('languages'), "mouseout", Flag.startCount);
		Event.observe($('languages'), "mouseover", Flag.stopCount);
		items = $('languages').getElementsByTagName('LI');
		for (var i = 0; i < items.length; i++) {
			Event.observe(items[i], "mouseover", function() {this.addClassName('hover');});
			Event.observe(items[i], "mouseout", function() {this.removeClassName('hover');});
		}
	},
	
	startCount: function() {
		if (!Flag.timeout) {
			Flag.timeout=setTimeout('Flag.hide()', 500);
		}
	},
	
	stopCount: function() {
		if (Flag.timeout) {
			clearTimeout(Flag.timeout);
			Flag.timeout = null;
		}
	},
	
	show: function() {
		Flag.stopCount();
		$('languages').style.display = 'block';
	},
	
	hide: function(name) {
		$('languages').style.display = 'none';
		Flag.timeout = null;
	}
}

var Dropdown = {
	timeout: null,
	
	init: function() {
		Event.observe($('list'), "mouseover", Dropdown.show);
		Event.observe($('list'), "mouseout", Dropdown.startCount);
		var item = $('list').getElementsByTagName("UL");
		Event.observe(item[0], "mouseout", Dropdown.startCount);
		Event.observe(item[0], "mouseover", Dropdown.stopCount);
	},
	
	startCount: function() {
		if (!Dropdown.timeout) {
			Dropdown.timeout=setTimeout('Dropdown.hide()', 250);
		}
	},
	
	stopCount: function() {
		if (Dropdown.timeout) {
			clearTimeout(Dropdown.timeout);
			Dropdown.timeout = null;
		}
	},
	
	show: function() {
		Dropdown.stopCount();
		var item = $('list').getElementsByTagName("UL");
		item[0].style.display = 'block';
	},
	
	hide: function(name) {
		var item = $('list').getElementsByTagName("UL");
		item[0].style.display = 'none';
	}
}

var Track = {
	IE: document.all?true:false,
	timenow: 0,
	mousex: 0,
	mousey: 0,
	scrollx: 0,
	scrolly: 0,
	windowx: 0,
	windowy: 0,
	scrollbar: 0,
	scrolling: 0,
	resizing: 0,
	url: location.href.toString(),
	align: 'left',
	server: 'http://track.allpokersites.com/',
	
	init: function(align) {
		var thisdate = new Date();
		Track.timenow = Math.round(thisdate.getTime()/1000);
		Track.align = align;
		Track.windowx = Track.windowWidth();
		Track.windowy = Track.windowHeight();
		Track.getScrollBar();
		if (!Track.IE) document.captureEvents(Event.MOUSEMOVE);
		document.onmousedown = Track.getClickXY;
		window.onscroll = Track.getScroll;
		window.onresize = Track.getResize;
		var string = Base64.encode('url='+Track.url+';wx='+Track.windowx+';wy='+Track.windowy+';ref='+document.referrer);
		var senddata = new Image();
		senddata.src = Track.server + 'load/'+string;
	},
	
	getScrollBar: function() {
		Track.scrollbar = document.body.offsetHeight>Track.windowy?1:0;
	},
	
	getScroll: function() {
		if (Track.scrolling) return true;
		Track.scrolling = 1;
		setTimeout('Track.sendScroll()', 1000);
	},
	
	sendScroll: function() {
		Track.scrolling = 0;
		Track.scrolly = Track.scrollTop();
		var string = Base64.encode('url='+Track.url+';top='+Track.scrolly+';wx='+Track.windowx+';wy='+Track.windowy);
		var senddata = new Image();
		senddata.src = Track.server + 'scroll/'+string;
	},
	
	getResize: function() {
		if (Track.resizing) return true;
		Track.resizing = 1;
		setTimeout('Track.sendResize()', 1000);
	},
	
	sendResize: function() {
		Track.resizing = 0;
		Track.windowx = Track.windowWidth();
		Track.windowy = Track.windowHeight();
		var string = Base64.encode('url='+Track.url+';wx='+Track.windowx+';wy='+Track.windowy);
		var senddata = new Image();
		senddata.src = Track.server + 'resize/'+string;
	},

	getClickXY: function(e) {
		if (Track.scrollbar) {
			if (Track.IE) {
				if (event.clientX>Track.windowx) return true;
			} else {
				if (e.pageX+16>Track.windowx) return true;
			}
		}
		var thisdate = new Date();
		if (Track.timenow == Math.round(thisdate.getTime()/1000)) return true;
		else Track.timenow = Math.round(thisdate.getTime()/1000);
		if (Track.IE) {
			Track.mousex = event.clientX + Track.scrollLeft();
			Track.mousey = event.clientY + Track.scrollTop();
		} else {
			Track.mousex = e.pageX  + Track.scrollLeft();
			Track.mousey = e.pageY;
		}
		if (Track.align == 'center') {
			if (Track.scrollbar && Track.documentWidth() > Track.windowx) Track.mousex = Math.round(Track.mousex-Track.documentWidth()/2);
			else if (Track.scrollbar && !Track.IE) Track.mousex = Math.round(Track.mousex-Track.windowx/2-8);
			else Track.mousex = Math.round(Track.mousex-Track.windowx/2);
		} else if (Track.align == 'right') {
			if (Track.scrollbar && Track.documentWidth() > Track.windowx) Track.mousex = Math.round(Track.documentWidth()-Track.mousex);
			else if (Track.scrollbar && !Track.IE) Track.mousex = Math.round(Track.documentWidth()-16-Track.mousex);
			else Track.mousex = Math.round(Track.windowx-Track.mousex);
		}
		var string = Base64.encode('url='+Track.url+';x='+Track.mousex+';y='+Track.mousey);
		var senddata = new Image();
		senddata.src = Track.server + 'click/'+string;
	},
	
	scrollLeft: function() {
		var result = window.pageXOffset?window.pageXOffset:0;
		result = (document.documentElement && result == 0)?document.documentElement.scrollLeft:result;
		result = (document.body && result == 0)?document.body.scrollLeft:result;
		return result;
	},

	scrollTop: function() {
		var result = window.pageYOffset?window.pageYOffset:0;
		result = (document.documentElement && result == 0)?document.documentElement.scrollTop:result;
		result = (document.body && result == 0)?document.body.scrollTop:result;
		return result;
	},
	
	windowWidth: function() {
		var result = window.innerWidth?window.innerWidth:0;
		result = (document.documentElement && result == 0)?document.documentElement.clientWidth:result;
		result = (document.body && result == 0)?document.body.clientWidth:result;
		return result;
	},

	windowHeight: function() {
		var result = window.innerHeight?window.innerHeight:0;
		result = (document.documentElement && result == 0)?document.documentElement.clientHeight:result;
		result = (document.body && result == 0)?document.body.clientHeight:result;
		return result;
	},

	documentWidth: function() {
		var result = document.body.parentNode.scrollWidth;
		if (Track.IE) {
			result = result - 20;
		} else {
			result = result - (Track.scrollbar?8:16);
		}
		return result;
	}

};

var Base64 = {

	//_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
	_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+|=",

	encode: function(input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
		input = Base64._utf8_encode(input);
		while (i < input.length) {
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
		}
		return output;
	},

	decode: function(input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
		//input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
		input = input.replace(/[^A-Za-z0-9\+\|\=]/g, "");
		while (i < input.length) {
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
		}
		output = Base64._utf8_decode(output);
		return output;
	},

	_utf8_encode: function(string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},

	_utf8_decode: function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while ( i < utftext.length ) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}

}

var Search = {
	url: '',
	error: '',

	keyup: function(event) {
		if (event.keyCode == 13) Search.dosearch();
	},
	
	dosearch: function() {
		if ($('search') && $('search').value) window.location = Search.url + $('search').value;
		else if ($('bottomsearch') && $('bottomsearch').value) window.location = Search.url + $('bottomsearch').value;
		else if ($('topsearch') && $('topsearch').value) window.location = Search.url + $('topsearch').value;
		else alert(Search.error);
	}
};

function jumpto(url) {
	window.location = url+$('jumpto').value+'/';
}