$(function(){
  on = {
		get: {
			$window: $(window),
			$container: $('#container'),
			$footer: $('footer'),
			$p: $('#content p'),
			increment: 0,
			top: 0,
			bottom: 0,
			orig: {
				top: 0,
				bottom: 0,
				pos: 0
			}			
		},
		
		init: function() {
			on.get.$container.css('visibility', 'hidden').show();
  
		    on.get.orig.top = parseInt( on.get.$container.css('padding-top') );
			on.get.orig.bottom = parseInt( on.get.$container.css('padding-bottom') );
			on.get.orig.pos = parseInt( on.get.$footer.css('bottom') );
			
			on.resize();
			on.bind();
			
			$(window).load( function(){
				on.get.$container.hide().css('visibility', 'visible').fadeIn('350');		
				setTimeout(function() { window.scrollTo(0, 1) }, 100);
			});
		},
		
		bind: function() {
			on.get.$window.bind('resize', on.resize);
		},
		
		resize: function() {
			
			on.get.$container.css('padding-top', on.get.orig.top);
			on.get.$container.css('padding-bottom', on.get.orig.bottom);
			
			on.get.bottom = on.get.orig.bottom + on.get.$footer.outerHeight() - parseInt( on.get.$p.css('margin-bottom') );
			on.get.$container.css('padding-bottom', on.get.bottom);
			
			if( on.get.$container.height() < on.get.$window.height() ) {
				on.get.increment = ( on.get.$window.height() - on.get.$container.outerHeight() ) / 2;

				on.get.top = parseInt( on.get.orig.top ) + Math.floor(on.get.increment);
				on.get.bottom = on.get.bottom + Math.floor(on.get.increment);
				on.get.$container.css('padding-top', on.get.top);
				on.get.$container.css('padding-bottom', on.get.bottom);
				
				on.get.$footer.css('bottom', on.get.orig.pos + on.get.increment );
			}
			
			on.get.$footer.width( on.get.$window.width() - on.get.$footer.offset().left );
		}
	}
	
	on.init();
});

