(function($)
{
	$.fn.amArtikelen = function(text, args) {
		return this.each(function() {
			var hover = false;
			$(this).mouseover(function(){
				hover = true;
			});
			$(this).mouseout(function(){
				hover = false;
			});
			var menu = $(this).find('ul>li');
			var children = $(this).children('div');
			menu.each(function(){
				$(this).click(function(){
					menu.removeClass("selected");
					children.removeClass("selected");
					$(this).addClass("selected");
					$(children[	$(this).index()]).addClass("selected");
				});
			});	
			if(menu.length > 0)
				$(menu[0]).click();
			var rotate = function(init){
				if(!init && !hover)
				{
					var idx = 0;
					menu.each(function(){
						if($(this).hasClass("selected"))
							idx = $(this).index();
					});
					idx = idx+1;
					if(idx > menu.length-1)
					{
						idx = 0;
					}
					$(menu[idx]).click();
				}
				setTimeout(rotate, 3000);
			};
			rotate(true);
		});
	};
	$(function(){
		// initialize all media containers on pageload.
		$('div.artikeloverview.large.multi').amArtikelen();
	});
})($);

