﻿<!--
Lightware.Gallery={
	Images:new Array(),
	SelectedImage:null,
	Window:null,
	Display:null,
	ImageIndex:0,
	Init:function(){
		var element=Lightware.$('LwGallery');
		var links=element.getElementsByTagName('a');
		for(var i=0;i<links.length;i++){
			var click=links[i].onclick.toString();
			var matches=click.match(/ShowImage\(([^)]+)\)/);
			this.Images[this.Images.length]=matches[1].split(',');
			this.Images[this.Images.length-1][0]=this.Images[this.Images.length-1][0].substr(1,this.Images[this.Images.length-1][0].length-2);
		}
	},
	ShowImage:function(Image,Width,Height,DownloadImage){
		this.SelectedImage=new Array(Image,Width,Height,DownloadImage);
		if (this.Window!=null){
			document.getElementsByTagName('body')[0].removeChild(this.Window);
			this.Window=null;
		}
		var position=Lightware.GetMiddleOfScreen();
		this.Window=document.createElement('div');
		this.CreateWindowHeader();
		this.Window.className='LwGallery_Window';
		this.Window.style.left=(position[0]-Math.floor(this.SelectedImage[1]/2))+'px';
		this.Window.style.top=(position[1]-Math.floor(this.SelectedImage[2]/2))+'px';
		var image=document.createElement('img');
		image.src=Image;
		image.width=Width;
		image.height=Height;
		image.border=0;
		image.style.display='block';
		image.onclick=function(){
			Lightware.Gallery.CloseWindow();
		}
		this.Window.appendChild(image);
		this.CreateWindowFooter();
		document.getElementsByTagName('body')[0].appendChild(this.Window);
		this.CenterWindow();
	},
	CenterWindow:function(){
		if (this.Window!=null){
			var position=Lightware.GetMiddleOfScreen();
			this.Window.style.left=(position[0]-Math.floor(this.SelectedImage[1]/2))+'px';
			this.Window.style.top=(position[1]-Math.floor(this.SelectedImage[2]/2))+'px';
			setTimeout('Lightware.Gallery.CenterWindow()',100);
		}
	},
	CloseWindow:function(){
		if (this.Window!=null){
			document.getElementsByTagName('body')[0].removeChild(this.Window);
			this.Window=null;
			this.SelectedImage=null;
		}
	},
	CreateWindowHeader:function(){
		var header=document.createElement('div');
		header.className='LwGallery_Header';
		this.Window.appendChild(header);
/*
		if (this.SelectedImage.length==4 && this.SelectedImage[3]!=null){
			var download=document.createElement('a');
			download.href="DownloadImage.php?image="+trim(this.SelectedImage[3]);
			download.appendChild(document.createTextNode('download'));
			header.appendChild(download);
		}
*/
		var close=document.createElement('a');
		close.onclick=function(){
			Lightware.Gallery.CloseWindow();
		}
		close.appendChild(document.createTextNode('schliessen'));
		header.appendChild(close);
	},
	CreateWindowFooter:function(){
		var footer=document.createElement('div');
		footer.className='LwGallery_Footer';
		this.Window.appendChild(footer);
		var previous=document.createElement('a');
		previous.onclick=function(){
			Lightware.Gallery.PreviousImage();
		}
		previous.appendChild(document.createTextNode('zurück'));
		footer.appendChild(previous);
		var middle=document.createElement('span');
		middle.className='LwGallery_Display';
		var nr=1;
		for(var i=0;i<this.Images.length;i++){
			if(this.SelectedImage[0]==this.Images[i][0]){
				this.ImageIndex=i;
				nr=i+1;
				break;
			}
		}
		middle.appendChild(document.createTextNode(nr+' / '+this.Images.length));
		footer.appendChild(middle);
		var next=document.createElement('a');
		next.onclick=function(){
			Lightware.Gallery.NextImage();
		}
		next.appendChild(document.createTextNode('weiter'));
		footer.appendChild(next);
	},
	NextImage:function(){
		this.ImageIndex++;
		if (this.ImageIndex>=this.Images.length) this.ImageIndex=0;
		var download=null;
		if (isset(this.Images[this.ImageIndex][3])) download=this.Images[this.ImageIndex][3];
		this.ShowImage(this.Images[this.ImageIndex][0],this.Images[this.ImageIndex][1],this.Images[this.ImageIndex][2],download);
	},
	PreviousImage:function(){
		this.ImageIndex--;
		if (this.ImageIndex<0) this.ImageIndex=this.Images.length-1;
		var download=null;
		if (isset(this.Images[this.ImageIndex][3])) download=this.Images[this.ImageIndex][3];
		this.ShowImage(this.Images[this.ImageIndex][0],this.Images[this.ImageIndex][1],this.Images[this.ImageIndex][2],download);
	}
}
//-->