

 var infoboxes;


 function page_init()
 {
	infoboxes= new infoboxes_class();
	bm.execute(bm.get(document, 'div', 'imageviewer'), function(e) { new imageviewer_class(e); });
	bm.addevent(document.getElementById('zoom'), 'click', function(e) { if (e.target.className != 'right' && e.target.className != 'left') bm.fadeout(document.getElementById('zoom')); });
 }
 
 
 
 function infoboxes_class()
 {
 	this.opened= '';
 	
 	this.init= function()
 	{
 		bm.execute(bm.get(document, 'div', 'bar'), function (e) { bm.get(e, 'div', 'info')[0].style.display= 'none'; bm.addevent(e, 'mouseover', function() { infoboxes.open(e); }); bm.addevent(e, 'mouseout', function(ev) { infoboxes.close(ev); }); });
 	}
 	
 	this.open= function(e)
 	{
 		if (e == this.opened) return;
 		
 		this.opened= e;
 		i= bm.get(e, 'div', 'info')[0];
 		bm.fadein(i);
 		i.style.minHeight= 0;
 		bm.moveto(i, 'height', 570, 0);
 	}
 	
 	this.close= function(ev)
 	{
 		if (this.opened == '' || !bm.nochild(this.opened, ev)) return;
 		bm.timer.removework(bm.get(this.opened, 'div', 'info')[0]);
 		bm.get(this.opened, 'div', 'info')[0].style.display= 'none';
 		this.opened= '';
 	}
 	
 	this.init();
 }





 function imageviewer_class(e)
 {
 	var that= this;
 	this.e= e;
 	this.active= 0;
 	this.imageCount= 0;
 	this.images= [];
 	this.imageTexts= [];
	
	this.zoomsym= document.createElement("p");
	e.appendChild(this.zoomsym);
	bm.fadeto(this.zoomsym, 1, 0);
	bm.addevent(this.zoomsym, 'mouseover', function(evt) { bm.fadeto(that.zoomsym, 100); });
	bm.addevent(this.zoomsym, 'mouseout', function(evt) { bm.fadeto(that.zoomsym, 1); });
	bm.addevent(this.zoomsym, 'click', function(evt) { that.zoom.init(that.active); });
 	
	bm.execute(bm.get(e, 'div'), function(ev)
	{
		ev.style.display= 'none';
		that.imageCount++;
		that.images.push(bm.get(ev, 'img')[0].src.split('&box')[0]);
		that.imageTexts.push(bm.get(ev, 'span')[0].innerHTML);
	});
	
	if (this.imageCount > 1)
	{
		var link1= document.createElement("a");
		link1.className= 'left';
		link1.href= 'javascript:void(0)';
		bm.addevent(link1, 'click', function(ev) { that.previousImage(); });
		e.appendChild(link1);
		var link2= document.createElement("a");
		link2.className= 'right';
		link2.href= 'javascript:void(0)';
		bm.addevent(link2, 'click', function(ev) { that.nextImage(); });
		e.appendChild(link2);
	}
	
	
	this.openImage= function(nr)
	{
		bm.execute(bm.get(this.e, 'div'), function(ev, x)
		{
			if (x == nr) bm.fadeto(ev, 100, 0);
			else bm.fadeto(ev, 0, 0);
		});
	}
	
	this.previousImage= function()
	{
		this.active--;
		if (this.active < 0) this.active= this.imageCount-1;
		this.openImage(this.active);
	}
	
	this.nextImage= function()
	{
		this.active++;
		if (this.active > this.imageCount-1) this.active= 0;
		this.openImage(this.active);
	}
	
	function zoomClass(images, imageTexts)
	{
		var that2= this;
		this.zoomBox= document.getElementById('zoom');
		this.images= images;
		this.imageTexts= imageTexts;
		this.imageCode= 0;
		this.active= 0;
		
		
		this.init= function(nr)
		{
			this.clear();
			if (this.images.length > 1)
			{
				var link1= document.createElement("a");
				link1.className= 'left';
				link1.href= 'javascript:void(0)';
				bm.addevent(link1, 'click', function(ev) { that2.previousImage(); });
				this.zoomBox.appendChild(link1);
				var link2= document.createElement("a");
				link2.className= 'right';
				link2.href= 'javascript:void(0)';
				bm.addevent(link2, 'click', function(ev) { that2.nextImage(); });
				this.zoomBox.appendChild(link2);
			}
			bm.fadein(this.zoomBox);
			this.open(nr);
		}
		
		this.clear= function()
		{
			if (this.zoomBox.hasChildNodes()) while (this.zoomBox.childNodes.length >= 1) this.zoomBox.removeChild(this.zoomBox.firstChild);
		}
		
		this.clean= function()
		{
			bm.execute(bm.get(this.zoomBox, 'div'), function(ev) { that2.zoomBox.removeChild(ev) });
			bm.execute(bm.get(this.zoomBox, 'img'), function(ev) { that2.zoomBox.removeChild(ev) });
		}
		
		this.open= function(nr)
		{
			this.active= nr;
			this.activeCode= Math.random();
			this.clean();
			var loader= document.createElement("div");
			loader.className= 'loader';
			this.zoomBox.appendChild(loader);
			var img= new Image();
			img.src= this.images[nr]+'&box='+Math.round(window.innerWidth*0.8)+','+Math.round(window.innerHeight*0.8);
			img.id= this.activeCode;
			img.nr= nr;
			bm.addevent(img, 'load', function(ev)
			{
				if (that2.activeCode != ev.target.id) return;
				that2.clean();
				ev.target.style.marginLeft= -Math.round(ev.target.width/2)+'px';
				ev.target.style.marginTop= -Math.round(ev.target.height/2)+'px';
				that2.zoomBox.appendChild(ev.target);
				bm.fadein(ev.target);
				if (that2.imageTexts[ev.target.nr] != '')
				{
					var text= document.createElement("div");
					text.innerHTML= that2.imageTexts[ev.target.nr];
					text.className= 'text';
					that2.zoomBox.appendChild(text);
					//text.style.left= Math.round(window.innerWidth/2-text.offsetWidth/2)+'px';
					bm.moveto(text, 'bottom', 0, -200);
				}
			});
		}
	
		this.previousImage= function()
		{
			this.active--;
			if (this.active < 0) this.active= this.images.length-1;
			this.open(this.active);
		}
		
		this.nextImage= function()
		{
			this.active++;
			if (this.active > this.images.length-1) this.active= 0;
			this.open(this.active);
		}
	}
	
	this.zoom= new zoomClass(this.images, this.imageTexts);
	this.openImage(0);
 }



 
 
 
 function mail(tl, sl, nm)
 {
 	document.location.href= 'mailto:'+nm+'@'+sl+'.'+tl;
 }



