/**
* Fullscreenr - lightweight full screen background jquery plugin
* By Jan Schneiders
* Version 1.0
* www.nanotux.com
**/
(function($){	
	$.fn.fullscreenr = function(options) {
		if(options.height === undefined) alert('Please supply the background image height, default values will now be used. These may be very inaccurate.');
		if(options.width === undefined) alert('Please supply the background image width, default values will now be used. These may be very inaccurate.');
		if(options.bgID === undefined) alert('Please supply the background image ID, default #bgimg will now be used.');
		var defaults = { width: 1280,  height: 1024, bgID: 'bgimg' };
		var options = $.extend({}, defaults, options); 
		$(document).ready(function() { $(options.bgID).fullscreenrResizer(options);	});
		$(window).bind("resize", function() { $(options.bgID).fullscreenrResizer(options); });		
		return this; 		
	};	
	$.fn.fullscreenrResizer = function(options) {
		// Set bg size
		var ratio = options.height / options.width;	
		// Get element size
		var elementwidth = $('#bildrahmen').width();
		var elementheight = $('#bildrahmen').height();
		// Scale the image
		if ((elementheight/elementwidth) > ratio){
		    $(this).height(elementheight);
		    $(this).width(elementheight / ratio);
		} else {
		    $(this).width(elementwidth);
		    $(this).height(elementwidth * ratio);
		}
		// Center the image
		$('#start #bgimg').css('right', (elementwidth - $('#start #bgimg').width())/4);
			$('#start #bgimg').css('top', (elementheight - $('#start #bgimg').height())/3);
		$('#vita #bgimg').css('right', (elementwidth - $('#vita #bgimg').width())/2);
			$('#vita #bgimg').css('top', (elementheight - $('#vita #bgimg').height())/3);
		$('#projekte #bgimg').css('right', (elementwidth - $('#projekte #bgimg').width())/8);
			$('#projekte #bgimg').css('top', '0');
		$('#presse #bgimg').css('right', '0');
			$('#presse #bgimg').css('top', (elementheight - $('#presse #bgimg').height())/4);
		$('#proben #bgimg').css('right', (elementwidth - $('#proben #bgimg').width())/3);
			$('#proben #bgimg').css('top', '0');
		$('#angebot #bgimg').css('right', (elementwidth - $('#angebot #bgimg').width())/2);
			$('#angebot #bgimg').css('top', (elementheight - $('#angebot #bgimg').height())/4);
		$('#kontakt #bgimg').css('right', (elementwidth - $('#kontakt #bgimg').width())/2+20);
			$('#kontakt #bgimg').css('top', '0');
		
		
		//$(this).css('top', (elementheight - $(this).height())/2);
		return this; 		
	};
})(jQuery);
