$(function() {
	setBackground();
	$(window).resize(function() { setBackground(); });
	
	$('#nieuwsnaam').bind('focus',function() {
		
		if($(this).val() == 'uw naam') {
			$(this).val('').css({color:'#2a2a2a'});	
		}
		
	});
	
	$('#nieuwsnaam').bind('blur',function() {
		if($(this).val() == '' || $(this).val() == 'uw naam') {
			$(this).val('uw naam').css({color:'#BBB'});
		}
	});
	
	$('#emailadres').bind('focus',function() {
		
		if($(this).val() == 'uw e-mailadres') {
			$(this).val('').css({color:'#2a2a2a'});	
		}
		
	});
	
	$('#emailadres').bind('blur',function() {
		if($(this).val() == '' || $(this).val() == 'uw e-mailadres') {
			$(this).val('uw e-mailadres').css({color:'#BBB'});
		}
	});
});

function setBackground() {
	imageWidth 	= $('#background img').width();
	imageHeight	= $('#background img').height();
	windowWidth	= $(window).width();
	windowHeight= $(window).height();
	ratioView	= windowWidth / windowHeight;
	
	ratioWidth	= windowWidth / imageWidth;
	ratioHeight	= windowHeight / imageHeight;
	
	if(ratioWidth > 1 || ratioHeight > 1) {
		if(ratioWidth > 1 && ratioHeight > 1) {
		// Both ratiWidth AND ratioHeight bigger then 1
			if(ratioWidth > ratioHeight) {
				newHeight 	= imageHeight * ratioWidth;
				newWidth	= imageWidth * ratioWidth;
				$('#background img').css({height:newHeight,width:newWidth});
			} else {
				newHeight 	= imageHeight * ratioHeight;
				newWidth	= imageWidth * ratioHeight;
				$('#background img').css({height:newHeight,width:newWidth});
			}
		} else if(ratioWidth > 1) {
		// Ratio width is bigger ratioheight NOT
		newHeight 	= imageHeight * ratioWidth;
		newWidth	= imageWidth * ratioWidth;
		$('#background img').css({height:newHeight,width:newWidth});
		} else {
		// Ratio height bigger than 1
		newHeight 	= imageHeight * ratioHeight;
		newWidth	= imageWidth * ratioHeight;
		$('#background img').css({height:newHeight,width:newWidth});
		}
	} else if(ratioWidth > ratioHeight) {
	// RatioWidth bigger than ratioHeight but under 1
	newHeight 	= imageHeight * ratioWidth;
	newWidth	= imageWidth * ratioWidth;
	$('#background img').css({height:newHeight,width:newWidth});
	} else {
	// RatioHeight bigger than RatioWidth but under 1
	newHeight 	= imageHeight * ratioHeight;
	newWidth	= imageWidth * ratioHeight;
	$('#background img').css({height:newHeight,width:newWidth});
	}
}
