/**
 * Fullscreenr - lightweight full screen background jquery plugin
 * By Jan Schneiders
 * Version 1.0
 * www.nanotux.com
 *
 * modified by nicolas massouh 
 **/
(function($) {
	$.fn.fullscreenr = function(options) {
		var defaults = {
			width : 1172,
			height : 760,
			bgID : 'bgimg'
		};
		var options = $.extend(defaults, options);
		$(document).ready(function() {
			$(options.bgID).fullscreenrResizer(options);
		});
		$(window).resize(function(){
			$(options.bgID).fullscreenrResizer(options);
		});
		
		return this;
	};
	$.fn.fullscreenrResizer = function(options) {
		
		var win = $(window);
		var $el = $(this);
		
		// Set Size
		var ratioImg = options.width / options.height;
		
		// Get browser window size
		var browserWidth = win.width();
		var browserHeight = win.height();
		var ratio = browserWidth / browserHeight; 
		
		if(ratio > ratioImg) { 
			$el.width(browserWidth);
			$el.height(browserWidth / ratioImg);
		}else{
			$el.width(browserHeight * ratioImg);
			$el.height(browserHeight);
		}
		
		// Center the image
		$el.css('left', ((browserWidth - $el.width()) / 2));
		$el.css('top', ((browserHeight - $el.height()) / 2));
		//$el.css('position', 'fixed');
		return this;
	};
})(jQuery);

