window.addEvent('domready', function(){
	var diffY = 10;
	var allowResizing = true;
	var wsize = window.getCoordinates();
	var csize = $('pages_margins').getCoordinates();
	var colSize = $('col').getCoordinates();
	var nHeight = wsize.height-(csize.height-colSize.height)-diffY;
	$('col').setStyle('height', nHeight +'px');
	
	var currentCol = $('col');
	
	window.addEvent('resize', function(){
		if(allowResizing){
			var wsize = window.getCoordinates();
			var csize = $('pages_margins').getCoordinates();
			var colSize = currentCol.getCoordinates();
			var nHeight = wsize.height-(csize.height-colSize.height)-diffY;
			currentCol.setStyle('height', nHeight +'px');
		}
	});

	
	
	$$('.submenu').each(function(sub, idx_sub){
		sub.getElements('a.h1').addEvent('click', function(event){
			allowResizing = false;
			event.stop();
			if(!this.hasClass('current')){
				var tmpcol = new Element('div', {
					'styles':{
						'background-image': 'url(fileadmin/images/loading.gif)',
						'background-position' : 'center',
						'background-repeat' : 'no-repeat',
						'height': 0
					}
				});
				tmpcol.injectAfter(sub);
				$$('.submenu a.h1').removeClass('current');
				this.addClass('current');
				
				var h = currentCol.getCoordinates().height;
				new Fx.Morph(tmpcol).start({height: [0, h]});
				var currentColMorph = new Fx.Morph(currentCol);
				currentColMorph.start({height: [h, 0]}).chain(function(){
					window.location = this.getProperty('href');
					allowResizing = true;
				}.bind(this));
				
				/*
				new Fx.Slide(tmpcol).hide();
				new Fx.Slide(currentCol).slideOut();
				new Fx.Slide(tmpcol).slideIn().chain(function(){
					window.location = this.getProperty('href');
					allowResizing = true;
				}.bind(this));
				*/
				
				currentCol = tmpcol;
			}else{
				window.location = this.getProperty('href');
			}
		});
	});
	
});
