var homeSliderIndex = 0;
var homeSliderTimeout = 0;
$(document).ready(function(){

  setTimeout(fixFooterHeight, 500);
  $(window).resize(fixFooterHeight);

	//Openen van de homeblokken
	var open_blok_home = 1;
	
	if($('#chatImage').length < 1) {
    $("#flash_home").show("slide",{ direction: "left" }, 500);
    $("#flash_home div[rel=\""+open_blok_home+"\"]").next(".homeblok_image_overlay").animate({bottom:'0px'}, 300);
  }
  if($('#home_slider #home_slider_holder').length > 0) {
    homeSliderTimeout = setTimeout(moveSlider, 5000);
    $('#home_slider #home_slider_numbers div').click(function() {
      clearTimeout(homeSliderTimeout);
      homeSliderIndex = $('#home_slider #home_slider_numbers div').index(this) - 1;
      moveSlider();
    });
  }
	
	$("#flash_home .mini").css("width","80px");
	$("#flash_home .homeblok_mini_overlay").live('click', function(){	
		var open_blok_home_temp = open_blok_home;
		$("#flash_home div[rel=\""+open_blok_home+"\"]").next(".homeblok_image_overlay").animate({bottom:'-200px'}, 300);
		$("#flash_home div[rel=\""+open_blok_home+"\"]").parents(".homeblok").animate({width:'80px'}, 600, function(){
			$("#flash_home div[rel=\""+open_blok_home_temp+"\"]").addClass("homeblok_mini_overlay");
			$("#flash_home div[rel=\""+open_blok_home_temp+"\"]").removeClass("homeblok_overlay");
			
		});
		var oud_blok_dicht = $(this).attr("rel");	
		$("#flash_home div[rel=\""+oud_blok_dicht+"\"]").parents(".homeblok").animate({width:'740px'}, 600); 
		$("#flash_home div[rel=\""+oud_blok_dicht+"\"]").next(".homeblok_image_overlay").animate({bottom:'0px'}, 300);
		$("#flash_home div[rel=\""+oud_blok_dicht+"\"]").removeClass("homeblok_mini_overlay");
		$("#flash_home div[rel=\""+oud_blok_dicht+"\"]").addClass("homeblok_overlay");
		open_blok_home = $(this).attr("rel");		
	});
	
	//Link volgen van een homeblok
	$("#flash_home .homeblok_overlay").live('click', function(){
		if($(this).attr("href")!=""){ window.location.replace($(this).attr("href")); }
	});
	
	//Link volgen van een miniblokje
	$(".miniblok_overlay").live('click', function(){
		if($(this).attr("href")!=""){ window.location.replace($(this).attr("href")); }
	});
	
	//Animeren van de kleurblokken
	$(".miniblok_1").mouseover(function(){$(this).stop().animate({"backgroundColor":"#006bb3" }, 600);}).mouseout(function(){$(this).stop().animate({"backgroundColor":"#0099ff" }, 600);});	
	$(".miniblok_2").mouseover(function(){$(this).stop().animate({"backgroundColor":"#801320" }, 600);}).mouseout(function(){$(this).stop().animate({"backgroundColor":"#d11a30" }, 600);});	
	$(".miniblok_3").mouseover(function(){$(this).stop().animate({"backgroundColor":"#ad6d05" }, 600);}).mouseout(function(){$(this).stop().animate({"backgroundColor":"#fb9c07" }, 600);});	
	
	//Werking van het hoofdmenu
	$("#flash_menu ul li a").mouseover(function(){				
		$(this).stop().animate({"marginTop":"-40px" }, 200);
	}).mouseout(function(){		
		$(this).stop().animate({"marginTop":"0px" }, 200);
	});	
		
	//Verkleuren en groter worden van een opleidingscategorie bij een hover
	$(".flash_opleidingen>ul.menu>li>a").mouseover(function(){				
		$(this).stop().animate({"color":"#fff","fontSize":"20px"}, 50);
		$(this).children("img").stop().animate({"left":"-10px"}, 100);
	}).mouseout(function(){	
		if(!$(this).hasClass("actief")){
			$(this).stop().animate({"color":"#000","fontSize":"18px"}, 500);
			$(this).children("img").stop().animate({"left":"-40px"}, 500);
		}
	});	
	
	$(".flash_opleidingen>ul.submenu>li>a").mouseover(function(){				
		$(this).stop().animate({"fontSize":"20px"}, 50);
		$(this).children("img").stop().animate({"left":"-10px"}, 100);
	}).mouseout(function(){		
		$(this).stop().animate({"fontSize":"18px"}, 500);
		$(this).children("img").stop().animate({"left":"-40px"}, 500);
	});	
	
	$(".flash_opleidingen>ul.menu>li>a").click(function(ev){		
		ev.preventDefault();
		$(".opleidingen_image").stop().animate({"right":"-500px"}, 350);
		$(".opleidingen_image[rel=\""+$(this).attr("rel")+"\"]").stop().animate({"right":"0px"}, 350);
		$(".flash_opleidingen>ul.menu>li>a.actief").stop().animate({"color":"#000","fontSize":"18px"}, 500);
		$(".flash_opleidingen>ul.menu>li>a.actief").children("img").stop().animate({"left":"-40px"}, 500);
		$(".flash_opleidingen>ul.menu>li>a.actief").removeClass("actief");
		$(this).addClass("actief");		
		$(".flash_opleidingen>ul.submenu").stop().animate({"left":"-200px"}, 300);
		$(".flash_opleidingen>ul.submenu[rel=\""+$(this).attr("rel")+"\"]").stop().animate({"left":"200px"}, 150);
	})	
		
	
		
		
	$("#newsletter a, #callmeback a, #offerteaanvraag a, #tellafriend a, #snelcontact a").click(function(event){
	  if($(this).next('div').hasClass('active')){
		$(this).next('div').removeClass('active').slideUp('fast');
	  }else{
		$(this).next('div').addClass('active').slideDown('fast');
	  }
		event.preventDefault();
		
	});
	$("#newsletter form input[type=text],#callmeback form input[type=text], #offerteaanvraag form input[type=text], #tellafriend form input[type=text], #tellafriend form textarea, #snelcontact form input[type=text], #snelcontact form textarea").blur(function(){
		if(!$(this).val()){
			$(this).val($(this).attr('default'));	
		}
	});
	$("#newsletter form input[type=text],#callmeback form input[type=text], #offerteaanvraag form input[type=text], #tellafriend form input[type=text], #tellafriend form textarea, #snelcontact form input[type=text], #snelcontact form textarea").focus(function(){
		if(!$(this).attr('default')) $(this).attr('default',$(this).val());
		if($(this).attr('default') == $(this).val()){
			$(this).val('');	
		}
	});
	
	$("#callmeback form,#offerteaanvraag form,#tellafriend form,#snelcontact form").submit(function(event){
		$("#callmeback form input[type=text],#offerteaanvraag form input[type=text],#tellafriend form input[type=text], #tellafriend form textarea, #snelcontact form input[type=text], #snelcontact form textarea").each(function(){
			if(!$(this).attr('default')) $(this).attr('default',$(this).val());
			if($(this).val() == $(this).attr('default')){
				$(this).val('');	
			}
		});
		var form = $(this);
		$.ajax({
			type: 	form.attr('method'),
			url: 	form.attr('action'),
			data: 	form.serialize(),
			success: function(msg){
				$("#"+form.attr('target')).html(msg);
			}
		});	
		
		$("#newsletter form input[type=text],#callmeback form input[type=text],#offerteaanvraag form input[type=text],#tellafriend form input[type=text], #tellafriend form textarea, #snelcontact form input[type=text], #snelcontact form textarea").each(function(){
			if(!$(this).val()){
				$(this).val($(this).attr('default'));	
			}
		});
		event.preventDefault();
	});	
	
	$('.minialbum').css({height:($('.minialbum').height()+70)+'px'});
	$('.minialbum a').each(function(){
		$(this).css({left:$(this).position().left,top:$(this).position().top});
		$(this).hover(function(){
			clearInterval(minialbumTimeout);
			miniAlbumShow($(this));	
		},function(){
			miniAlbumHide($(this));
			startRandomMini();
		});
	});
	$('.minialbum a').css({position:'absolute'});
	startRandomMini();
	
	
	$(".minialbum a[href$=.jpg]").fancybox({
		'titleFormat'	: function(title, currentArray, currentIndex, currentOpts){
			el = $('.minialbum a[href$=.jpg]:eq('+currentIndex+')');
			if(currentIndex == 0){
				nav = 	'<a href="javascript:;" onclick="$.fancybox.next();">volgende</a>';
			}else if(currentIndex == currentArray.length-1){
				nav = 	'<a href="javascript:;" onclick="$.fancybox.prev();">vorige</a>';
			}else{
				nav = 	'<a href="javascript:;" onclick="$.fancybox.prev();">vorige</a> - <a href="javascript:;" onclick="$.fancybox.next();">volgende</a>';
			}
			return('<div class="customtitle">'+
						'<a href="javascript:;" onclick="$.fancybox.close();">sluiten</a>' +
						'<div>Foto '+(currentIndex+1)+' van '+currentArray.length+
						'<br />' + nav+'</div>' +
						'<strong>' + el.attr('titel') + '</strong>'+
				   '</div>');
		},
		'overlayShow'		: true,
		'overlayColor'		: '000',
		'padding'			: 0,
		'overlayOpacity'	: 0.8
	});
	
	
	$("#twitter").gosiTwitter({userName: "osseforth", numTweets: 10, loaderText: "Loading tweets..."});
	
	$(".faq_kop_ov").click(function(){
		$(this).parents('div:first').slideUp('fast');
		$(this).parents('div:first').next().slideDown('fast');
	})
	$(".slideopen > div").click(function(){
		$(this).parent().slideUp('fast');
		$(this).parent().prev().slideDown('fast');
	})
});
function moveSlider() {
  homeSliderIndex++;
  if(homeSliderIndex > 2) { homeSliderIndex = 0; }
  $('#home_slider #home_slider_numbers div').removeClass('active');
  $('#home_slider #home_slider_numbers div').eq(homeSliderIndex).addClass('active');
  $('#home_slider #home_slider_holder').animate({left:(0 - homeSliderIndex * 391) + 'px'}, 300);
  homeSliderTimeout = setTimeout(moveSlider, 5000);
}
function fixFooterHeight() {
  if($(window).height() > $('body').height()) {
    $('#footer').css('height', ($(window).height() - $('body').height() + $('#footer').height()) + 'px');
  } else {
    $('#footer').att('style', '');
  }
}
var minialbumTimeout = null;
var zIndexer = 10;
function startRandomMini(){
	clearInterval(minialbumTimeout);
	minialbumTimeout = setInterval(function(){ randomMini(); },2000);
}

function randomMini(){
	var randomnumber=Math.floor(Math.random()*($('.minialbum a').length+1));
	miniAlbumShow($('.minialbum a:eq('+randomnumber+')'));
	setTimeout(function(){
		miniAlbumHide($('.minialbum a:eq('+randomnumber+')')); 
	},1000);
}
function miniAlbumShow(el){
	zIndexer++;
	el.css({'zIndex':zIndexer});
	marginLeft = '0px';
	marginTop = '0px';
	if((el.index()+1)%3 == 0){
		marginLeft = '-60px';
	}
	
	if(($('.minialbum a').length%3) == 0 && el.index() >= $('.minialbum a').length-3){
		marginTop = '-60px';		
	}else if(el.index() >= $('.minialbum a').length - ($('.minialbum a').length%3)){
		marginTop = '-60px';
	}
	el.stop().animate({marginLeft:marginLeft, marginTop:marginTop, width:'115px',height:'115px'},500);
}
function miniAlbumHide(el){
	el.stop().animate({marginTop:'0px',marginLeft:'0px',width:'55px',height:'55px'},500);
}
