Ajax.Responders.register({
	  onCreate: function(){
		loader('on');
	  }, 
	  onComplete: function(){
		  loader('off');
	  }
	});


Event.observe(window, 'load', function() {
	centra_splash()
		$('body2').setStyle({visibility: 'visible'});

	$('centro_pagina').observe('click', function(event){
		
	});
	function appari_index(){
		/*
		 new Effect.Morph('body2', {style: 'background: #ffffff', duration: 1});
		 new Effect.Appear('container',{style: 'opacity: 1' , duration: 1});	
		 $('container_splash').setStyle({display: 'none'})
		 */
		document.location.href='/newsite/index2/lang:' + time();
		
	}
	$('lingua_italiano').observe('click', function(event){
		sipario();
		refresh_lingua.delay(2, 'ita');
	});
	
 	$('lingua_inglese').observe('click', function(event){
		sipario();
		refresh_lingua.delay(2, 'eng');
	});
 	
	$('lingua_russo').observe('click', function(event){
		sipario();
		refresh_lingua.delay(2, 'rus');
	});
	
	$('lingua_spagnolo').observe('click', function(event){
		sipario();
		refresh_lingua.delay(2, 'esp');
	});
	
});
function sipario() {
	var winHeight = document.viewport.getHeight();
	altezza_centrale=(winHeight*1)-178;

	new Effect.Parallel(
	[ 
	 new Effect.Morph('splash_lingue', {sync: true, style: 'opacity:0', duration: 1}),
	 new Effect.Morph('img_up', {sync: true, style: 'opacity:0', duration: 1}),
	 new Effect.Morph('img_dw', {sync: true, style: 'opacity:0', duration: 1})
	 ],
	 	{
		 	transition: Effect.Transitions.linear,
		 	duration: 1
	 	}
	)
	sipario2.delay(1)
}
function sipario2() {

	new Effect.Parallel(
			[ 
			 new Effect.Morph('contenitore_moneta_up', {sync: true, style: 'height:' + 77 + 'px', duration: 2}) ,
			 new Effect.Morph('contenitore_moneta_up', {sync: true, style: 'margin-top:' + 0 + 'px', duration: 2}) ,
			 new Effect.Morph('contenitore_moneta_center', {sync: true, style: 'height:' + altezza_centrale + 'px', duration: 2}),  
			 new Effect.Morph('contenitore_moneta_down', {sync: true, style: 'height:' + 95 + 'px', duration: 2})


			 ],
	 	{
		 	transition: Effect.Transitions.linear,
		 	duration: 2
	 	}
	)
	// appari_index.delay(2);
	
}

function refresh_lingua(lingua) {
	document.location.href='/newsite/lingua/'+lingua;
}

function centra_splash() {
	altezza_tot=document.viewport.getHeight();
	larghezza_tot=document.viewport.getWidth();
	var alto=((document.viewport.getHeight()*1)-400)/2;
	var sinistra=((document.viewport.getWidth()*1)-400)/2;
	$('centro_pagina').setStyle({
		});
	$('contenitore_moneta_up').setStyle({
		width: larghezza_tot + 'px',
		marginTop: alto + 'px' 
		});
	$('contenitore_moneta_down').setStyle({
		width: larghezza_tot + 'px'
		});
	$('contenitore_moneta_center').setStyle({
		width: larghezza_tot + 'px'
		});
	$('container_splash').setStyle({
		width: larghezza_tot + 'px', 
		height: altezza_tot + 'px' 
	});
	immagine_up=$$('.moneta_up img');
	immagine_dw=$$('.moneta_down img');
	// alert(immagine_up[0].getStyle('marginLeft'));
	// alert(immagine_up[0].getStyle('width'));
	 
	for (i=0; i < immagine_up.length; i++) {
		if(immagine_up[0].getStyle('marginLeft')==null) {
			ml='0px';
		} else {
			ml=$(immagine_up[i]).getStyle('marginLeft');
		}
		w=$(immagine_up[i]).getStyle('width')
		 if(w.indexOf('px')>0) {w=w.substring(0,w.length-2);}
		 if(ml.indexOf('px')>0) {ml=ml.substring(0,ml.length-2);}
		 margine=((larghezza_tot*1)-w)/2;
		 $(immagine_up[i]).setStyle({ marginLeft: margine + 'px'})
		 
	}
	 for (i=0; i < immagine_dw.length; i++) {
			if(immagine_dw[0].getStyle('marginLeft')==null) {
				ml='0px';
			} else {
				ml=$(immagine_dw[i]).getStyle('marginLeft');
			}
		 w=$(immagine_dw[i]).getStyle('width')
		 if(w.indexOf('px')>0) {w=w.substring(0,w.length-2);}
		 if(ml.indexOf('px')>0) {ml=ml.substring(0,ml.length-2);}
		 margine=((larghezza_tot*1)-w)/2;
		 $(immagine_dw[i]).setStyle({ marginLeft: margine + 'px'})
}
	$('riga_lingue').setStyle({marginLeft: ((larghezza_tot*1)-760)/2  + 'px', marginTop: '50px'});
	$('body2').setStyle({width: larghezza_tot  + 'px'});
	$('body2').setStyle({height: altezza_tot + 'px' });
}
