(function ($, b) {
	$.extend($.support, {
		touch: typeof Touch == "object"
	});
	this.Insurge = {
		init : function(pageRouter) {
			if(typeof pageRouter != "undefined")
				this.loadResource(pageRouter);
			
			if ($.support.touch) $('#footer').css('position','absolute');
			$(window).resize(_.bind(this.resizeContent, this));
			var t = this;	
			window.onscroll = function() {
				if (!t.firstResize) {
					t.resizeContent();
					t.firstResize = true;
				}
				var posY = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : window.pageYOffset;
				var ground = document.getElementById('ground');
				var groundparallax = calcParallax(950, 14, posY);
				ground.style.backgroundPosition = "0 " + groundparallax + "px"; 
				
				var clouds = document.getElementById('content');
				var cloudsparallax = calcParallax(950, 2, posY);
				clouds.style.backgroundPosition = "0 " + cloudsparallax + "px"; 
			
			}		
		},
		firstResize: false,
		resizeContent: function() {
			
			var contentH = $('#content').height(), docH = $(document).height();
			$log(contentH+' '+docH)
			if (contentH < docH) $('#content').height(docH);
		},
		Api: b,
		loadResource :  function(pageRouter) {
			this._resources = {};
		
			if (this._resources[pageRouter] === true) return;
            var t = this;

            $.getScript(pageRouter, function () {
                t._resources[pageRouter] = true;
            });
		}
	};
	
	function calcParallax(tileheight, speedratio, scrollposition) {
		return (tileheight - (Math.floor(scrollposition / speedratio) % (tileheight+1)));
	}
	
})(jQuery, Backbone);


