(function($) {
	
	/**
	 * Document ready
	 */
	$(function() {
				
		var $wrapper = $('#wrapper');

		var current_scale = 1.0;

		var center_content = function() {
			var content_height	= $wrapper.outerHeight() - 20*current_scale;
			var window_height	= $(window).height();
			var top = parseInt( (window_height - content_height) / 2 );
			if (top < 60*current_scale) top = 60*current_scale;
			
			$wrapper.css({top: top+'px'});
		};
		
		
		var resize_content = function() {

			var w = $(window).width();
			
			var c = '';
			var scale_w = 0, scale_h = 0;
			
			if (w < 1000) {
				scale_w = 0.75
				c = 'small';
			}
			else if (w > 1250) {
				scale_w = 1.25;
				c = 'large';
			}
			else {
				scale_w = 1.00;
				c = 'medium';
			}
			
			var h = $(window).height();
			var content_height = $wrapper.height();			
			content_height /= current_scale;
			content_height += 60;
			
			if (content_height*1.25 < h) {
				scale_h = 1.25;
			}
			else if (content_height < h) {
				scale_h = 1.0;
			}
			else {
				scale_h = 0.75;
			}
			
			current_scale = (scale_w<scale_h?scale_w:scale_h);
			
			if (current_scale == 1.0)		c = 'medium';
			else if (current_scale == 1.25)	c = 'large';
			else if (current_scale == 0.75) c = 'small';

			$(document.documentElement).attr('class',c);
			
		};
		
		$(window).resize(function() {
			resize_content();
			center_content();
		});
		resize_content();
		center_content();
		
		
		$('img').load(function() {
			resize_content();
			center_content();
		});
		
		
				
	});
	
	
	
	
})(jQuery);