// -*- coding: utf-8 -*-


jQuery.fn.resizeContainingImage = function() {
    var $obj = $(this[0]) // It's your element
    
    var $img = $obj.find("img");

    img_width = $img.width();

    img_height = $img.height();

    if(img_height==0){img_height=img_width};
    var img_ratio = img_width / img_height;

    var window_width = $(window).width();
    var window_height = $(window).height();

    window_ratio = window_width / window_height;

    if(window_ratio < img_ratio){
	$img.height(window_height).css("width", "auto").resize();
    }else {
	$img.width(window_width).css("height", "auto").resize();
    }
};





$(document).ready(function(){
    $(window).resize(function() {
	$("#background").resizeContainingImage();
      });
  });


$(window).load(function(){
	$("#background").resizeContainingImage();
});
