// Document ready events.
$(document).ready(function() {
	form();
	cycle();
	calculateHeight();
	calculateWidth();
});

// Window resize events.
$(window).resize(function() {
	calculateWidth();
});

// Function that calculates the width of the page.
function calculateWidth()
{
	windowWidth 		= $(window).width(); // Window width.
	totalMargin 		= windowWidth-960; // Total margin around countainer.
	
	marginLeft 			= Math.floor(totalMargin/2); // Minus width of container.
	marginRight			= marginLeft // Default the same as marginLeft.

	marginDifference 	= totalMargin-(marginLeft*2); // Incase it's not a round number; calculate the difference.
	
	if (marginDifference > 0) {
		marginRight = marginLeft+marginDifference;
	}
	
	if (marginLeft < 0) {
		$('#container .marginLeft, #container .marginRight').css('display', 'none');
	} else {
		$('#container .marginLeft, #container .marginRight').css('display', 'block');
		
		$('#container .marginLeft').width(marginLeft);
		$('#container .marginRight').width(marginRight);
	}
}

//Function that calculates the height of the page's shadow border.
function calculateHeight() 
{
	// Reset height!
	$('#text, #block4Left, #block4Left, #contentRightExtra').height('auto');
	
	// Set margin.
	margin = 44;
	
	contentHeight 		= $('#text').height()+margin; // + 44 = margin.
	contentHeightExtra 	= $('#contentRightExtra').height(); // + 44 = margin.
	
	// If content height of EXTRA is higher.
	if (contentHeightExtra > contentHeight) {
		contentHeight = contentHeightExtra;
	}

	// If content height is lower then 350px (= min. height). FORCE!
	if (contentHeight < 350) {
		if ($('#text.homepage').length === 0) { // No min-height for homepage.
			contentHeight = 350;
		}
	}

	$('#block4Left').height(contentHeight);
	$('#block4Right').height(contentHeight);
	$('#contentRightExtra').height(contentHeight); // Block next to content.
	$('#text').height(contentHeight-margin) // Actual text.
}

// Function randomly display images.
function cycle()
{
	if ($('#introExtra img').length != false) {;
		$('#introExtra').cycle({
			fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		});
	}
	
	if ($('#footer .logos div').length != false) {;
		$('#footer .logos').cycle({
			fx: 'scrollLeft' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		});
	}
}

function form()
{	
	// Checkbox factuur check.
	$('#fac_check').click(function() {
		if ($('#fac_check:checked').val() !== undefined) {
			$('.displayGroupFactuur').show();
		} else {
			$('.displayGroupFactuur').hide();
		}
		
		calculateHeight(); // Calculate!
		calculateWidth(); 
	});
	
	// Disable if checkbox factuur is NOT checked.
	if ($('#fac_check:checked').val() !== undefined) {
		$('.displayGroupFactuur').show();
	}
	
	
}
