(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");				
			};
			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){
				if(!hover)
				{
					var nextIdx = selectedIndex+1;
					if(nextIdx > menu.length-1)
					{
						nextIdx = 0;
					}
					if (!init)
						activateItem(menu[nextIdx]);
				}
				setTimeout(rotate, rotateTime);
			};
			if(doRotate)
				rotate(true);
		});
	};
	$(function(){
		// initialize all media containers on pageload.
		// onhover,onclick, rotate, rotateTime
		$('div.artikeloverview.large.multi').amArtikelen(true,false,true,5000);
	});
})($);

$(document).ready(function() {
	$("div.artikeloverview.medium > div.artikelitem:nth-child(3n+1)").addClass('odd');
	
	if($.browser.msie && parseInt($.browser.version) < 9)
  {      
    $("div.artikeloverview.medium").each(function() {
       $("div.artikelitem", $(this)).each(function() {
       var prev = $(this).prevAll().length;
          if( (( prev) % 3) == 0) 
          {
            $(this).css("margin-left", "0");
          }
       });
    });
  }
  
	$("div.artikeloverview.medium > div.artikelitem:nth-child(odd)").addClass('oddColored');
	
	if($(".homeVideoclip").length > 0) 
	{
	  $(".homeVideoclip").each(function() {
	    var curLink = $(".thumb", this).attr("src");
	    if(curLink && typeof curLink != "undefined")
	    {
	      var newLink = curLink.replace("w=195&h=195", "w=388&h=195");
	      $(".thumb", this).attr("src", newLink);
	      var pageLink = $(".thumb", this).parent().attr("href");
	      if(pageLink)
	      {
	        $(".homeVideoclipOverlay", this).click(function() {
	            window.location.href = pageLink;
	        });
	      }
	    }
	  });
	}
/*
	if($(".percentagePoll").length > 0)
	{
	  //Percentages weergeven voor de poll, ipv getallen
	  
	  //eerst het totaal aantal stemmen ophalen	  
	  var total = 0;
	  $(".pollAntwoordText").each(function() {
	      if($(this).text() != "")
	      {
	        total += parseInt($(this).text());
	      }
	  });
	  var percPerScore = 100 / total;
	  $(".pollAntwoordStat .pollAntwoordText").each(function() {
	      if($(this).text() != "")
	      {
	        var votes = parseInt($(this).text());
	        $(this).text(parseInt(votes * percPerScore) + " %");	        
	      }
	  });
	}*/
});

