
function loadCenterBox() {
	//new Effect.Opacity('main', { from: 1.0, to: 0.7, duration: 0.0 });
	//setSizeMainLancio();
	goToMain(0);

}




var mainElement;
var mainLancioElement;
var marginHide =0;
var marginShow = 0;
var currentElement = null;
var timerId;

function goToMain(i) {
	mainElement = $$('.mainCenter')[i];
	mainLancioElement = $$('.lancioMain')[i];
	mainImageElement = $$('.imageMain')[i];
    mainTitoloElement = $$('.titoloMain')[i]
	
	if(currentElement != null) {
		$$('.articoloBox')[currentElement].hide({duration: 2.0});
        $$('.mainMenu')[currentElement].className = "mainMenu";
//		new Effect.Morph($$('.mainMenu')[currentElement], { style: 'current', transition: Effect.Transitions.reverse, afterFinish: function() {$$('.mainMenu')[temp].className = "mainMenu"}});
		currentElement = i;
		clearTimeout(timerId);
	} else {
		currentElement = i;
	}
//	new Effect.Morph($$('.mainMenu')[i], { style: 'current'});
    $$('.mainMenu')[i].className = "mainMenu current";
	new Effect.Morph(mainElement,{ style:"margin-top: 0px;", duration: 0.0 });
	$$('.articoloBox')[i].appear({duration: 1.0,afterFinish: function(){
		new Effect.Opacity(mainElement, { from: 1.0, to: 0.7, duration: 0.0 });
        
        cut(30,$$('.occhielloMain')[i]);
        //cut(35,$$('.titoloMain')[i]);
        
        marginHide = $$('.occhielloMain')[i].getHeight() + mainTitoloElement.getHeight() + $$('.dataMain')[i].getHeight() ;
        marginShow = marginHide + mainLancioElement.getHeight()+10;
        new Effect.Morph(mainElement,{ style:"margin-top: -"+marginHide+"px;"});			
	}});
	timerId = setTimeout('nextMain()',5000);
	
}


function nextMain() {
	var nextMainElement = currentElement+1;
	if(nextMainElement > 3)
		nextMainElement=0;
	goToMain(nextMainElement);
}


var isLancioHided = true;
var hidingRequest = 0;
var lancioMotion;


function showLancio() {
	try{
    hidingRequest--;
	if(hidingRequest<0 && isLancioHided) {
		isLancioHided=false;
		try {lancioMotion.cancel();} catch(ex){}
		clearTimeout(timerId);
		lancioMotion = new Effect.Morph(mainElement,{ style:"margin-top: -"+marginShow+"px;"});
	}
    } catch(e) {}
}

function hideLancio() {
	hidingRequest=0;
	setTimeout('hideLancio2()',50);
}

function hideLancio2() {
	try{
	if(hidingRequest>=0 && !isLancioHided) {
		isLancioHided=true;
		try {lancioMotion.cancel();} catch(ex){}
        //margin = mainElement.getHeight() - mainLancioElement.getHeight();
		lancioMotion = new Effect.Morph(mainElement,{ style:"margin-top: -"+marginHide+"px;"});
		timerId = setTimeout('nextMain()',7000);
	}
    } catch(e) {}
}





