$(document).ready(function(e) {
	setMaxHeight();
	$(window).bind('resize scroll', function() {
		setMaxHeight();
	});
	$('html').bind('scroll', function() {
		setMaxHeight();
	});

    $(function(){
      $("#twitterberichten").tweet({
        avatar_size: 0,
        count: 1,
        username: ["soleilacademy"],
        loading_text: "searching...",
        refresh_interval: 90
      });
    });
	

	$('#simplegallery>div>div>div').jqDock(
		{ 	align: 'bottom',
			size: 80,
			active:2,
			distance: 70,
			labels: false
		}
	);

	
	/************* GALLERY CLICK *************/
	var curr=0;
	
	var simplegallerywidth = $("#simplegallery").width()-39;
	//alert(simplegallerywidth );
	$('#simplegallery .left').click(function(e) {
		$('#simplegallery>div>div').jqDock({active:4});
		$('#simplegallery .container').animate({'left':'+='+simplegallerywidth},{ queue:false, duration:750, easing:"backEaseInOut", complete: function(){
			var left = parseInt($(this).css('left'), 10);
			if(left>=0)
			{
				$(this).css('left', '-1658px');
			}
			
		}});
	});
	$('#simplegallery .right').click(function(e) {
		$('#simplegallery>div>div').jqDock({active:4});
		$('#simplegallery .container').animate({'left':'-='+simplegallerywidth},{ queue:false, duration:750, easing:"backEaseInOut", complete: function(){
			var left = parseInt($(this).css('left'), 10);
			if(left<=-1685)
			{
				$(this).css('left', '-535px');
			}
		}});
	});
	
	/************* GALLERY CLICK END *********/
	
	
	
	/************* BROCHURE AANVRAGEN *************/
	$('.brochureaanvragen').click(function(e) {
		e.preventDefault();
		error = false;
		$('.required').css({"border":"1px solid #9AB","background-color":"white"});
		$('.required').each(function(index, element) {
			if(!$(this).val())
			{
				$(this).css({"border":"1px solid red","background-color":"pink"});
				error = true;
			}
		});
		if(error)
		{
			alert('Vul aub alle roodgemarkeerde velden in');
			return false;
		}
		else
		{
			var email = $('input[name="email"]').val();
			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
			if(!emailReg.test(email)) {
				$('input[name="email"]').css({"border":"1px solid red","background-color":"pink"});
				alert('Vul aub een geldig email adres in');
				error = true;
				return true;
			}
		}
		
		var theForm = $(this).closest('form').serialize();
		$.post('/lib/vacansoleilacademy/brochureversturen.php', theForm ,function(data){
			pageTracker._trackPageview('/brochure/request-confirmed');

			setTimeout(function(){
				window.location.href='/informatie/aanvraag-verstuurd/';
			}
			,500);																				  
		});
	});
	/************* BROCHURE AANVRAGEN END *********/

});


$(window).load(function() {	//start after HTML, images have loaded
	var itemInterval = 5000;
	var fadeTime = 500;
	var numberOfItems = $('.rotating-item').length;
	var currentItem = -1;
 	var InfiniteRotator = 
 	{
 		init: function()
 		{
			$('.rotating-item').eq(currentItem).dequeue();
			$('.rotating-item').eq(currentItem).fadeOut(fadeTime);
			if(currentItem == numberOfItems -1){
				currentItem = 0;
			}else{
				currentItem++;
			}
			var dit = $('.rotating-item').eq(currentItem);
			dit.fadeIn(fadeTime);
			dit.queue(function() {
				setTimeout(function(){
					InfiniteRotator.init();
					dit.dequeue();
				}, itemInterval);
			});
 		}	
 	};
 	InfiniteRotator.init();
});


function setMaxHeight()
{
	$("body, html").css('min-height', $("#menu").height()+'px');
}
