/**
* Fullscreenr - lightweight full screen background jquery plugin
* By Jan Schneiders
* Version 1.0
* www.nanotux.com
* Modified by Amphebia
**/
(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 browser window size
		var browserwidth = $(window).width();
		var browserheight = $(window).height();
		
		// Scale the image
		if ((browserheight/browserwidth) > ratio){
		    $(this).height(browserheight);
		    $(this).width(browserheight / ratio);
		} else {
		    $(this).width(browserwidth);
		    $(this).height(browserwidth * ratio);
		}
		intScale = ($(this).width() / options.width);
		
		// Center the image
		$(this).css('left', (browserwidth - $(this).width())/2);
		//$(this).css('bottom', (browserheight - $(this).height())/2);
		$(this).css('top', 0);

		objMainImg = $(this);
		$('IMG.backgroundimage').css('width', objMainImg.css('width')).css('height', objMainImg.css('height')).css('left', objMainImg.css('left')).css('top', 0);
		
		// x, y, width, height
		objPos = objMainImg.position();
		arrEngOrig = [698, 36, 58, 18];
		arrEngNew = [(objPos.left + Math.round(intScale * arrEngOrig[0])),Math.round(intScale * arrEngOrig[1]),Math.round(intScale * arrEngOrig[2]),Math.round(intScale * arrEngOrig[3])];
		arrDEOrig = [758, 36, 63, 18];
		arrDENew = [(objPos.left + Math.round(intScale * arrDEOrig[0])),Math.round(intScale * arrDEOrig[1]),Math.round(intScale * arrDEOrig[2]),Math.round(intScale * arrDEOrig[3])];
		arrNLOrig = [826, 36, 88, 18];
		arrNLNew = [(objPos.left + Math.round(intScale * arrNLOrig[0])),Math.round(intScale * arrNLOrig[1]),Math.round(intScale * arrNLOrig[2]),Math.round(intScale * arrNLOrig[3])];
		$('DIV#dvEnglish').css('width', arrEngNew[2]).css('height', arrEngNew[3]).css('left', arrEngNew[0]).css('top', arrEngNew[1]);
		$('DIV#dvDeutsch').css('width', arrDENew[2]).css('height', arrDENew[3]).css('left', arrDENew[0]).css('top', arrDENew[1]);
		$('DIV#dvNL').css('width', arrNLNew[2]).css('height', arrNLNew[3]).css('left', arrNLNew[0]).css('top', arrNLNew[1]);
		return this;
	};
})(jQuery);

