/*
 * jQuery ratiobg
 * 
 * @author Domenico Falco
 * www.domenicofalco-design.com
 *
 * @version 1.1
 * Free to use
 *
 */

(function($){  

	jQuery.fn.ratiobg = function() {
	 
	   /* 
	 	* do not forget 
	 	* to put the style 
	 	* OVERFLOW -> HIDDEN 
	 	* at tag "body"
	 	*
	 	*/
	 	
	 	jQuery(window).load(function(){
	 	
		 	//var for window size
		 	 var alt;
		 	 var larg;
		 	 
		 	 //var for ratio
		 	 var propAlt;
		 	 var propLarg;
		 	 
		 	 
		 	 //calculate img size
		 	 var altImg = jQuery('img').height();
		 	 var largImg = jQuery('img').width();
		 	 
		 	 
		 	 //call function for the first time
		 	 resizeBg();
		 	 
		 	 
		 	 //call function resizeBg() when the users resize the window
		 	jQuery(window).resize(function(){
		 	 	resizeBg();
		 	 });
		 	 
		 	 
		 	 //develop function
		 	 function resizeBg() {
		 	 
		 	 	alt = jQuery(window).height();
		 	 	larg = jQuery(window).width();
		 	 	
		 	 	propAlt = alt/altImg;
		 	 	propLarg = larg/largImg;
		 	 	
		 	     jQuery('img').css({
		 	     	'width': largImg*propAlt + 'px',
		 	     	'height': altImg*propAlt + 'px'
		 	     });
		 	     
		 	     if(larg > (largImg*propAlt)){
		 	     	jQuery('img').css({
		 	     		'width': largImg*propLarg + 'px',
		 	     		'height': altImg*propLarg + 'px'
		 	     	});
		 	     }
		 	 }//end function
		 
			});	
	}
})(jQuery);
