window.addEvent('domready', function() {
	
	// gestione centratura per visualizzazione corretta barra stage
	var left2Center = (getWidth() - $$('div.pagina').getWidth()) / 2;

	if ($('iStage')) {
		var stage = $('iStage');
		stage.setStyle('top', '-40px');
		var morph = new Fx.Morph('iStage');
		var pos = 'close';
		
		$$('a.openClose').addEvent('click', function(e) {
			if (pos == 'close') {
				e.stop();
				morph.start({
					top: '0'
				});
				$$('a.openClose img').set('src', '/skinAdmin/entigo/widgets/ico-stage2.gif');
				pos = 'open';
			} else {
				e.stop();
				morph.start({
					top: '-40px'
				});
				$$('a.openClose img').set('src', '/skinAdmin/entigo/widgets/ico-stage.gif');
				pos = 'close';
			}
		});
	}
	
	$$('div.pagina').setStyle('position', 'absolute');
	$$('div.pagina').setStyle('left', left2Center);
	$$('div.pagina').setStyle('margin', '0');
	
	// gestione paginazione testo due colonne
	if ($$('twoCols')) {
		
		$$('div.colonna').each(function(el) {
			el.set('opacity', 0);
			el.setStyle('display', 'block');
		});		
						
		$$('div.pair1').each(function(el) {
			el.morph({
				'opacity': 1
			});
		});
		
		if ($('iStage')) {
			$$('div.colonna').each(function(el) {
				if (el.getScrollHeight() > el.getHeight()) {
					el.setStyle('overflow', 'auto');
					el.setStyle('background-color', '#ffc');
				}
			});
		}
		
		$$('a.pag').each(function(el) {
			
			var num = el.innerHTML;			
			
			el.addEvents({
				click: function(){
					$$('div.colonna').each(function(el) {
						el.morph({
							'opacity': 0
						});
					});					
					$$('div.pair'+num).each(function(el) {
						el.morph({
							'opacity': 1
						});
					});
				}
			});
			
		});
		
	}	
});

window.addEvent('scroll', function() {
	
	// gestione centratura per visualizzazione corretta barra stage
	var left2Center = (getWidth() - $$('div.pagina').getWidth()) / 2;
	$$('div.pagina').setStyle('position', 'absolute');
	$$('div.pagina').setStyle('left', left2Center);
	$$('div.pagina').setStyle('margin', '0');
	
});

window.addEvent('resize', function() {
	
	// gestione centratura per visualizzazione corretta barra stage
	var left2Center = (getWidth() - $$('div.pagina').getWidth()) / 2;	
	$$('div.pagina').setStyle('position', 'absolute');
	$$('div.pagina').setStyle('left', left2Center);
	$$('div.pagina').setStyle('margin', '0');
	
});