function Slideshow(albumname) {
	this.maxImgAreaHeight = 480;

	this.name = albumname;
	this.images = Array();
	this.currentIndex = 0;
	this.active = false;
	
	this.slideshowArea = document.createElement('div');
	this.slideshowArea.id = 'slideshow';
	
	this.slideshowContainer = document.createElement('div');
	this.slideshowContainer.id = 'slideshowContainer';
	
	this.nameArea = document.createElement('h2');
	this.nameArea.appendChild(document.createTextNode(this.name));
	this.nameArea.id = 'slideshowTitle';
	
	this.contentArea = document.createElement('div') //The content area contains title, image and subtitle
	this.contentArea.id = 'slideshowContent';
	
	//Create image area
	
	this.imgArea = document.createElement('div');
	this.imgArea.id = 'slideshowImageArea';
	this.imgTag = document.createElement('img');
	this.imgTag.id = 'slideshowImage';
	
	this.imgArea.appendChild(this.imgTag);
	
	this.imgAreaHeight = this.imgArea.offsetHeight;
	
	this.subtitleArea = document.createElement('div');
	this.subtitleArea.id = 'slideshowSubtitle';
	this.controlsArea = document.createElement('div');
	this.controlsArea.id = 'slideshowControls';
	//Setup contols
	var prev = document.createElement('img');
	prev.className = 'prev';
	prev.onclick = function() {slideshow.prev()};
//	prev.setAttribute('onclick','slideshow.prev()');
	prev.setAttribute('src','gfx/left.gif');
	
	//var close = document.createElement('img');
	var close = document.createElement('a');
	close.className = 'close';
	close.onclick = function() {slideshow.endSlideshow()};
	//close.setAttribute('onclick','slideshow.endSlideshow()');
	//close.setAttribute('src','gfx/sl_quit.png');
	closeText = document.createTextNode('Stäng');
	close.appendChild(closeText);
	var next = document.createElement('img');
	next.className = 'next';
	next.onclick = function() {slideshow.next()};
	//next.setAttribute('onclick','slideshow.next()');
	next.setAttribute('src','gfx/right.gif');
	
	this.infoArea = document.createElement('div');
	this.infoArea.id = 'slideshowInfo';
	
	this.controlsArea.appendChild(this.infoArea);
	this.controlsArea.appendChild(prev);
	this.controlsArea.appendChild(close);
	this.controlsArea.appendChild(next);
	
	this.slideshowContainer.appendChild(this.nameArea);
	this.slideshowContainer.appendChild(this.imgArea);
	this.slideshowContainer.appendChild(this.subtitleArea);
	
	this.slideshowContainer.appendChild(this.controlsArea);
	this.slideshowArea.appendChild(this.slideshowContainer);
	
	//this.slideshowArea.appendChild(this.contentArea);
	
	this.add = function(image) {
		this.images.push(image);
	}
	
	this.next = function() {
		nextIndex = this.currentIndex+1 == this.images.length ? 0 : this.currentIndex+1;
		this.showImage(nextIndex);
	}
	
	this.prev = function() {
		prevIndex = this.currentIndex == 0 ? this.images.length-1 : this.currentIndex-1;
		this.showImage(prevIndex);
	}
	
	this.showImage = function(index) {
		this.image = this.images[index];
		this.currentIndex = index;
		this.showCurrentImage();
	}
	
	this.showImageFromUrl = function(url,subtitle) {
		this.clearSlideshow();
		this.image = Object();
		this.images.push(this.image);
		this.image.filename=url;
		this.image.subtitle = isFileExtensionImage(subtitle) ? '' : subtitle;
		this.showCurrentImage();
	}
	
	this.showCurrentImage = function() {
		scroll(0,0);
		this.subtitleArea = document.getElementById('slideshowSubtitle') ? document.getElementById('slideshowSubtitle') : this.subtitleArea;
		if(!this.active)
			this.startSlideshow();
		this.imgAreaHeight = this.imgArea.offsetHeight;
		this.imgTag.onload = function() { setTimeout('slideshow.resizeImage()',200);};
		this.imgTag.src = this.image['filename'];
	}
	
	this.endSlideshow = function() {
		
		this.nameArea.InnerHTML = this.name;
		this.imgTag.src = '';
		this.subtitleArea.InnerHTML = '';
		
		var transpLayer = document.getElementById("transparentLayer");
		document.body.removeChild(this.slideshowArea);
		transpLayer.style.display = 'none';
		
	}
	
	this.startSlideshow = function(index) {
		var transpLayer = document.getElementById("transparentLayer");
		document.body.appendChild(this.slideshowArea);
		var docSize = getDocumentSize();
		transpLayer.style.display='block';
		transpLayer.style.height = document.documentElement.scrollHeight + 'px';
	}
	
	this.clearSlideshow = function() {
		this.images = Array();
		this.currentIndex = 0;
	}
	
	this.resizeImage = function() {
		var height = this.imgTag.offsetHeight > this.maxImgAreaHeight ? this.maxImgAreaHeight : this.imgTag.offsetHeight;
		//alert(areaHeight+',offsetHeight: '+this.imgTag.offsetHeight);
		this.imgTag.style.height = height +'px';
		this.subtitleArea.innerHTML = this.image['subtitle'];
		this.infoArea.innerHTML = 'Bild '+(this.currentIndex+1)+' av '+this.images.length;
		this.slideshowContainer.style.width = (this.imgTag.width+20)+'px'; 
		var transpLayer = document.getElementById("transparentLayer");
		transpLayer.style.height = document.documentElement.scrollHeight + 'px';
	}
	
}
