$(document, this).ready(function(){
	
	function isIE(){
	  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
	}
	
	function checkIfReady(alto)
	{
		if ( alto<=0 ){
			$('#pageTitle').remove();
			$('.contentContainer').remove();
			setTimeout(function(){			
				window.location.href='overlay.games.php';
			}, 5000);
		} else {
			$('#ieLoadHelper').hide();
		}
	}
	
	function setContainerHeight()
	{
		var overflow = true;
		var holder = $('.linksHolder').height();
		
		var alto = 0;
		
		var hDoc = $(document).height();
		var hWin = $(window).height();
		
		if ( hDoc == hWin ){ alto = hDoc; }
		else { alto = hWin; }
		
		alto = alto - 10 - $('#pageTitle').height() - $('.textDescription').height() - 55 - $('.roundedBottom').height();
		
		if( alto >= holder ){
			overflow = false;
		}
		
		//$('#contentContainer').css({ height: alto+'px' });
		$('#contentContainer').height(alto);
		
		if( isIE() ){
			checkIfReady(alto);
		}		
		
		if ( overflow ){
			$('#contentContainer').css({ 'overflow-y': 'scroll', 'overflow-x': 'hidden' });
		} else{
			$('#contentContainer').css({ 'overflow': 'hidden'});
		}
		
	}
	
	$(window)
	.resize(function(){
		setTimeout(function(){
			setContainerHeight();
		}, 100);
	})
	.load(function(){
		setTimeout(function(){
			setContainerHeight();
		}, 100);
	})
	;
	
	setTimeout(function(){
		setContainerHeight();
	}, 100);
	
});