

// JQUERY CUSTOM COMMANDS
$(document).ready( function() {  // start javascript when document is loaded
	
	
	
	 // fancy box - startup
	 fancyBox_images();
	 
	 //for header animation - startup
	 var headAnimation = new HeaderAnimation();
	
	 
	 // faq module
	 $("#faq_list_a").accordion({ 
	    autoheight: false 
	 });
	 
	 
	// validate the comment form when it is submitted
	// -jquery.validation-
	$("#test_je_zelf_form").validate();
	$("#stel_je_vraag_form").validate();	
	 
	
	
	// A IMG HOVERS
	// HOVER
	var hoverStateButtonsAnimating = false;		
	$('a img:not(.picture_big a img)').mouseover(function() {			
		if (!hoverStateButtonsAnimating) {
			$(this).fadeTo(100, 0.75); 		//SET
			hoverStateButtonsAnimating = true;
		}
	});	
	// UNHOVER
	$("a img").mouseleave(function() {			
		$(this).fadeTo(100, 1.00).queue(function() { 	//RESET
			hoverStateButtonsAnimating = false; $(this).dequeue(); 	
		});		
	}); 
	
	
	//fix voor IE8 het kaartje met image maps bij - hulp en advies
	$(".sidebar_adressen_kaart .img_map_holder .top_click a").fadeTo(10,0);
	
	
	
   
}); // end ready function







//color changer function, controlleble with a links
function swapStylesheet(scheme) {
	
	
	
	if ($.browser.msie) {		
		location.reload(true);
	}
	$.cookie('styleScheme', scheme, {path: '/'});
	
	$('#mainStyle').attr('href', $('#mainStyle').attr('href').replace(/\?.*/, '') + '?scheme=' + scheme);
	
	
}



function fancyBox_images(){
	$(".extra_pictures a.single_image").fancybox();
	$("a.go_big_img").fancybox();
	
	/* Using custom settings */
	$(".extra_pictures a.inline").fancybox({
		'hideOnContentClick': true
	});
	$(".pictures_list_in_content a.group").fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300,
		'overlayShow': true
	});
}




function HeaderAnimation() {
	this.init();
}

HeaderAnimation.prototype = {
		
	current: 0,
	timerInterval: 3000,
	
	init: function() {

		var self = this;
		
		// defineer
		
		this.photoWrapper 		= $('#main_banner .image li');
		this.linkWrappers 		= $('#main_banner .controls li');		
		//this.textWrapper 	= $('#main_banner li');
		//this.textHolderWrapper	= $('.top_text_layer');	
		
		// pause mode
		this.photoWrapper.hover(
			function() { self.pauseAutoTimer(); },
			function() { self.resetAutoTimer(); });
		this.hideAll();
		/*// pause mode		
		this.mainBannerWrapper.hover(
			function() { self.pauseAutoTimer(); },
			function() { self.resetAutoTimer(); });		*/
		
		
		//var self = this;
		// linkWrappers click actie
		this.linkWrappers.css('cursor', 'pointer').hover(
			function() {		
				self.setCurrent(
					self.linkWrappers.index($(this))
				);
			}			
		);
		
		this.resetAutoTimer();
	},
	
	pauseAutoTimer: function() {

		clearInterval(this.autoTimer);
	},
	
	resetAutoTimer: function() {

		var self = this;

		clearInterval(this.autoTimer);
		this.autoTimer = setInterval(function() {
			self.showNext();
		}, this.timerInterval);
	},
	
	hideAll: function() {		

		this.photoWrapper.css({
			opacity: 0,
			position: 'absolute',
			top: 0
		});	
		/*
		this.textWrapper.css({
			opacity: 0,
			position: 'absolute',
			top: 0
		});	*/
		 
		this.showCurrent();
	},
	
	showCurrent: function() {
		this.linkWrappers.eq(this.current).addClass('active');
		//this.photoWrapper.eq(this.current).stop().animate({opacity: 1});
		this.photoWrapper.eq(this.current).stop().css({'zIndex':'10'}).animate({opacity: 1});
	},
	
	hideCurrent: function() {
		this.linkWrappers.eq(this.current).removeClass('active');
		//this.photoWrapper.eq(this.current).stop().animate({opacity: 0});
		this.photoWrapper.eq(this.current).stop().css({'zIndex':'1'}).animate({opacity: 0});
	},
	
	setCurrent: function(index) {
		
		//prev state
		this.hideCurrent();
		//set new state
		this.current = index;
		//new state
		this.showCurrent();
		
		//reset timer
		this.resetAutoTimer();
	},
	
	showNext: function() {
		//can only be a number as large as the collection!, otherwise it wil reset itself
		this.setCurrent((this.current + 1) % this.linkWrappers.length);
	}
};
