(function($)
{
	$.fn.amArtikelen = function(onMouseOver, onClick, doRotate, rotateTime) {
		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');
			var selectedIndex = 0;
			var activateItem = function(item){
				$this = $(item);
				menu.removeClass("selected");
				children.removeClass("selected");
				selectedIndex = $this.index();
				$this.addClass("selected");
				$(children[ selectedIndex	]).addClass("selected");				
			};
			menu.each(function() {
			  var myIndex = ($(this).prevAll().length + 1);
			  var total = $(this).parent().children().length;
			  
			  var prevItem = $(this).prev("li");			  
			  if(prevItem.length == 0)
			  {			    
			      prevItem = $(this).parent().children().last();
			  }
			  var prevSelector = $("<a> < </a>");
			  prevSelector.click(function() {
			    activateItem(prevItem);
			  });			  			  
			  
			  var nextItem = $(this).next("li");
			  if(nextItem.length == 0)
			  {
			      nextItem = $(this).parent().children().first();
			  }
			  
			  var nextSelector = $("<a> > </a>");
			  nextSelector.click(function() {
			    activateItem(nextItem);
			  });	
			  
			  var navControl = $("<span class='hightlightnav' />");			  
			  navControl.append(prevSelector).append(" " + myIndex + " / " + total + " ").append(nextSelector);			  
			  $(this).append(navControl);			  
			});
			
			if(onMouseOver)
			{
				menu.mouseover(function(){ activateItem(this); });
			}
			if(onClick)
			{
				menu.click(function(){ activateItem(this); });
			}
			if(menu.length > 0)
				activateItem(menu[0]);
				
			var rotate = null;
			rotate = function(init){
			
					var nextIdx = selectedIndex+1;
					if(nextIdx > menu.length-1)
					{
						nextIdx = 0;
					}
					if (!init)
						activateItem(menu[nextIdx]);
				
				setTimeout(function() { rotate() }, rotateTime);
			};
			if(doRotate)
				rotate(true);
		});
	};
	$('div.artikeloverview.large.multi').ready(function(){
		// initialize all media containers on pageload.
		// onhover,onclick, rotate, rotateTime
		$('div.artikeloverview.large.multi').amArtikelen(false,false,true,4000);		
	});
})($);

$(document).ready(function() {
	$("div.artikeloverview.medium > div.artikelitem:nth-child(3n+1)").addClass('odd');
});
