GamePlay = Class.create({
	
	COUNT_MAX	: 15,
	
	initialize: function(containerHeight) {
		this.containerHeight	= containerHeight;
		this.gamePlayContainer 	= $("gamePlayContainer");
		this.gamePlayCounter	= $("gamePlayCounter");
		this.skipCounting		= $("skipCounting");
		this.displayCounter		= $("displayCounter");
		if (this.gamePlayContainer && this.gamePlayCounter && this.skipCounting && this.displayCounter)
		{
			this.started	= true;
			this.counter 	= this.COUNT_MAX;
			this.displaySeconds();
			this.skipCounting.observe("click", this.skipClick.bindAsEventListener(this));
			this.count.bind(this).delay(1);
		}
	},
	
	displaySeconds: function() {
		this.displayCounter.update(this.counter);
	},
	
	skipClick: function() {
		this.stop();
	},
	
	count: function() {
		this.counter--;
		if (this.counter > 0)
		{
			this.displaySeconds();
			this.count.bind(this).delay(1);
		} else
		{
			this.stop();
		}
	},
	
	stop: function() {
		if (this.started)
		{
			this.started	= false;
			this.counter 	= 0;
			this.gamePlayContainer.setStyle({
				visibility: "visible",
				height: this.containerHeight + "px" 
			});
			this.gamePlayCounter.hide();
		}
	}
	
});

Searcher = Class.create({
	
	initialize: function(baseUrl, searchUrl) {
		this.searchBox = $("searchBox");
		if (this.searchBox)
		{
			this.baseUrl 	= baseUrl;
			this.searchUrl 	= searchUrl;
			this.searchBox.observe("keypress", this.keyPress.bindAsEventListener(this));
		}
	},
	
	getKeyAndCharCode: function(e) {
		this.keyCode 	= 0;
		this.charCode 	= 0;
		if (Object.isUndefined(e.charCode)) // IE
		{
			this.charCode 	= e.keyCode;
			this.keyCode 	= 0;
		} else								// FF
		{
			this.charCode 	= e.charCode;
			this.keyCode 	= e.keyCode;
		}
	},
	
	keyPress: function(e) {
		this.getKeyAndCharCode(e);
		if (this.keyCode == 13)
		{
			var value = this.searchBox.getValue().trim();
			if (value != "")
			{
				top.location.href = this.searchUrl + value;
			} else
			{
				top.location.href = this.baseUrl;
			}
		}
	}
	
});

GameRating = Class.create({
	
	initialize: function(url, gameId) {
		this.url		= url;
		this.gameId		= gameId;
		this.thumbUp 	= $("thumbUp");
		this.thumbDown	= $("thumbDown");
		this.pleaseWait	= $("pleaseWait");
		this.ratingInfo	= $("ratingInfo");
		this.completed	= this.response.bind(this);
		this.thumbUp.observe("click", 	this.thumbUpClick.bindAsEventListener(this));
		this.thumbDown.observe("click", this.thumbDownClick.bindAsEventListener(this));
	},
	
	thumbUpClick: function() {
		this.request(5);
	},
	
	thumbDownClick: function() {
		this.request(1);
	},
	
	request: function(rating) {
		this.thumbUp.hide();
		this.thumbDown.hide();
		this.ratingInfo.hide();
		this.pleaseWait.show();
		new Ajax.Request(
				this.url,
				{
					method		: "get",
					parameters	: {g:this.gameId, r:rating},
					onComplete	: this.completed,
					onException	: this.completed
				});
	},
	
	response: function() {
		this.pleaseWait.removeClassName("blink");
		this.pleaseWait.update("Thank you for voting this game...");
	}
});


