$(document).ready(function() {
    $('ul#contentImage').innerfade({
		speed: "slow",
		timeout: 4000,
		type: "random_start",
		animationtype: "fade"
	});
	
	$('#gallery a').lightBox();
	$('#promotie_afbeelding a').lightBox();
	$('#showroomPicture a').lightBox();
 
	// Floating box
	var $floatingbox = $('#cta-container');
	
	if($('#content').length > 0){
		var bodyY = parseInt($('#content').offset().top) - 100;
		var originalX = $floatingbox.css('margin-left');
		
		$(window).scroll(function () {
			var scrollY = $(window).scrollTop();
			var isfixed = $floatingbox.css('position') == 'fixed';
			
			if($floatingbox.length > 0) {
				
				if (scrollY > bodyY && !isfixed) {
					$floatingbox.stop().css({
			  			position: 'fixed',
			  			left: '50%',
			  			top: 0,
			  			marginLeft: -480
					});
					
					$floatingbox.addClass("isfixed");
				
				} else if (scrollY < bodyY && isfixed) {
					$floatingbox.css({
			  			position: 'relative',
			  			left: 0,
			  			top: 0,
			  			marginLeft: originalX
					});
					
			  		$floatingbox.removeClass("isfixed");
				}		
			}
		});
	}
});
