var randomInterval = null;
$(document).ready(function(){
						   
	$('.project').slideshow();
	$('#slideshow').cycle({timeout:4000});
	$('#subslideshow').cycle({timeout:3000});
	$("#menu a").hover(function(){
		leftpos = $(this).offset().left - $("#header").offset().left;
		widthpos = $(this).outerWidth()-4;
		$("#slider").stop().animate({left:leftpos+'px',width:widthpos+'px'})
	},function(){
		leftpos = $("#menu a.active").offset().left - $("#header").offset().left;
		widthpos = $("#menu a.active").outerWidth()-4;
		$("#slider").stop().animate({left:leftpos+'px',width:widthpos+'px'})
	});
	resizeWindow();
	
	leftpos = $("#menu a.active").offset().left - $("#header").offset().left;
	widthpos = $("#menu a.active").outerWidth()-4;
	$("#slider").stop().css({left:leftpos+'px',width:widthpos+'px'})
	
	
	$(".ajaxformulier").each(function(i){
		$(this).unbind('submit').bind('submit',function(e){
			submitAjaxForm($(this));
			e.preventDefault();
		});
	});
	$('.slider a').fancybox();
	
});

function resizeWindow(){
	
//	html = $('#content .scroller').html();
//	$("#content").html('<div class="scroller"></div>');
	//$("#content .scroll").html(html);
	//$('#content').css({width:($(window).width()-80-$("#content").offset().left)+'px',height:($(window).height()-100-$("#content").offset().top)+'px'})
	//$("#contents .scroller").jScrollPane({scrollbarMargin :'20'});
	
	
}

function submitAjaxForm(form){
	var form = form;
	var data = form.serialize();
	var buttonlabel = form.find('input[type=submit]').val();
	form.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: 	form.attr('method'),
		url: 	form.attr('action'),
		data: 	data,
		success: function(msg){
			if(form.attr('target')){
				form.find('input[type=submit]').attr('disabled',false).val(buttonlabel);
				$("#"+form.attr('target')).html(msg);
			}
		},
		error: function(xhr, ajaxOptions, thrownError){
			alert(xhr.status);
			alert(thrownError);
		}
	});
	
	form.find('input[type=submit]').attr('disabled',true).val('Bezig met verzenden..');
	return false;	
}
