

	function Imagelist(container)
	{
		var that= this;
		this.gallery= null;
		this.container= container;
		
	
		this.loadImages= function(images)
		{
			if (this.gallery != null && this.gallery.images == images) return;
			
			while (this.container.firstChild) this.container.removeChild(this.container.firstChild);
			this.gallery= new galleryClass(this.container, images);
		}
		
		
		function galleryClass(container, images)
		{
			var that= this;
			this.container= container;
			this.images= images;
			this.slider= null;
			this.activeImage= null;
		
			this.init= function()
			{
				this.center= document.createElement('div');
				this.center.className= 'center';
				this.container.appendChild(this.center);
				
				this.slider= document.createElement('div');
				this.slider.className= 'slider';
				this.center.appendChild(this.slider);
		
				this.sliderStart= 0;
				this.slider.rightOffset= 0;
				var firstRound= true;
				
				for (var i= 0; i < this.images.length; i++)
				{
					var temp= this.createImage(this.images[i]);
					this.slider.appendChild(temp);
					temp.style.marginLeft= this.slider.rightOffset+'px';
					temp.marginLeft= this.slider.rightOffset;
					temp.sliderPosition= this.slider.rightOffset+Math.round(temp.width/2);
					temp.imageNr= i;
					
					this.slider.rightOffset+= temp.width;
					
					if (i == 0 && !firstRound) sliderStart= temp;
					
					if (i == this.images.length-1 && firstRound) 
					{
						i= -1;
						firstRound= false;
					}
				}
				
				//this.slider.style.left= sliderStart.sliderPosition*(-1)+'px';
				this.openImage(sliderStart);
				
				if (this.images.length > 1)
				{
					var tempPrevious= document.createElement('a');
					tempPrevious.className= 'control previous';
					tempPrevious.href= 'javascript: void(0);';
					bm.addevent(tempPrevious, 'click', function(e) { that.previousImage(); });
					this.center.appendChild(tempPrevious);
					
					var tempNext= document.createElement('a');
					tempNext.className= 'control next';
					tempNext.href= 'javascript: void(0);';
					bm.addevent(tempNext, 'click', function(e) { that.nextImage(); });
					this.center.appendChild(tempNext);
					
					bm.addevent(this.container, 'mouseover', function(e) { keypressLeft= that.previousImage; keypressRight= that.nextImage; });
					bm.addevent(this.container, 'mouseout', function(e) { keypressLeft= null; keypressRight= null; });
				}
			}
			
			this.openImage= function(image)
			{
				if (image == this.activeImage) return;
				
				if (this.activeImage != null) bm.fadeto(this.activeImage, 10, 100);
				
				bm.moveto(this.slider, 'left', image.sliderPosition*(-1)+Math.round(this.container.offsetWidth/2));
				bm.fadeto(image, 100, 20);
				this.activeImage= image;
			}
			
			this.nextImage= function()
			{
				that.openImage(that.activeImage.nextSibling);
				
				var old= that.slider.firstChild;
				var temp= that.createImage({url: old.url, width: old.width, color: old.color});
				temp.marginLeft= that.slider.lastChild.marginLeft+that.slider.lastChild.width;
				temp.style.marginLeft= temp.marginLeft+'px';
				temp.sliderPosition= that.slider.lastChild.marginLeft+that.slider.lastChild.width+Math.round(temp.width/2);
				that.slider.appendChild(temp);
				that.slider.removeChild(that.slider.firstChild);
				
			}
			
			this.previousImage= function()
			{
				that.openImage(that.activeImage.previousSibling);
				
				var old= that.slider.lastChild;
				var temp= that.createImage({url: old.url, width: old.width, color: old.color});
				temp.marginLeft= that.slider.firstChild.marginLeft-temp.width;
				temp.style.marginLeft= temp.marginLeft+'px';
				temp.sliderPosition= that.slider.firstChild.marginLeft-temp.width+Math.round(temp.width/2);
				that.slider.insertBefore(temp, that.slider.firstChild);
				that.slider.removeChild(that.slider.lastChild);
			}
		
			this.createImage= function(image)
			{
				var temp= document.createElement('img');
				temp.src= image.url;
				temp.url= image.url;
				temp.height= 240;
				temp.width= image.width;
				temp.color= image.color;
				bm.fadeto(temp, 10, 0);
				//bm(temp).addevent('click', function(evt) { alert(evt.currentTarget.color); });
				
				return temp;
			}
			
			this.init();
		}
		
		
	}
	
	



