// Si assume che siano stati importati prototype e scriptaculous

/* Carica l'immagine specificata da strSrc nell'elemento <img> di id strImgId
 * eseguendo un fadeout dell'immagine attuale e poi un fadein al caricamento.
 * Fadeout e fadein durano numDur secondi.
 * Se viene specificata una funzione poststep questa viene eseguita al termine 
 * del fade in.
*/
function loadImage(strImgId,strSrc,numDur,poststep){
	var durata;
	durata = numDur ? numDur : 1;
	$(strImgId).onload=function(){
		$(strImgId).style.visibility='visible';
		new Effect.Opacity(strImgId, {duration:durata, to:1, sync:false});
	}		
	function step2(obj){
		$(strImgId).style.visibility='hidden';
		$(strImgId).style.opacity='0';
		$(strImgId).src=strSrc;
		if (poststep!=undefined){
			poststep.call();
		}
	}
	if (Element.getStyle(strImgId,'visibility')!='hidden'){
		new Effect.Opacity(strImgId, {duration:durata, to:0, sync:false, afterFinish:step2});
	} else {
		new Effect.Opacity(strImgId, {duration:0, to:0, sync:false, afterFinish:step2});
	}
}

/* Carica l'immagine specificata da strSrc nell'elemento <img> di id strImgId
 * eseguendo un fadeout delcontenitore di id strContId attuale e poi un fadein al caricamento.
 * Fadeout e fadein durano numDur secondi.
 * Se visibility del contenitore è hidden non viene eseguito il fadeout.
 * Se viene specificata una funzione poststep questa viene eseguita al termine 
 * del fade in.
*/
function loadImageInto(strContId,strImgId,strSrc,numDur,poststep){
	var durata;
	durata = numDur ? numDur : 1;
	$(strImgId).onload=function(){
		$(strContId).style.visibility='visible';
		new Effect.Opacity(strContId, {duration:durata, to:1, sync:false});
	}		
	function step2(obj){
		$(strContId).style.visibility='hidden';
		$(strContId).style.opacity='0';
		$(strImgId).src=strSrc;
		if (poststep!=undefined){
			poststep.call();
		}
	}
	if (Element.getStyle(strContId,'visibility')!='hidden'){
		new Effect.Opacity(strContId, {duration:durata, to:0, sync:false, afterFinish:step2});
	} else {
		new Effect.Opacity(strContId, {duration:0, to:0, sync:false, afterFinish:step2});
		/*
		$(strContId).style.opacity='0';
		$(strImgId).src=strSrc;
		*/
	}
}