// remap jQuery to $
(function($){})(window.jQuery);

$("#imgTexture").hide().bind('load', function () { $(this).fadeIn(); });

function makeItFit(img) {
	
	img = $('#imgTexture');

	var pw = $(window).width();
	var ph = $(window).height();
	
	
	var pd = $('#bgTexture');
	
	pd.css ({
		'width':pw,
		'height':ph
	});
	
	var wpc = parseInt((pw / img.attr('width')) * 100);
	var hpc = parseInt((ph / img.attr('height')) * 100);
	
		
	var va = $('viewArea');
	
	if (wpc > hpc) {
	
		var nh = (img.attr('height') * (wpc / 100));
		img.css({
			'width': pw,
			'height': nh,
			'left':0,
			'top': -((nh - ph) / 2)
		});
		va.css ({
			'width': img.attr('width') * .05,
			'height': (img.attr('height') * .05) * (ph / nh),
			'left': 0,
			'top': ((img.attr('height') * .05) - ((img.attr('height') * .05) * (ph / nh))) / 2
		});
		
	} else {
		var nw = (img.attr('width') * (hpc / 100));
		img.css({
			'width': nw,
			'height': ph,
			'top':0,
			'left': -((nw - pw) / 2)
		});
		va.css ({
			'width': (img.attr('width') * .05) * (pw / nw),
			'height': (img.attr('height') * .05),
			'left': ((img.attr('width') * .05) - (img.attr('width') * .05) * (pw / nw)) / 2,
			'top': 0
		});
	};
	
	
};

$(document).ready(function (){
	
	makeItFit();
	
	$(window).resize(function (){
		makeItFit();
	})
		
});


