	var galerie_layer = function(){
		// container
		this.container = document.createElement('div');
		this.container.style.display = 'none';
		this.container.id="galerys";
		
			// layer
			layer= document.createElement('div');
			layer.className = 'layer';
			layer.parent=this;
			layer.onclick=function(){this.parent.container.style.display= 'none'};
			this.container.appendChild(layer);
			
			// content box
			this.contentbox = document.createElement('div');
			this.contentbox.className = 'contentbox';
			this.container.appendChild(this.contentbox);	
		
				// image container
				this.imagecontainer = document.createElement('div');
				this.imagecontainer.className = 'imagecontainer';
				this.contentbox.appendChild(this.imagecontainer);		
				
				// navigation bar
				this.navbar = document.createElement('div');
				this.navbar.className = 'navbar';
				this.contentbox.appendChild(this.navbar);		
				
					// nav elements
					// field img number
					this.field_img_num = document.createElement('span');
					this.field_img_num.className = 'img_num';
					this.field_img_anz = document.createElement('span');
					this.field_img_anz.className = 'img_anz';
					this.field_img_alt = document.createElement('div');
					this.field_img_alt.className = 'img_alt';
					
					this.field_img_alt_bg = document.createElement('div');
					this.field_img_alt_bg.className = 'img_alt_bg';
					
					
					this.contentbox.appendChild(this.field_img_alt_bg);
					this.contentbox.appendChild(this.field_img_alt);
					
					button_con1   = document.createElement('span');
					button_con1.className = 'button_con1';
					
					button_con2   = document.createElement('span');
					button_con2.className = 'button_con2';

					this.button_prev 	 = document.createElement('a');
					this.button_next 	 = document.createElement('a');
					this.button_close	 = document.createElement('a');
												

					this.navbar.appendChild(Bild);
					this.navbar.appendChild(this.field_img_num);		
					this.navbar.appendChild(von);
					this.navbar.appendChild(this.field_img_anz);		
					
					
					this.navbar.appendChild(button_con1);
						button_con1.appendChild(this.button_prev);		
							this.button_prev.appendChild(weiter);
						
						button_con1.appendChild(trenn);
						
						button_con1.appendChild(this.button_next);		
							this.button_next.appendChild(zurueck);
					
					
					this.navbar.appendChild(button_con2);		
						button_con2.appendChild(this.button_close);		
							this.button_close.appendChild(img_close);
						
						this.button_close.parent = this;
						this.button_close.onclick=function(){this.parent.container.style.display= 'none'};
					
		document.lastChild.lastChild.appendChild(this.container);
					
	}
	var galery =	function(gal_id, start){
			
			if(!window.layer){
				window.layer = new galerie_layer();
			}
			this.layer = window.layer;			
			this.id=gal_id;

			this.img_num = start;			
			this.img_anz = 0;
			this.images = new Array();
			
			
			// function open
			this.open = function(){
			
			if(this.img_anz == 0){alert('galery empty'); return -1;};
			
			this.layer.field_img_anz.innerHTML = this.img_anz;
			this.layer.field_img_num.innerHTML = this.img_num;
			
			//if( this.img_num == 1 ) this.set_func_prev_off();
			//if( this.img_num > 1 ) this.set_func_prev_on();
			//if( this.img_num < this.img_anz ) this.set_func_next_on();
			//if( this.img_num == this.img_anz ) this.set_func_next_off();
			 this.set_func_prev_on();
			 this.set_func_next_on();
			
			this.layer.imagecontainer.innerHTML='';
			this.layer.imagecontainer.appendChild(this.images[this.img_num]);
			
			this.layer.imagecontainer.parent = this;
			this.layer.imagecontainer.onclick = function(){this.parent.nextImage()};
			
			
			if(this.images[this.img_num].alt.length > 2){
				this.layer.field_img_alt_bg.style.display='block';
				this.layer.field_img_alt.innerHTML = this.images[this.img_num].alt;
				this.layer.field_img_alt_bg.innerHTML = this.images[this.img_num].alt;
			}
			else{
				this.layer.field_img_alt_bg.style.display='none';
				this.layer.field_img_alt.innerHTML = '';
			}
			
			

				this.layer.container.style.display = 'block';
			}	
							
			this.set_func_prev_off = function(){
				this.layer.button_prev.className = 'off';
				this.layer.button_prev.onclick = function(){};
			}
			
			this.set_func_prev_on = function(){
				this.layer.button_prev.className = 'on';
				this.layer.button_prev.parent = this;
				this.layer.button_prev.onclick = function(){this.parent.prevImage()};
				
			}
			this.set_func_next_off = function(){
				this.layer.button_next.className = 'off';
				this.layer.button_next.onclick = function(){};
			}
			this.set_func_next_on = function(){
				this.layer.button_next.className = 'on';
				this.layer.button_next.parent = this;
				this.layer.button_next.onclick = function(){this.parent.nextImage()};
			}
			
			this.nextImage = function(){
				if(this.img_num < this.img_anz)
					this.img_num = this.img_num+1;
				else if(this.img_num == this.img_anz)
					this.img_num = 1;
				
				this.open();
			}
			
			this.prevImage = function(){
				if(this.img_num > 1)
					this.img_num = this.img_num-1;
				else if(this.img_num == 1)
					this.img_num = this.img_anz;

				this.open();
			}
			
			this.addImage = function(tsrc, talt, ow, oh){
				img = document.createElement('img');
				img.src=tsrc;
				img.alt=talt;
								
				//theight = 585;
				tw = 780;
				th = 585;
				if(ow || oh){
					or = ow/oh;
					tr = tw/th;
					if(tr > or){
						nh = th;
						nw = or * th ;
					}else{
						nh = tw / or;
						nw = tw; 
					}
					if(nh > th) nh = th;
					if(nw > tw) nw = tw;
		
					if(nw < tw){
						img.style.marginLeft = ((tw-nw)/2)+'px';		
					}
					if(nh < th){
						img.style.marginTop = ((th-nh)/2)+'px';		
					}
		
				}else {
					nw = tw;
					nh = th;
				}
				img.width = nw;
				img.height = nh;
								
				this.images[this.img_anz+1] = img;
				this.img_anz++;
			}
			

			
	}
