var gamesbrowser = {

	// Left position.
	left: 0,
	
	// Move step length.
	stepLength: 300,
	
	// Step duration.
	stepDuration: 500,
	
	// Scroll area width.
	scrollAreaWidth: 0,
	
	// Left limit.
	leftLimit: 0,

	/**
	 * Init browser.
	 */
	init: function() {

		// Calculate the width for scroll area.
		var item = $("#gameBrowserInner .game:first");
		var items = $("#gameBrowserInner .game");
	
		gamesbrowser.scrollAreaWidth = item.width() * items.length;
		
		// Set width.
		$("#gameBrowserInner").css("width", gamesbrowser.scrollAreaWidth);
		
		// Calculate left limit.
		gamesbrowser.leftLimit = - gamesbrowser.scrollAreaWidth + $("#gameBrowser").width();
		
		//console.log(gamesbrowser.scrollAreaWidth +  " " + gamesbrowser.leftLimit);
		
		$("#gameBrowserButtonRight").click(function(){
		
			gamesbrowser.left = gamesbrowser.left - gamesbrowser.stepLength;
			
			if (gamesbrowser.left < gamesbrowser.leftLimit) gamesbrowser.left = gamesbrowser.leftLimit;
					
			
			
			$("#gameBrowserInner").animate(
				{
					"left": gamesbrowser.left
				}, 
				gamesbrowser.stepDuration);
		});
	
		$("#gameBrowserButtonLeft").click(function(){
		
			gamesbrowser.left = gamesbrowser.left + gamesbrowser.stepLength;
			if (gamesbrowser.left > 0) gamesbrowser.left = 0;
			$("#gameBrowserInner").animate(
				{
					"left": gamesbrowser.left
				}, 
				gamesbrowser.stepDuration);
			
			//$("#gameBrowserInner").animate();
		});
	
	}

};
