var ccHeaderfadeInterval;

$.fn.ccheaderfade = function(options)
{
	
	var defaults = {
						timeoutFade: 1500,
						timeoutLoop: 5000,
						autorun: 	 true
	};
	
	var opts = $.extend(defaults, options);
	
	return this.each(
		function()
		{
			var $this = $(this);
	
			if ($this.find("img").length > 1)
			{		
				$this.find("img:gt(0)").hide();
				$this.find("img:first").addClass('active');
				
	// Automatisch de foto's laten wijzigen
				if (opts.autorun)
				{
					$.fn.ccheaderfade.autorun(opts, $this);
				}
			}
		}
	);
}

$.fn.ccheaderfade.autorun = function(opts, oBlock)
{
	ccHeaderfadeInterval = setInterval(function(){$.fn.ccheaderfade.loopImages(opts, oBlock)}, opts.timeoutLoop);
}

$.fn.ccheaderfade.loopImages = function(opts, oBlock)
{
	var current = oBlock.find("img.active");
	var next = current.next("img");
	
	if (next.length == 0)
	{
		next = oBlock.find("img:first");
	}
	
	current.fadeOut(opts.timeoutFade);
	next.fadeIn(opts.timeoutFade);
	
	current.removeClass('active');
	next.addClass('active');
}
