google.load("webfont", "1");
google.setOnLoadCallback(function() {
	WebFont.load({
		google: {families: [ 'Copse' ]},
		active: positionMenu
	});
});

$(document).ready(function(){
						   
	$('.menu').hide();
	$('.slideshow').cycle({ 
		timeout:  	5000, 
		speed:  	1000
	}); 
	$('a.meel').each(function(i) {
        var text = $(this).text();
        var address = text.replace(" op ", "@");
        var address = address.replace(" punt ", ".");
        $(this).attr('href', 'mailto:' + address);
		$(this).text(address);
	});
	
	$('.route').maps();
	$("#ajaxformulier:not(.jQueried)").addClass('jQueried').unbind('submit').submit(function(){
		var form = $(this);
		var data = $(this).serialize();
		$(this).find('input, textarea, checkbox, radio, select').each(function(){
			if($(this).attr('title')){
				ar = $(this).attr('name').split('[]');
				naam = ar[0];
				data += '&veldnamen['+encodeURIComponent(naam)+']=' + encodeURIComponent($(this).attr('title'))
			}
		});
		$.ajax({
			type: 	$(this).attr('method'),
			url: 	$(this).attr('action'),
			data: 	data,
			success: function(msg){
				if(form.attr('target')){
					$("#"+form.attr('target')).html(msg);
				}
			},
			error: function(xhr, ajaxOptions, thrownError){
				alert(xhr.status);
				alert(thrownError);
			}
		});
		return false;
	});
	
	$('.movies').each(function(){
		$(this).find('li').bind('click', function(){
			$(this).parent().find('.active').removeClass('active');
			$(this).addClass('active');
			$parent = $(this).parents('.movies:eq(0)');
			$parent.find('iframe').remove();
			$parent.find('.movie').html('<iframe width="100%" height="100%" src="http://www.youtube.com/embed/'+$(this).attr('rel')+'" frameborder="0" allowfullscreen></iframe>')
		});
	});
	
	$(window).bind('resize',function(){
		positionBeeldmerk();
	});
		positionBeeldmerk();
});

function positionBeeldmerk(){
	if($('#subfooter').length > 0){
		$el = $('#subfooter');	
	}else{
		$el = $('#footer');
	}
	posy = $el.position().top - 379;
	
	var rest = ($(window).width() - 900) / 2;
	if(rest > 230){
		posx = 0;
	}else{
		posx = rest - 230;
	}
	$('#beeldmerk').css('left', posx+'px');
	$('#beeldmerk').css('bottom', '');
	$('#beeldmerk').css('top', posy+'px');
}
function positionMenu(){
	$('.menu').show();
	$('.menu').each(function(){
		var $width = 0;
		$(this).find('li').each(function(){
			$width += $(this).outerWidth() + 1;								 
		});
		$(this).css('width',($width)+'px');
	});	
}
