var imgCenter = "#taalkeuze_background_image";

var picWidth = 1280;
var picHeight = 900;

jQuery.noConflict();
	(function($) { 
		$(function() {
			$(document).ready(function() {
				$(imgCenter).load(function() {
					// loader verbergen
					$(".loader").css("display", "none");
					
					// image resizen & tonen
					$(imgCenter).fadeIn();
					resizeImage();	
				});
				
				// src van image switchen met rel attribuut, om problemen met het load event te vermijden
				$(imgCenter).attr('src', $(imgCenter).attr('rel'));
				$(imgCenter).attr('rel', '');
			});
			
			$(window).resize(function(){
				resizeImage();
			});
			
			function resizeImage() {
				var navWidth = $(window).width();
				var navHeight = $(window).height();
				var navRatio = navWidth / navHeight;
			
				if ($('.taalkeuze_background_image').width() > 1) picWidth = $('.taalkeuze_background_image').width();
				if ($('.taalkeuze_background_image').height() > 1) picHeight = $('.taalkeuze_background_image').height();
				
				picRatio = picWidth / picHeight;
				
				if (navRatio > picRatio) {
					var newHeight = (navWidth / picWidth) * picHeight;
					var newWidth = navWidth;
				} else {
					var newHeight = navHeight;
					var newWidth = (navHeight / picHeight) * picWidth;
				}
				
				newTop = 0 - ((newHeight - navHeight) / 2);
				newLeft =  0 - ((newWidth - navWidth) / 2);
			
				$('#taalkeuze_image_holder').css({height: navHeight, width: navWidth});
				$('#taalkeuze_image_holder').css({visibility:"visible", display:"block"});
				
				$('.taalkeuze_background_image').css({height: newHeight, width: newWidth});
				
				$(imgCenter).css({top: -20, left: newLeft});
			}
	});
})(jQuery);
