window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){arguments.callee=arguments.callee.caller;var a=[].slice.call(arguments);(typeof console.log==="object"?log.apply.call(console.log,console,a):console.log.apply(console,a))}};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
{console.log();return window.console;}catch(err){return window.console={};}})());


/**
 * Fullscreenry - lightweight full screen background jquery plugin extended
 * By Robert Weber
 * Version 1.1
 * www.closingtag.org
 *
 * based on: Fullscreenr By Jan Schneiders
 * http://nanotux.com/blog/fullscreen/
 * www.nanotux.com
 **/

(function($){ 
  
  $.fn.fullscreenry = function(options) {
    var defaults = { width: 1280,  height: 1024, elm: 'body' };
    var options = $.extend({}, defaults, options); 
    
    // Set bg size
    var ratio = options.height / options.width; 
    // Get browser window size
    var browserwidth = $(window).width();
    var browserheight = $(window).height();
    
    var loader_img = "img/loader.gif";
    var bg_img = $(options.elm).css('background-image').replace(/^(url\(")(.+)("\))$/,"$2").replace(/^(url\()(.+)(\))$/,"$2");
    
    $(options.elm).css({"background-image": "url("+loader_img+")"});
    
    $('body').append('<img />');
    
    var $img =  $('body > img:last');
    
    $img.addClass('fullscreenry')
    $img.attr('src', bg_img)
    
    $img.css({
      "position":"absolute",
      "top": "0",
      "left": "0",
      "z-index": "-1"
    });
    

    // Scale the image
    if ((browserheight/browserwidth) > ratio){
        $img.height(browserheight);
        $img.width(browserheight / ratio);
    } else {
        $img.width(browserwidth);
        $img.height(browserwidth * ratio);
    }
    
    $(document).ready(function() { $().fullscreenrResizer(options); });
    $(window).bind("resize", function() { $().fullscreenrResizer(options); });    
  
    return this;    
  };
  
  $.fn.fullscreenrResizer = function(options) {
    var $img =  $('body > img.fullscreenry:last');
    // Set bg size
    var ratio = options.height / options.width; 
    // Get browser window size
    var browserwidth = $(window).width();
    var browserheight = $(window).height();
    // Scale the image
    if ((browserheight/browserwidth) > ratio){
        $img.height(browserheight);
        $img.width(browserheight / ratio);
    } else {
        $img.width(browserwidth);
        $img.height(browserwidth * ratio);
    }

    // Center the image
    // $(this).css('left', (browserwidth - $(this).width())/2);
    // $(this).css('top', (browserheight - $(this).height())/2);

    return this;    
  };
  
  
})(jQuery);



