function Slideshow(numImages, slideshowId, timeout) {
	
  this.numImages = numImages;
  this.curr = 0;
  this.next = 1;
  this.images = new Array();
  this.link = document.getElementById('magnifier');
  
  //this.captions = new Array();
  for (i = 0;i < this.numImages;i++) {
    this.images[i] = document.getElementById(id = 'slideshow' + i);
    //this.captions[i] = document.getElementById('caption_' + slideshowId + '_' + i);
  }
  


  this.imageWidth = $(this.images[0].parentNode).width();

  this.timeout = timeout;
  this.fadetime = 700;
  

  //this.captiontime = 500;
  
  $(this.images[0]).animate({'left':'0px'}, this.captiontime);
  
  
  selfRef = this;
  setTimeout(function() { selfRef.setDelay();}, this.timeout);

}

Slideshow.prototype.fade = function() {
  selfRef = this;
  $(this.images[this.curr]).fadeOut(this.fadetime, function() {selfRef.swap()});
  var timediff = this.fadetime - this.captiontime;
  setTimeout(function() {selfRef.swapCaption();}, timediff);
}

Slideshow.prototype.swapCaption = function() {
  $(this.images[this.curr]).animate({'left':'-'+this.imageWidth+'px'}, this.captiontime);
  $(this.images[this.next]).css('left', this.imageWidth+'px');
  $(this.images[this.next]).animate({'left':'0'}, this.captiontime);
}

Slideshow.prototype.swap = function() {


  selfRef = this;
  // swap to bottom
  this.images[this.curr].style.zIndex = 0;
  $(this.images[this.curr]).show();


  
  
  leadingZero = '0';
  
  if (parseInt(this.curr + 1) > 9) {
	leadingZero = '';
  }	
	
  this.link.href='/bildgalleri/prod' + leadingZero + (this.curr + 2) + '.html';
  

  
  // change images
  this.curr = this.next;
  
  this.next++;
  if(this.next >= this.numImages) {
    this.next = 0;
  }

  

  
  // swap next up
  this.images[this.curr].style.zIndex = 2;
  this.images[this.next].style.zIndex = 1;


  setTimeout(function() {selfRef.setDelay();}, this.timeout);
}

Slideshow.prototype.setDelay = function() {

	$('.magnifier').show();
/*  if(this.images[this.curr].complete && this.images[this.next].complete) {
    this.fade();
  } else {
    selfRef = this;
    setTimeout(function() {selfRef.setDelay();}, this.timeout);
  }
  */
  
    this.fade();

}
