  var switchbox = {

	switchTime : 5000,
	switchElements : new Array(),
	firstItem : new Array(),
	firstBlock : new Array(),
	activeItems : new Array(),
	itemCounter : new Array(),
	items : new Array(),
	activeBlocks : new Array(),
  hoveredElement : new Array(),
  hoveredElementParent : new Array(),
	mouseOverItem : new Array(),
		
  init : function() {
		for (var c = 0; c < this.switchElements.length; c++) {
	      this.firstItem[c] = $("."+this.switchElements[c]+" .item:first");
	      this.firstBlock[c] = $("."+this.switchElements[c]+" .block:first");
	      this.activeItems[c] = null;
	      this.itemCounter[c] = 1;
		  	this.mouseOverItem[c] = 0;
		  this.items[c] = $("."+this.switchElements[c]+" .item").size();
	      $(this.firstItem[c]).addClass("active");
		  $(this.firstBlock[c]).addClass("activeblock");
		  /* hover */
	      this.hoveredElement[c] = null;
	      this.hoveredElementParent[c] = null;
		  $("."+this.switchElements[c]+" .item").hover( function() {
		  	switchbox.hover(this);
		  },
		  function() {
			 switchbox.hoverout(this);
		  });
		}
		 $().everyTime(this.switchTime, 1, function() {
		 	switchbox.rotate();
		 });

  },
	
	rotate : function () {
	  for (var c = 0; c < this.switchElements.length; c++) {
	  	if (this.mouseOverItem[c] == 1) {
				// nu niks doen, want iemand hangt met de muis boven een item
			} else {
          this.activeItems[c] = $("."+this.switchElements[c]+" .item.active");
          this.activeBlocks[c] = $("."+this.switchElements[c]+" .block.activeblock");
      
          $(this.activeItems[c]).removeClass("active");
          $(this.activeBlocks[c]).removeClass("activeblock");
      
          if (this.itemCounter[c] == this.items[c]) {
            $(this.firstItem[c]).addClass("active");
            $(this.firstBlock[c]).addClass("activeblock");
            this.itemCounter[c] = 1;
          } else {
            $(this.activeItems[c]).next(".item").addClass("active");
            $(this.activeBlocks[c]).next(".block").addClass("activeblock");
            this.itemCounter[c] = this.itemCounter[c] + 1;
          }
		  }
	  }
	},
	
  hover : function(e) {
			 // onderstaande regels dienen om het hoverelement (li) te bepalen en daarbij horende id 
			 // zoals in item[id] 
			 var obj = e.className.match(/item+[0-9]/);
			 var hoveredElement = new String(obj); // uit match komt object en wij hebben string nodig voor replace
       itemid = hoveredElement.replace('item', '')*1;

			 for (var c = 0; c < this.switchElements.length; c++) {
				 var match = e.parentNode.className.match(this.switchElements[c]);
				 if (match) {
		 			 var hoveredElementParent = match;
					 this.itemCounter[c] = itemid;
					 this.mouseOverItem[c] = 1;
				 }
			 }
			 
       $("." + hoveredElementParent + " .item.active").removeClass("active");
       $("." + hoveredElementParent + " .block.activeblock").removeClass("activeblock");
       
       $("." + hoveredElementParent + " .item." + hoveredElement).addClass("active");
       $("." + hoveredElementParent + " .block." + hoveredElement).addClass("activeblock");
	},
	
  hoverout : function(e) {
			 for (var c = 0; c < this.switchElements.length; c++) {
				 var match = e.parentNode.className.match(this.switchElements[c]);
				 if (match) {
					 this.mouseOverItem[c] = 0;
				 }
			 }
	}

}
