var left_offset;
var left_width;
var content_offset;
var content_height;
var right_offset;
var right_width;
var recept_van_offset;
var recept_van_width;

// On load
$(window).load(function() {
	
	// Get the current offsets en dimensions
	left_offset = $('#left').offset();
	left_width = $('#left').width();
	content_offset = $('#content').offset();
	content_height = $('#content').height() + 25;
	right_offset = $('#right').offset();
	right_width = $('#right').width();
	recept_van_offset = $('#het_recept_van').offset();
	recept_van_width = $('#het_recept_van').width();
	
	$('#container_shadow').css({
		'left': left_offset.left,
		'height': getDocHeight() - 615
	});
	
	// Create left content shadow
	$('<div/>',	{
		'id': 'left_shadow'
	}).css({
		'top': left_offset.top,
		'left': (left_offset.left + left_width) + 8,
		'height': content_height + 15
	}).appendTo('#left');
	
	// Create right content shadow
	$('<div/>',	{
		'id': 'right_shadow'
	}).css({
		'top': left_offset.top,
		'left': right_offset.left + 2,
		'height': content_height + 15
	}).appendTo('#right');
	
	// Create content bottom shadow
	$('<div/>', {
		'id': 'content_bottom_shadow'
	}).css({
		'top': (content_offset.top + content_height) - 15,
		'left': content_offset.left - 35
	}).appendTo('body');
	
	// Positioning the banners (right)
	$('#banners_right').css({
		'top': recept_van_offset.top,
		'left': (recept_van_offset.left + recept_van_width) + 35
	});
	
	// Apply stylish select boxes
	$('.stylish_select').sSelect();
	
	// Init menu
	initmenu();
	
	// Logo link
	$('#logo').click(function() {
		$(location).attr('href', BASE_URL+'nl');
	});
	
});

// On resize
$(window).resize(function() {
	
	// Get the current offsets and dimensions
	left_offset = $('#left').offset();
	left_width = $('#left').width();
	content_offset = $('#content').offset();
	content_height = $('#content').height() + 25;
	right_offset = $('#right').offset();
	right_width = $('#right').width();
	recept_van_offset = $('#het_recept_van').offset();
	recept_van_width = $('#het_recept_van').width();
	
	// Update the style
	$('#container_shadow').css({
		'left': left_offset.left
	});
	
	// Update the style
	$('#left_shadow').css({
		'left': (left_offset.left + left_width) + 8
	});
	
	// Update the style
	$('#right_shadow').css({
		'left': right_offset.left + 2
	});
	
	// Update the style
	$('#content_bottom_shadow').css({
		'left': content_offset.left - 35
	});
	
	// Update the style
	$('#banners_right').css({
		'left': (recept_van_offset.left + recept_van_width) + 35
	});
});

// Get document height
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)
	);
}

function get_diersoort_verkooppunten(e, ajax_base_url)
{
	var pid = $(e).attr('id');
	
	$('.provincie_verkooppunten').hide();
	
	$.get(ajax_base_url+'/pid,'+pid, function(data) {
		
		$('#provincie_verkooppunten_'+pid)
		.html(data)
		.show(0, function() {
		
			content_offset = $('#content').offset();
			content_height = $('#content').height() + 25;
			
			offset = $('#page_end').offset();
			
			$('#content_bottom_shadow').css({
				'top': offset.top+10
			});
			
			$('#left_shadow').css({
				'height': content_height + 20
			});
			
			$('#right_shadow').css({
				'height': content_height + 20
			});
			
		});
		
	});
}

function get_vleessoort_verkooppunten(e, ajax_base_url)
{
	var pid = $(e).attr('id');
	
	$('.provincie_verkooppunten').hide();
	
	$.get(ajax_base_url+'/pid,'+pid, function(data) {
		
		$('#provincie_verkooppunten_'+pid)
		.html(data)
		.show(0, function() {
			
			content_offset = $('#content').offset();
			content_height = $('#content').height() + 25;
			
			offset = $('#page_end').offset();
			
			$('#content_bottom_shadow').css({
				'top': offset.top+10
			});
			
			$('#left_shadow').css({
				'height': content_height + 20
			});
			
			$('#right_shadow').css({
				'height': content_height + 20
			});
			
		});
		
	});
	
}

function show_vleessoorten_popup(e)
{
	var theClass = e.className.split(' ');
		theClass = theClass[0];
	
	$('.vleessoorten_popup').remove();
	
	popup_offset = $('#wildbereiden_'+theClass).offset();
	
	$popup = $('<div/>',	{
		'class': 'vleessoorten_popup',
		'id': 'vleessoorten_popup_'+theClass
	}).css({
		'position': 'absolute',
		'top': popup_offset.top,
		'left': (popup_offset.left + $('#wildbereiden_'+theClass).width()) + 10,
		'width': '160px',
		'z-index': 10000,
		'padding': '10px 20px 10px 20px',
		'display': 'none'
	})
	.text('Bezig met laden..')
	.appendTo('body');
	
	$.get($('#wildbereiden_'+theClass).attr('href'), function(data) {
		$('#vleessoorten_popup_'+theClass).html(data);
		$popup.fadeIn(300);
	});
}

function checkPass(form)
{
	if(form.f_password.value.length >= 6 && form.f_password.value == form.f_password2.value)
		return true;
	else
	{
		alert('Uw nieuwe wachtwoord dient minimaal 6 tekens te bevatten en u dient deze ter controle te herhalen.');
		return false;
	}
}

function checkSearch(form)
{
	return true;
}

Array.prototype.in_array = function (element) 
{
  var retur = false;
  for (var values in this) 
  {
	if (this[values] == element) 
	{
	  retur = true;
	  break;
	}  
  }
  return retur;
};

// 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+$/,"");
};


