var menuOffset;
var menuHeight;
var logo_offset;
var logo_width;

$(window).load(function() { //Replaced line [sander @ 25/08/10] org: $(document).ready(function() {
	
	logo_offset = $('#logo').offset();
	logo_width = $('#logo').width();
	
	menu_height = $('#menu').height();
	menu_bottom_height = $('#menu_bottom').height();
	
	$('#content_middle').css({
		'min-height': ((menu_height + menu_bottom_height) + 125)
		//'min-height': ((menu_height + menu_bottom_height) - 60)
	});
	
	$('#menu_wrapper').height(
		$('#menu').height() - 55
	);
		
	var menu_under_offset = $('#under_menu').offset();
	var content_corner_bottom_offset = $('#content_corner_bottom').offset();
	
	menu_under_height = content_corner_bottom_offset.top - menu_under_offset.top;

	$('#under_menu').height( menu_under_height + 6 );
	
	set_menu_offset();
	
	/*
	$('#menu_wrapper').height(
		$('#menu').height() - 55
	);
	
	menu_height = $('#menu').height();
	menu_bottom_height = $('#menu_bottom').height();
	
	$('#content_middle').css({
		'min-height': ((menu_height + menu_bottom_height) - 60)
	});
	*/
	
	/*
	content_middle_height = $('#content_middle').height() - 384;
	
	menu_height = $('#menu').height();
	menu_bottom_height = $('#menu_bottom').height();
	
	$('#content_middle').css({
		'min-height': ((menu_height + menu_bottom_height) - 58)
	});
	
	resize_grey_container();
	set_menu_offset();
	*/
	
	
	/* Menu hovers */
	$('#menu #middle ul li a.menu_level0')
		.mouseenter(function() { 
			
			currentLink = $(this);
			topOffset = currentLink.offset();
			menuOffset = $('#menu').offset();
		
			$('#menu_left_outer #hover').
				show().
				css({
					top: topOffset.top - 149,
					width: menuOffset.left + 9,
					height: currentLink.height() + 4
				});
		
		})
		.mouseleave(function() {
			
			$('#menu_left_outer #hover').hide();
			
		});
	
	/* Active menu */
	if($('#menu #middle ul li a').is('.menu_level0_on'))
	{
		activeLink = $('#menu #middle ul li a.menu_level0_on');
		topOffset = activeLink.offset();
		menuOffset = $('#menu').offset();
		
		$('#menu_left_active').css({
			'display' : 'block',
			'top': topOffset.top,
			'width': menuOffset.left,
			'height': activeLink.height() + 4
		});
	}
	
	
	$('#logo').click(function() { $(location).attr('href', BASE_URL); });
	
	$('.stylish_select').sSelect();
						   
	$('#grey_container').height( getDocHeight() + 10 );
	
	// Positioning the banners (right)
	$('#banners_right').css({
		'left': (logo_offset.left + logo_width) + 25
	});
	
	$('#menu #middle ul li:last-child').addClass('last');
	
	$('.rounded_link').corner();
	
	$('#menu_bottom')
		.append(
			$('<div />')
				.css({
					'width': '160px',
					'text-align': 'right',
					'padding-top': '75px'
				})
				.append(
					$('<div />')
						.css({
							'cursor': 'pointer'
						})
						.click(function() {
							window.open('http://twitter.com/#!/poeliernl')
						})
						.append(
							$('<img />')
								.attr({
									'src': BASE_URL+'images/layout/volg_ons_op_twitter.jpg'
								})
								.css({
									'margin-bottom': '5px'
								})
						)
						.append(
							$('<img />')
								.attr({
									'src': BASE_URL+'images/layout/twitter.png'
								})
						)
				)
		);
	
});

$(window).resize(function() {
	
	menuOffset = $('#menu').offset();
	logo_offset = $('#logo').offset();
	logo_width = $('#logo').width();
	
	//resize_grey_container();
	//set_menu_offset();
	
	// Update the styles
	$("#menu_left_outer").css({
		width: menuOffset.left
	});
	
	$('#menu_left_active').css({
		'width': menuOffset.left
	});
	
	// Update the styles
	$('#banners_right').css({
		'left': (logo_offset.left + logo_width) + 25
	});
	
});

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

var resize_grey_container = function() {

	$('#grey_container').height(
		$(document).height()
	);
	
	$('#grey').height(
		$(document).height()
	);

}

var set_menu_offset = function() {
	
	menuOffset = $('#menu').offset();
	menuHeight = $('#menu').height();
	
	$("#menu_left_outer").css({
		top: menuOffset.top,
		width: menuOffset.left,
		height: menuHeight + 19
	});
	
}

var do_search = function(href, terms) {
	
	var url = href + terms;
	$(location).attr('href', url);
	
	return false;
}

// Trim functions
function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
};
function ltrim(stringToTrim)
{
	return stringToTrim.replace(/^\s+/,"");
};
function rtrim(stringToTrim)
{
	return stringToTrim.replace(/\s+$/,"");
};

function checkInput2()
{

	var doErr = false;
	var errMsg = 'U dient de volgende velden te corrigeren;\n\n';
	
	if(trim($('#f_achternaam').val()).length == 0)
	{
		doErr = true;
		errMsg += '- Achternaam\n';
	}
	if(trim($('#f_voorletters').val()).length == 0)
	{
		doErr = true;
		errMsg += '- Voorletters\n';
	}
	if(trim($('#f_voornaam').val()).length == 0)
	{
		doErr = true;
		errMsg += '- Voornaam\n';
	}
		if(trim($('#f_straat').val()).length == 0)
	{
		doErr = true;
		errMsg += '- Straat\n';
	}
	if(trim($('#f_huisnummer').val()).length == 0)
	{
		doErr = true;
		errMsg += '- Huisnummer\n';
	}
	if(trim($('#f_postcode').val()).length == 0)
	{
		doErr = true;
		errMsg += '- Postcode\n';
	}
	if(trim($('#f_woonplaats').val()).length == 0)
	{
		doErr = true;
		errMsg += '- Woonplaats\n';
	}
	if(trim($('#f_emailadres').val()).length == 0)
	{
		doErr = true;
		errMsg += '- E-mailadres\n';
	}
	if(trim($('#f_naam_recept').val()).length == 0)
	{
		doErr = true;
		errMsg += '- Naam recept\n';
	}
	if(trim($('#f_ingredienten').val()).length == 0)
	{
		doErr = true;
		errMsg += '- Ingredienten\n';
	}	
	if(trim($('#f_bereidingswijze').val()).length == 0)
	{
		doErr = true;
		errMsg += '- Bereidingswijze\n';
	}		
		
	if(doErr)
	{
		alert(errMsg);
		return false;
		
	}
	
	return true;
};


