var zbahn = {
	galleryimages: $H(),
	currentimage: false,
	initpage: function()
	{
		$('menu-top').down('ul').childElements().each(function(li) {
			li.down('a').observe('mouseover', function(e) {
				if (e.element().nodeName.toLowerCase() != 'a') return;
				var el = (e.element().next('ul') ? e.element().next('ul').identify() : false);
				//alert(zbahn.menuanimatingel);
				if (zbahn.menuanimating || zbahn.activemenu == el) return;
				if (zbahn.activemenu && zbahn.activemenu != el) {
					Effect.BlindUp(zbahn.activemenu, {
						duration: 0.3
					});
					zbahn.activemenu = false;
				}
				if (!e.element().next('ul')) return;
				zbahn.menuanimating = true;
				zbahn.menuanimatingel = el;
				Effect.BlindDown(e.element().next('ul'), {
					duration: 0.3,
					afterFinish: function() { zbahn.menuanimating = false; zbahn.activemenu = zbahn.menuanimatingel; zbahn.menuanimatingel = false; }
				});
			});
		});
		
		var firstimg = false;
		var i = 0;
		
		if ($('content-top')) {
			$('content-top').select('.gallery').each(function(g) {
				g.select('a').each(function(a) {
					i++;
					this.galleryimages.set(a.readAttribute('href'), i);
					if (!firstimg) {
						$('bg').update(new Element('div').setStyle({'position':'relative', 'height':'740px'}).insert(new Element('img', {'src':a.readAttribute('href'),'id':'gimg-'+i}).setStyle({'position':'absolute'})));
						firstimg = true;
						this.currentimage = 'gimg-'+i;
					}
					a.observe('click', function(e) {
						e.stop();
						var i = this.galleryimages.get(a.readAttribute('href'));
						if (this.currentimage == 'gimg-'+i) return;
						
						$(this.currentimage).fade();
						this.currentimage = 'gimg-'+i;
						if ($(this.currentimage)) {
							$(this.currentimage).appear();
						} else {
							$('bg').down('div').insert(new Element('img', {'src':a.readAttribute('href'),'id':'gimg-'+i}).setStyle({'position':'absolute'}).hide().observe('load', function() {
								$(this.currentimage).appear();
							}.bindAsEventListener(this)));
						}
					}.bind(this));
				}, this);
			}, this);
		}
	}
};

document.observe('dom:loaded', zbahn.initpage.bindAsEventListener(zbahn));

