
function addLocalLinkEvent(el) {
	el.addEvent('click', function(e) {
		new Event(e).stop();
		glayout.loadSheet(el.href);
	});
}

var glayout;

var Layout = new Class({
	initialize: function() {
		this.contentfx = $('content').effects({duration: 500, transition: Fx.Transitions.Quart.easeOut});
		this.schildfx = $('schild').effects({duration: 500, transition: Fx.Transitions.Quart.easeOut});
		this.navfx = $('navigation').effects({duration: 500, transition: Fx.Transitions.Quart.easeOut});
		this.hidenavtimer = undefined;
	},
	
	loadSheet: function(url) {
		this.contentfx.start({
			'opacity': 0
		}).chain(function() {
			// clear contents
			$('content').empty();

			// ajax request
			new Ajax(url, {
				method: 'get',
				update: $('content'),
				evalScripts: true,
				onComplete: glayout.rewriteLinks
			}).request();

			// show me
			this.start({
				'opacity': 1
			});
		});
	},
	
	showNav: function() {
		this.hideNavTclear();
		$('inactivetext').setStyle('display', 'none');
		$('navigation').setStyle('display', '');
		this.schildfx.start({'height': '380px;'});
		this.navfx.start({'display': 'block', 'height': '170px'});
	},
	hideNav: function() {
		$('inactivetext').setStyle('display', '');
		$('schild').setStyle('height', '215px');
		$('navigation').setStyle('height', '10px');
		$('navigation').setStyle('display', 'none');
	},
	hideNavT: function() {
		this.hidenavtimer = this.hideNav.delay(1300);
	},
	hideNavTclear: function() {
		$clear(this.hidenavtimer);
	},
	rewriteLinks: function() {
		// rewrite links to open locally
		var links = $$($('content').getElementsByTagName('a'));
		links.each(function(element) {
			if (!element.hasClass('extern'))
				addLocalLinkEvent(element);
		});
	}

});

if ((document.all) && (navigator.userAgent.indexOf('Opera')== -1))  {
	// IE -- do nothing. no js for ie. fucking ie. go away. error. error. does not compute. ##@@#!@
} else {
	window.addEvent('domready', function() {
		glayout = new Layout();
	/*	
		$$('.menuitem').each(function(element) {
			element.addEvent('click', function() {
				var el_id = element.id;
				var itemname = el_id.substr(el_id.indexOf('_') + 1);
				var url = 'content/'+itemname.replace(/_/g, '/')+'.php';
				glayout.loadSheet(url);
			});
		});
	*/	
		$('schild').addEvent('mouseenter', function() {
			glayout.showNav();
		});

		$('schild').addEvent('mouseleave', function() {
			glayout.hideNavT();
		});

		$('biene').addEvent('click', function() {
			glayout.loadSheet('/foo.html');
		});

		glayout.hideNav();
	});
}

