(function($) {
	jQuery.fn.kBgFloat = function(options) {
		var defaults = {
			duration: 400,
			position: 'fixed'
		};
		var options = $.extend(defaults, options);
		return $(this).each(function(el) {
			var el = $(this);
			if(el.parent().is('body')) {
				el.parent().css({margin: 0});
				el.css({float: 'left', position: 'absolute', display: 'none'}).wrap('<div></div>');
				$(window).bind('load', function() {
					action(el, 1);
				});
				$(window).bind('resize', function() {
					action(el);
				});
				function action(img, fade) {
					var vp_width = ($(window).width() > $('body').width()) ? $(window).width() : $('body').width();
					var vp_height = ($(window).height() > $('body').height()) ? $(window).height() : $('body').height();
					var el_width = $(img).width();
					var el_height = $(img).height();
					$(img).css({left: 'auto', marginLeft: 0, width: vp_width+'px', height: 'auto'}).parent().css({position: options.position, zIndex: '-2', top: 0, left: 0, width: '100%', height: vp_height+'px', overflow: 'hidden'});
					if(fade) {
						$(img).css({display: 'none', visibility: 'visible'}).fadeIn(options.duration);
					}
					if($(img).height() < vp_height) {
						$(img).css({left: '50%', marginLeft: '-'+$(img).width()/2+'px', width: 'auto', height: vp_height+'px'});
						// -> call margin again
						$(img).css({marginLeft: '-'+$(img).width()/2+'px'});
						// <-
					}
				}
			}
		});
	};
})(jQuery);
