$(document).ready(function()
{
	var opties = {lang: 'nl'};
	
	MaxWidth 	= 	Math.max(Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
					Math.max(document.body.offsetWidth, document.documentElement.offsetWidth),
					Math.max(document.body.clientWidth, document.documentElement.clientWidth));
	if(MaxWidth > 1000)
	{
		$('.headerslider').css({'width' : MaxWidth});
		$('#logo').css({'margin-left' : (((MaxWidth - 1000) / 2) + 335)});
		$('#headertopmenu').css({'margin-left' : (((MaxWidth - 1000) / 2) + 665)});
		$('#headernav').css({'margin-left' : (((MaxWidth - 1000) / 2) + 450)});
		$('.headershare').css({'margin-left' : (((MaxWidth - 1000) / 2) + 750)});
	}
	else
	{
		$('.headerslider').css({'width' : '1000px'});
		$('#logo').css({'margin-left' : '335px'});
		$('#headertopmenu').css({'margin-left' : '600px'});
		$('#headernav').css({'margin-left' : '450px'});
		$('.headershare').css({'margin-left' : '700px'});
	}
	
	autoSlideTimer = requestTimeout(function()
	{
		autoSlide('rek', 4000);
	}, 4000);
	
	//Slider breedte berekenen
	sliderHWidth = 0;
	$('#rek .headerslider').each(function()
	{
		sliderHWidth += $(this).outerWidth(true);
	});
	
	$('#rek').css({'width' : sliderHWidth});
		
	$('.headersharebutton').mouseenter(function(){
		
		//$(this).css({'display' : 'block'});
		$('#headersharepopup').show();
	});
	
	$('#headersharepopup').mouseleave(function()
	{
		$(this).hide();
	});	
});


$(function() {
	$('#menubg li a').mouseenter(function() {
		var hetid = $(this).attr('id');
		var childs = $('#sub' + hetid + ' ul').children().length;
		
		$('.subnav').not('#sub' + hetid).stop(true).animate({"height":"0px"}, 200);
		
		if(childs > 1)
		{
			$('#sub' + hetid).animate({"height":"56px"}, 200);
		}
	});
	
	$('.subnav').mouseleave(function() {
		$(this).stop(true).animate({"height":"0px"}, 200);
	});
});


function autoSlide(ele, time)
{
	if(time == '' || time == 0)
	{
		var time = 3000; //default time
	}
	
	$('#'+ ele).parent().find('div:last a').each(function()
	{
		$(this).removeClass();
	});
	
	var mrg 			= 	parseInt($('.headerslider').css('width')); 	// 1 slide = 900 pixels
	var mSlides 		= 	$('#'+ ele + ' > div').size(); 				// 6 slides
	//var mMrg 			= 	(mSlides - 1) * mrg; 						// 6 * 900 = 5400
	var cMrg 			= 	parseInt($('#'+ ele).css('marginLeft')); 	// 0
	var cSlide 			= 	1 + (cMrg / -mrg);							// 1 + (0 / -900) = 1e slide

	if(cSlide < mSlides)
	{
		$('#headernav a').removeClass();
		$('a#cirkel_' + (cSlide + 1)).removeClass().addClass('active');
		$('#'+ ele).animate({ marginLeft : '-='+mrg}, 600);
	} 
	else
	{
		$('#'+ ele).css({ marginLeft : 0});
		$('#headernav a').removeClass();
		$('a#cirkel_1').removeClass().addClass('active');
	}

	autoSlideTimer = requestTimeout(function()
	{
		autoSlide(ele, time);
	}, time);
}

function closeShare(e)
{
	$(e).parent().slideUp('slow');
}


//headerslider
function schuif(id)
{
	clearRequestTimeout(autoSlideTimer);
	
	var mrg = parseInt($('.headerslider').css('width')) + (id * -parseInt($('.headerslider').css('width')));
	$('#rek').animate({marginLeft : mrg}, 1200, function()
	{
		$('#headernav ul li a').removeClass();
		$('#cirkel_'+id).addClass("active");
		
		autoSlideTimer = requestTimeout(function()
		{
			autoSlide('rek', 4000);
		}, 4000);
	});
}

