$(document).ready(function() {
	
$.fn.imageSize = function(width, height) { 	
	var img = $(this);
	stageRatio = $(window).width()/$(window).height();
	imageRatio = width/height;
	
	$("#data").empty().append('')
	if (stageRatio > imageRatio) {
		// match image width and adjust height to fit
		img.width($(window).width());
		img.height($(window).width()/imageRatio);
	} else {
		// match image height and adjust width to fit
			img.height($(window).height());
			img.width($(window).height()*imageRatio);
	}
}

$(function () {
    var img = new Image();
    $(img).load(function () {
        $(this).hide();
        $('#loader').removeClass('loading').append(this);

		//cache the image on load
		//and it's initial with/height ratio
      	var image = $(this);
		var width = image.width();
		var height = image.height();

		//resize against initial values
		$(img).imageSize(width, height);
		
        $(this).fadeIn();

		//resize image on window resize
		$(window).bind('resize', function(){
			$(image).imageSize(width, height);
		});
		
    }).error(function () {
        // notify the user that the image could not be loaded
    }).attr('src', 'http://thesocialdeviants.com/new/wp-content/themes/socialdeviants-1.0/images/SDbackground.jpg');
});
	

});
