function ImageCarousel() {
  this.items = new Array();
  this.counter = 1;
  this.nrThumbs = 4;
  //this.imgBig = document.getElementById("imggroot");
  this.arrowLeft = document.getElementById("pijllinks");
  this.arrowRight = document.getElementById("pijlrechts");
  
  this.imgThumbName = "imgKlein";

  this.add = function(item, url) {
    this.items.push(new Array(item, url));
  }
  
  this.goTo = function(x)
  {
      this.counter = this.checkExists(x);
      this.show(this.counter);
			this.ShowButtons(this.items.length, this.counter);
  }
  
  this.checkExists = function(x)
  {
  	if(x < 0)
    {
   	  x = this.items.length + x;
    }else if(!this.items[x])
    {
      x = 0;
    }
    this.counter = x;
    return this.counter;
  }
	
	this.ShowButtons = function(x,y)
	{
		if(y == (x-this.nrThumbs)){
			this.arrowLeft.href = "#";
			this.arrowLeft.innerHTML = "<img src='/interface/images/productslider_btn_links_disabled.gif'/>";
		}else{
			this.arrowLeft.innerHTML = "&nbsp;";
		}
		
		if(y == 0){
			this.arrowRight.href = "#";
			this.arrowRight.innerHTML = "<img src='/interface/images/productslider_btn_rechts_disabled.gif'/>";
		}else{
			this.arrowRight.innerHTML = "&nbsp;";
		}
	
		if(y == 0 && x <= this.nrThumbs){
			this.arrowRight.href = "#";
			this.arrowRight.innerHTML = "<img src='/interface/images/productslider_btn_rechts_disabled.gif'/>";
			this.arrowLeft.href = "#";
			this.arrowLeft.innerHTML = "<img src='/interface/images/productslider_btn_links_disabled.gif'/>";
		}
	}	
  
  
  this.gotoNext = function()
  {
  	this.goTo(this.counter+1);
  }
  
  this.gotoPrevious = function()
  {
  	this.goTo(this.counter-1);
  }

  this.show = function(i)
  {
    i = this.checkExists(i);
    //this.imgBig.style.backgroundImage = "url("+this.items[i][0]+")";
    this.arrowLeft.href = "javascript:carousel.goTo("+(i+1)+");";
    this.arrowRight.href = "javascript:carousel.goTo("+(i-1)+");";
		
		if(this.items.length >= this.nrThumbs){
			for(t=1;t<=this.nrThumbs;t++)
	    	{
	     	  document.getElementById(this.imgThumbName+t).href = this.items[this.checkExists(i+2-t)][1] + "&nr=" + (i+2-t);
					document.getElementById(this.imgThumbName+t).innerHTML = this.items[this.checkExists(i+2-t)][0];
	    	}
		}else{
			for(t=1;t<=this.items.length;t++)
	    {
  	    document.getElementById(this.imgThumbName+t).href = this.items[this.checkExists(i+2-t)][1];
				document.getElementById(this.imgThumbName+t).innerHTML = this.items[this.checkExists(i+2-t)][0];
	    }
		}
  }
  
  this.start = function()
  {
	  var nrTo = "";
	  if (location.search != ""){
		  var x = location.search.substr(1).split(";")
		  for (var i=0; i<x.length; i++){
			  var y = x[i].split("&");
			  for (var k=0; k<y.length; k++){
				  if (y[k].split('=')[0] == "nr"){
					  nrTo = (y[k].split('=')[1]);
				  }
			  }
		  }
	  }
	  if(nrTo != ""){
		  this.goTo(nrTo-1);
	  }else{
      this.goTo(this.items.length-2);
	  }
  }
		
}
