﻿function grf_menu_fx(){
	var Elementi=new Array()
	var tempo=new Date().getTime()
	setInterval(Esecuzione,16)
	var This=this
	
	this.mostra=function(o,id,verticale){
		if(verticale==true){
			document.getElementById(id).style.top=o.offsetTop+o.offsetHeight+'px'
			document.getElementById(id).style.left=o.offsetLeft+'px'
		}else{
			document.getElementById(id).style.top=o.offsetTop+'px'
			document.getElementById(id).style.left=o.offsetLeft+o.offsetWidth+'px'
		}
		document.getElementById(id).style.zIndex=1001
		if(Elementi[id]==undefined){Elementi[id]=new Elemento(id);ModificaOpacita(id,-100);}
		Elementi[id].daScoprire=true
		Elementi[id].daNascondere=false
		Elementi[id].contoRovescia=0
	}
	

	this.nascondi=function(id){
		if(Elementi[id]==undefined){Elementi[id]=new Elemento(id);ModificaOpacita(id,100)}
		document.getElementById(id).style.zIndex=1000
		Elementi[id].daScoprire=false
		Elementi[id].daNascondere=true
		Elementi[id].contoRovescia=5
	}
	
	this.blocca=function(id){
		Elementi[id].daScoprire=true
		Elementi[id].daNascondere=false
	}
	
	function ModificaOpacita(id,valore){
		valore=Math.round(valore)
		Elementi[id].opacita+=valore
		if(Elementi[id].opacita>100){Elementi[id].opacita=100}
		if(Elementi[id].opacita<0){Elementi[id].opacita=0}
		try{
			if(document.getElementById(id).filters.alpha==undefined){document.getElementById(id).style.filter='alpha(opacity='+Elementi[id].opacita+')'}
			document.getElementById(id).filters.alpha.opacity=Elementi[id].opacita		
			if((Elementi[id].opacita==100)||(Elementi[id].opacita==0)){document.getElementById(id).style.filter=''}
		}catch(e){}
		if(Elementi[id].opacita>0){document.getElementById(id).style.display='block'}else{document.getElementById(id).style.display='none'}
		return Elementi[id].opacita
	}
	
	function Esecuzione(){
		var diff=new Date().getTime()-tempo
		tempo=new Date().getTime()
		for(e in Elementi){
			if(Elementi[e].contoRovescia<=0){
				if(Elementi[e].daScoprire==true){
					if (ModificaOpacita(Elementi[e].id,diff/This.rallentamento)==100){Elementi[e].daScoprire=false;}
				}
				if(Elementi[e].daNascondere==true){
					if (ModificaOpacita(Elementi[e].id,-diff/This.rallentamento)==0){Elementi[e].daNascondere=false;}
				}
			}else{Elementi[e].contoRovescia+=-1}
		}
	}
	
	function Elemento(id,idCollegato){
		this.opacita=0
		this.daScoprire=false
		this.daNascondere=false
		this.contoRovescia=0
		this.id=id
		this.idCollegati=new Array()
		this.idCollegati[0]=idCollegato
		
	}
	
	this.rallentamento=1
}

