var maxheight = 680;
var minheight = 570;
var bg_y = 160;
var bg_x = 160;
var offset_org = 0;

$(document).ready(function(){
	$(window).resize(function(){resize()});
	resize();
});

function resize()
{
	if (window.innerHeight)
	{
		var w = window.innerWidth;
		var h = window.innerHeight;
	} else
	{
		var w = document.documentElement.clientWidth;
		var h = document.documentElement.clientHeight - 30;
	}
	
	if (h < minheight)
	{
		height = minheight;
		y = 60;
	} else if (h < maxheight)
	{
		height = h;
		y = bg_y - (maxheight - h);
	} else
	{
		height = maxheight;
		y = bg_y;
	}
	
	x = bg_x;
	
	offset = y - bg_y;
	
	// position container vertically middle
	var $w = $(window);
	var availH = $(window).height();

	var $c = $("#container");
	$c.css({
		height: height + "px",
		marginTop: (availH / 2) - (height / 2) - 30
	})
	
	// reposition universe wrappers bg if present
	var $uni = $("#universe-wrapper");
	if ($uni.length > 0)
	{
		$uni.css("background-position", "center " + ($("#fallback").offset().top + 85) + "px");
	}
	
	// reposition background on wrapper
	if ($("#splash").length == 0)
	{
		var $wrap = $("#wrap");
		$wrap.css("background-position", "left " + ($("#container").outerHeight(true) - 120) + "px");
	}
	else
	{
		var $wrap = $("#wrap");
		$wrap.css("background-position", "left " + ($("#welcome").offset().top + 70 + "px"));
	}
	

	// document.getElementById('container').style.backgroundPosition = x+'px '+ y +'px';
	
	//document.body.style.backgroundPosition = '0px '+offset+'px';
	
	var width = parseInt($(window).width());
	
	if (width < 1100)
	{
		var offset = (1100 - width) / 2;
		
		$("#wrap").css('margin-left', '-'+offset+'px');
	}
}

