		$(document).ready(function() {
		
		jQuery.fn.fadeIn = function(speed, callback) { 
			return this.animate({opacity: 'show'}, speed, function() { 
				if (jQuery.browser.msie)  
					this.style.removeAttribute('filter');  
				if (jQuery.isFunction(callback)) 
					callback();  
			}); 
		}; 
		 
		jQuery.fn.fadeOut = function(speed, callback) { 
			return this.animate({opacity: 'hide'}, speed, function() { 
				if (jQuery.browser.msie)  
					this.style.removeAttribute('filter');  
				if (jQuery.isFunction(callback)) 
					callback();  
			}); 
		};		
		
			//Variabele
			var parent = "#slideshow ";
			var thumbs = "#thumbs ";
			var fadespeed = 500;
			var fadeslow = 750;
			var timer = 5000;
			var size = $(parent+ ".slide").size();
			//Eerste element infaden
			$(parent+ ".slide:first-child").fadeIn(fadespeed, function(){
				$(parent+ ".slide:visible span").slideDown(fadespeed);
				activeThumb();
			});
			
			$(thumbs+ ".slide").hover(
			  function () {
				if (!$(this).hasClass("active")){
					$(this).fadeTo(fadespeed, 0.9);
				}
			  }, 
			  function () {
				if (!$(this).hasClass("active")){
					$(this).fadeTo(fadespeed, 0.8);
				}
			  }
			);
			//Stel timer in voor auto sliden	
			function startSlide()
			{  
				interval = setInterval(autoSlide, timer);
				if (size <= 1){
					resetSlide();
				}
			}
			//Denkwerk
			//var done = 1;
			function slideCode(){
				//if (done == 1){
					//done = 0;
					$(parent+ ".slide:visible span").slideUp(fadespeed, function(){
						if ($(parent+ ".slide:visible").next('.slide').length == 0){
							$(parent+ ".slide:first").fadeIn(fadespeed, function(){
								activeThumb();
							});
							$(parent+ ".slide:last").fadeOut(fadeslow, function(){
								$(parent+ ".slide:visible span").slideDown(fadespeed);
							});
						}
						else{
							$(parent+ ".slide:visible").next().fadeIn(fadeslow, function(){
								$(parent+ ".slide:visible").prev().hide();
								$(parent+ ".slide:visible span").slideDown(fadespeed);
								activeThumb();
							});
						}
					});
				//}
			}
			//Voer denkwerk uit
			function autoSlide()
			{
				slideCode();
			}
			//Slider stop zetten
			function resetSlide()
			{  
				clearInterval(interval);			
			}
			function activeThumb()
			{
				activeIndex = $(parent+ ".slide:visible").index();				
				$(thumbs+ ".slide").removeClass("active");
				$(thumbs+ ".slide").eq(activeIndex).addClass("active");
				$(thumbs+ ".slide:not('.active')").fadeTo(fadespeed, 0.8);
				$(thumbs+ ".slide.active").fadeTo(fadespeed, 1.0);
				//done = 1;
			}
			//Klik event
			$(".next").click(function() {
				resetSlide();
				slideCode();
				startSlide();
			});
			$(thumbs+ ".slide").click(function(){
				var index = $(this).index();
				var sindex = $(parent+ ".slide:visible").index();
				if (index != sindex){
					//if (done == 1){
						//done = 0;
						resetSlide();
						$(parent+ ".slide:visible span").slideUp(fadespeed, function(){
							$(parent+ ".slide").eq(index).fadeIn(fadeslow);
							$(parent+ ".slide").eq(sindex).fadeOut(fadeslow, function(){
								$(parent+ ".slide:visible span").slideDown(fadespeed);
								activeThumb();
							});
						});
						startSlide();
					//}
				}
				return false;
			});
			$(".slide span:not('#bramslide .slide span')").click(function(){
				return false;
			});			
			//if (done == 1){
				//done = 0;
				$(".slide[rel=fancygroup], .slidefancy").fancybox({
					'titlePosition'   : 'over',
					'overlayOpacity'	: 0.8,
					'overlayColor'	: '#333333',
					'onStart'	: function() {
						resetSlide();
					},
					'onClosed'	: function() {
						//done = 1;
						startSlide();
					}
				});
			//}
			startSlide();
			$(".loadFancy").click(function(){
				$(".slide[rel=fancygroup]:visible").trigger('click');
			});
			
		});
