var ACT = 
{
	getClientSize : function()
	{
		var dimensions = {width: 0, height: 0};
	     if (document.documentElement) {
	         dimensions.width = document.documentElement.offsetWidth;
	         dimensions.height = document.documentElement.offsetHeight;
	     } else if (window.innerWidth && window.innerHeight) {
	         dimensions.width = window.innerWidth;
	         dimensions.height = window.innerHeight;
	     }
	     return dimensions;
	},
	
	getToken : function()
	{
		return parseInt( (new Date()).getTime()/10000 ) + '';
	},
	
	setUTF8 : function()
	{
		var charset = (typeof document.charset == "undefined" || document.charset == null) ? document.characterSet : document.charset;
		if( charset != "UTF-8" && charset != "utf-8" ) 
		{
			try 
			{
				if(typeof document.charset == "undefined" ) 
					document.characterSet = "UTF-8"; //FF, hopefully someday FF allows it
				else
					document.charset = "UTF-8"; //IE
			} catch (e) {}
			window.location.reload();
		}
	},
	
	resizeIframe : function()
	{
		$("#frameContent").height(clientSize.height - 50);
	},
	
	resizeContentHeight : function()
	{
		$("#mainContent").height(ACT.getClientSize().height - 25);
	}
};
GAME = 
{
	listItemClick : function(item, callback)
	{
		var link = $(item).attr("href");
		if (link != "#") {
			GAME.loadGData(link, "#mainContent", callback);
			GAME.listItemSelect($("#sideBar a[href=\"" + link +"\"]").parent());
		}
	},
	
	listItemSelect : function(liItem)
	{
		GAME.listItemDeselectAll();
		$(liItem).addClass("selected");
	},
	
	listItemDeselectAll : function()
	{
		$("ul.game-list li.selected").removeClass("selected");
	},
	
	loadGData : function(url, container, callback)
	{
		$('html,body').animate({scrollTop : 0},'slow');
		$(container).slideUp('normal');
		$.get(
			url,
			function(data)
			{
				$(container).html(GAME.getContent(data)).slideDown('fast');
				if(callback)
				{
					callback();
				}
			}
		);
	},
	
	TOKEN_START : '<!--start-content-->',
	getContent : function(data)
	{
		var idxStart = data.indexOf(GAME.TOKEN_START) + GAME.TOKEN_START.length;
		var idxEnd = data.indexOf('<!--end-content-->');
		return data.substring(idxStart, idxEnd);
	}
};

$(document).ready(
	function()
	{
		ACT.setUTF8();
		$("iframe#navbar-iframe, script:eq(0), div:eq(0)").remove();
		
		if (location.href != "http://free.ola.vn/")
		{
			$(".main").addClass("goog-ws-outside-in").removeClass("main").css({margin:"5px", backgroundColor : "#fff"});
		}
		
		$("a#logo").click(
			function()
			{
				GAME.listItemClick(
					this,
					function()
					{
						$("#mainContent a").click(
							function()
							{
								GAME.listItemClick(this);
								return false;
							}
						);
					}
				);
				return false;
			}
		).click();
		
		$("#sideBar a").click(
			function()
			{
				GAME.listItemClick(this);
				return false;
			}
		);
	}
);
