(function($) {
  $.fn.fullBg = function(src, initWidth, initHeight){
	  
	var iwRatio = initWidth / initHeight;
    var ihRatio = initHeight / initWidth;
	  
    var container = $(this);
    
    $(window).resize(function() {
      resizeImg();
    });
    
    initFullBg();
    
    function test() {
    	alert(container.width());
    	alert(container.height());
    }
    
    //window.setInterval(test, 3000);
    
    
    
    function initFullBg() {	
    	var initBounds = getResizeBounds();
    	container.html("<img id='fullbgimg' src='" + src + "' alt='' width='"+initBounds[0]+"' height='"+initBounds[1]+"' />");
    }
    
    function getResizeBounds() {
    	
    	var cWidth = container.width();
        var cHeight = container.height();
        
		var cwRatio = cWidth / cHeight;
		var chRatio = cHeight / cWidth;
		
		if(cwRatio > iwRatio) {	  
			var outWidth = cWidth;
			var outHeight = cWidth * ihRatio;
		} else {
			var outWidth = (cHeight * iwRatio);
			var outHeight = cHeight;
		}
		
		return [parseInt(outWidth), parseInt(outHeight)];
    }
    
    function resizeImg() {
    	 
    	var bounds = getResizeBounds();
    	
		$("#fullbgimg").css({
        	width: bounds[0] + 'px',
        	height: bounds[1] + 'px'
        });
    } 
    
  };
})(jQuery)
