

$(document).ready(function(){

	// Itemlinks tonen en de eerste header img laten zien
	$(".itemlinks li:first").addClass("active");
	$(".items li:first").addClass("active");
	$("#featured .items a").find("span").stop(true,true).fadeIn();

	// Set interval timer
	if ($(".items li").length > 1)	var slideLoop = setInterval(showNext, itemWait);
	else slideLoop = false;

	$(".itemlinks li").click(function() {

		// Het timer interval schoonmaken
		clearInterval(slideLoop);
		
		// Toon bijschrift
		$("#featured .items a").find("span").stop(true,true).fadeIn();

		// Item laten zien
		if ($(".items .active").length && showItem(this)) return false;

	});
});

(function($)
{
   $.fn.showHtml = function(html, speed, callback)
   {
      return this.each(function()
      {
         var el = $(this);
         var finish = {width: this.style.width, height: this.style.height};
		 var cur = {width: el.width()+'px', height: el.height()+'px'};

         el.html(html);

         var next = {width: el.width()+'px', height: el.height()+'px'};

         el .css(cur)
            .animate(next, speed, function()
            {
               el.css(finish);
               if ( $.isFunction(callback) ) callback();
            });
      });
   };

})(jQuery);

// Show next item function
function showNext() {
	if ($(".itemlinks .active").next().length) showItem($(".itemlinks .active").next());
	else showItem($(".itemlinks li:first").get());
	
	// Toon bijschrift
	$("#featured .items a").find("span").stop(true,true).fadeIn();
}

// Show specific item number
function showItem(item) {

	// Don't do anything if this tab is active
	if ($(item).hasClass("active")) return false;

	// Stop animation
	$(".items ul").stop();

	// Set active state
	$(".itemlinks li").removeClass("active");
	$(item).addClass("active");
	featureNum = $(item).prevAll().length;
	feature = $(".items li").eq(featureNum);
	feature.css("z-index", "49");

	// Animate
	$(".items .active").removeClass("active").fadeOut(animSpeed, function() {
		$(this).css("z-index", "40").show();
		feature.css("z-index", "50").addClass("active");
	});

	return true;

}
