    function addEvent(obj, type, fn)
    {
      if(obj.attachEvent)
      {
        obj['e'+type+fn] = fn;
        obj[type+fn] = function(){obj['e'+type+fn](window.event);
      }
      obj.attachEvent('on'+type, obj[type+fn]);
      }else
      {
        obj.addEventListener( type, fn, false );
      }
    }
function ImageRoul() {
  // Interne variabelen
  this.items = new Array();

  this.counter = 0;
  this.showimages = 6;
  
  this.name = 'roulleren';
  this.container = "roul";
  this.txt = 'fotoInfo';
  this.groteimg = 'ctl00_cphInhoud_himFoto';
  this.href = '';
  this.aNext = 'roulnext';
  this.aPrev = 'roulprev';
  this.currenthidden = 'ctl00_cphInhoud_fotoSelected';
  
  this.roundandround = false;
  this.speed = '200';
    
  // Voeg plaatje met tekst toe aan items
  this.add = function(img, imggroot, tekst) {
    this.items.push(new Array(img, imggroot, tekst));
  }
  this.goto = function(x,speed)
  {
    //speed word pas later verwerkt
    if(!speed)
    {
      speed = this.speed;
    }
  	x = this.getitem(x);
  	
  	voorachter = Math.ceil(this.showimages/2);
  	
  	begin = (x-voorachter);
  	if(begin<0)
  	{
  		eind = (x+voorachter)-begin;
  	}else
  	{
  		eind = (x+voorachter);
  	}
  	if(eind>this.items.length)
  	{
  	  tot = eind;
  	}else
  	{
  	  tot = this.items.length;
  	}
  	//alert(begin+" - "+eind);
  	
  	if(begin >= 0 || this.roundandround == true)
  	{
  	  this.cPrev(true);
  	}else if(begin <= 0 && this.roundandround == false)
  	{
  	  this.cPrev(false);
  	}
  	if(eind< this.items.length || this.roundandround == true)
  	{
  	  this.cNext(true);
  	}else if(eind >= this.items.length && this.roundandround == false)
  	{
  	  this.cNext(false);
  	}
  	
  	//this.affectall("this.itemhide");
    for(i=document.getElementById("contoverflow").childNodes.length-1;i>=0;i--)
    {
      this.itemhide(i);
    }
    //document.getElementById("contoverflow").innerHTML = '';
  	if(this.roundandround == true)
  	{
  	  this.affectall("this.itemshow",(x-voorachter),(x+voorachter));
  	}else //rounaandround == false
  	{
  	  if(begin < 0)
  	  {
  	    begin = 0;
  	  }
      if(eind-begin<(this.showimages)+1)
      {
        eind = begin+(this.showimages);
      }else
      {
        eind = (this.showimages)+begin;
      }
  	  if(eind+voorachter > this.items.length)
  	  {
  	    begin += (this.items.length - 1 - eind);
  	    eind = this.items.length - 1;
  	  }
      
  	  this.affectall("this.itemshow",begin,eind);
  	}
	
	this.counter = x;
	this.itemselected(x);
  }
  this.next = function()
  {
    this.goto(this.counter+1);
  }
  this.prev = function()
  {
    this.goto(this.counter-1);
  }
  this.cNext = function(bln)
  {
    if(bln == true)
    {
      document.getElementById(this.aNext).style.visibility = 'visible';
    }else
    {
      document.getElementById(this.aNext).style.visibility = 'hidden';
    }
  }
  this.cPrev = function(bln)
  {
    if(bln == true)
    {
      document.getElementById(this.aPrev).style.visibility = 'visible';
    }else
    {
      document.getElementById(this.aPrev).style.visibility = 'hidden';
    }
  }
  this.itemhide = function(x)
  {
    document.getElementById("contoverflow").removeChild(document.getElementById("contoverflow").childNodes[x]);    
  }
  this.itemshow = function(x)
  {
    var objNewPic = document.createElement("div");
    //objNewPic.setAttribute("class","item show");
    objNewPic.className = "item show"
    objNewPic.style.backgroundImage = "url(" + this.items[x][0] + ")";
    //objNewPic.setAttribute("style","background-image:url("+this.items[x][0]+");")
    objNewPic.onclick = this.name + ".goto(" + x + ")"
    //objNewPic.setAttribute("onclick",);
    //");
    //addEvent(objNewPic,"click",function c(){this.name+".goto("+x+")"});
    addEvent(objNewPic,"click",function c(){roulleren.goto(x)});
    objNewPic.id = this.container+"item"+x;
    document.getElementById("contoverflow").appendChild(objNewPic);
    
  }
  this.itemselected = function(x)
  {
    
    if(this.txt != "")
    {
      document.getElementById(this.txt).innerHTML = (x+1)+" van "+(this.items.length);
    }
    if(this.currenthidden != "")
    {
    	document.getElementById(this.currenthidden).value = this.items[x][1];
    }
    if(this.groteimg != "")
    {
    	document.getElementById(this.groteimg).src = this.items[x][1];
    	document.getElementById(this.groteimg).alt = this.items[x][2];
    }
    
	document.getElementById(this.container+"item"+x).className = "item show selected";
  }
  this.getitem = function(x)
  {
    //alert(x);
  	if(this.items[x])
  	{
  	  return x;
  	}else if(x<0)
  	{
  	  return (this.items.length + x);
  	}else if(x >= this.items.length)
  	{
  	  //alert(x-this.items.length);
  	  return (x - this.items.length);
  	}
  	return 0;
  }
  this.affectall = function(f,from,to)
  {
    if(!from)
    {
      ifrom = 0;
    }else
    {
      ifrom = from
    }
    if(!to)
    {
      ito = document.getElementById("contoverflow").childNodes.length;
    }else
    {
      ito = to;
    }
    for(i=ifrom;i<=ito;i++)
    {
      if((this.roundandround == true) || ((i >= 0) && (i < this.items.length)))
      {
          eval(f+"("+this.getitem(i)+")");
      }     
    }
  }
  this.renderitem = function(x)
  {
  	//return "<div class='item hide' id='"+this.container+"item"+x+"' onclick=\"javascript:"+this.name+".goto("+x+");\">"+x+"</div>";
  }
  this.start = function()
  {
	if(this.aNext != "")
	{
	  document.getElementById(this.aNext).href = "javascript:"+this.name+".next();";
	}
	if(this.aPrev != "")
	{
	  document.getElementById(this.aPrev).href = "javascript:"+this.name+".prev();";
	}
  	var inhoud = '';
  	for(i=0;i<this.items.length;i++)
  	{
  	  inhoud += this.renderitem(i)
  	}
  	document.getElementById(this.container).innerHTML = "<div id='contoverflow'>"+inhoud+"</div>";
	this.goto(this.counter);
  }
}