var isEmpty = function(el) {
     var empty = 0;
     if(el!=null){
	     if(el.getChildren().length > 0){     	
	     	el.getChildren().each(function(a){
	     		if(a.getChildren().length > 0){
	     			a.getChildren().each(function(b){
	     				if(b.get('html').trim().length > 0 || b.get('text').trim().length > 0){
	     					empty = 1;
	     				}
	     			});
	     		}
	     	});
	     }
     }
     else{empty=-1;}
     return empty;
};

window.addEvent('domready', function() {

//Mittleren/Rechten/Linken Inhaltsbereich anzeigen/ausblenden
var totalWidth = 98;
var rightInnerWidth = 20;
var leftInnerWidth = 20;
var colSpace = 2;
var mainBorder = 2;

var leftIsEmpty = isEmpty($('left'));
var rightIsEmpty = isEmpty($('right'));
var mainIsEmpty = isEmpty($('main_outer'));

if(leftIsEmpty < 1 && rightIsEmpty < 1 && mainIsEmpty < 1){
	if(leftIsEmpty == 0) $('left').setStyle('display', 'none');
	if(rightIsEmpty == 0) $('right').setStyle('display', 'none');
	if(mainIsEmpty == 0) $('main_outer').setStyle('display', 'none');
}
else if(leftIsEmpty < 1 && rightIsEmpty < 1 && mainIsEmpty > 0){
	if(leftIsEmpty == 0) $('left').setStyle('display', 'none');
	if(rightIsEmpty == 0) $('right').setStyle('display', 'none');
	$('main_outer').setStyles({
	    display: 'block',
	    width: totalWidth - mainBorder + '%'
	});
}
else if(leftIsEmpty < 1 && rightIsEmpty > 0 && mainIsEmpty > 0){
	if(leftIsEmpty == 0) $('left').setStyle('display', 'none');
	$('right').setStyles({
	    display: 'block',
	    width: rightInnerWidth + '%'
	});
	$('main_outer').setStyles({
	    display: 'block',
	    width: totalWidth-mainBorder-rightInnerWidth-colSpace,
	    'margin-right': colSpace + '%'
	});

}
else if(leftIsEmpty > 0 && rightIsEmpty > 0 && mainIsEmpty > 0){
	$('left').setStyles({
	    display: 'block',
	    width: leftInnerWidth + '%'
	});
	$('right').setStyles({
	    display: 'block',
	    width: rightInnerWidth + '%'
	});
	$('main_outer').setStyles({
	    display: 'block',
	    width: totalWidth-mainBorder-rightInnerWidth-leftInnerWidth-colSpace-colSpace + '%',
	    'margin-right': colSpace + '%',
	    'margin-left': colSpace + '%'
	});

}
else if(leftIsEmpty > 0 && rightIsEmpty < 1 && mainIsEmpty > 0){
	if(rightIsEmpty == 0) $('right').setStyle('display', 'none');
	$('left').setStyles({
	    display: 'block',
	    width: rightInnerWidth + '%'
	});
	$('main_outer').setStyles({
	    display: 'block',
	    width: totalWidth-mainBorder-leftInnerWidth-colSpace + '%',
	    'margin-left': colSpace+ '%'
	});

}
else if(leftIsEmpty > 0 && rightIsEmpty > 0 && mainIsEmpty < 1){
	if(mainIsEmpty == 0) $('main_outer').setStyle('display', 'none');
	$('left').setStyles({
	    display: 'block',
	    width: totalWidth/2-colSpace/2-mainBorder + '%',
	    'margin-right': colSpace + '%'
	});
	$('right').setStyles({
	    display: 'block',
	    width: totalWidth/2-colSpace/2-mainBorder + '%'
	});

}
else if(leftIsEmpty > 0 && rightIsEmpty < 1 && mainIsEmpty < 1){
	if(mainIsEmpty == 0) $('main_outer').setStyle('display', 'none');
	if(rightIsEmpty == 0) $('right').setStyle('display', 'none');
	$('left').setStyles({
	    display: 'block',
	    width: totalWidth-mainBorder + '%'
	});

}
else if(leftIsEmpty < 1 && rightIsEmpty > 0 && mainIsEmpty < 1){
	if(mainIsEmpty == 0) $('main_outer').setStyle('display', 'none');
	if(leftIsEmpty == 0) $('left').setStyle('display', 'none');
	$('right').setStyles({
	    display: 'block',
	    width: totalWidth-mainBorder + '%'
	});
}
});
