function event_driver()
{
	this.lista = new Array();
	this.add_event = ADDevent;
	this.release_event = REMevent;
}

function REMevent()
{
	if (arguments.length!=1)
	{
		alert("erro nos argumentos da função release_event");
		return;
	}
	this.lista[arguments[0]].shift();
	if (this.lista[arguments[0]].length!=0)
	{
		this.lista[arguments[0]][0]
		window.setTimeout(arguments[0]+"."+this.lista[arguments[0]][0],1);
	}
}

function ADDevent()
{
	if (arguments.length!=2)
	{
		alert("erro nos argumentos da função add_event");
		return;
	}

	if (!this.lista[arguments[0]])
	{
		this.lista[arguments[0]]= new Array();
	}
	if(this.lista[arguments[0]].length==0)
	{
		this.lista[arguments[0]].push(arguments[1]);
		window.setTimeout(arguments[0]+"."+this.lista[arguments[0]][0],1);
	}
	else
	{
		this.lista[arguments[0]].push(arguments[1]);
	}
}

function redim_item()
{
		if (arguments.length!=2) { alert("erro nos argumentos da função redimensiona"); return; }
		this.significando.style.width = arguments[0];
		this.significando.style.height = arguments[1];
		global.release_event(this.objecto);
}

function move_item()
{
	if (!document.all)
	{
		this.significando.style.left = arguments[0];
		this.significando.style.top = arguments[1];
	}
	var move = 2;

	if (arguments.length>0)
	{
		if (arguments.length<2)
		{
			alert("erro na função desloca");
			return;
		}
		this.incremento = ((arguments[2])?arguments[2]:incremento);
		this.x_final = arguments[0];
		this.y_final = arguments[1];
		this.timer = window.setInterval(this.objecto+'.desloca()',animacao_timer);
	}

	if (this.x!=this.x_final)
	{
		var incremento_sig = ((this.x_final-this.x)/Math.abs(this.x_final-this.x))*this.incremento;
		if (Math.abs(incremento_sig)<Math.abs(this.x_final-this.x))
		{
			this.significando.style.left = this.x+incremento_sig;
		}
		else
		{
			this.significando.style.left = this.x_final;
		}
		this.x = parseInt(this.significando.style.left);
	}
	else
	{
		move--;
	}

	if (this.y!=this.y_final)
	{
		var incremento_sig = ((this.y_final-this.y)/Math.abs(this.y_final-this.y))*this.incremento;
		if (Math.abs(incremento_sig)<Math.abs(this.y_final-this.y))
		{
			this.significando.style.top = this.y + incremento_sig;
		}
		else
		{
			this.significando.style.top = this.y_final;
		}
		this.y = parseInt(this.significando.style.top);
	}
	else
	{
		move--;
	}

	if (!move)
	{
		window.clearInterval(this.timer);
		this.timer = null;
		global.release_event(this.objecto);
	}
}

function init_item()
{
	if (this.x) { this.significando.style.left = this.x; this.x = parseInt(this.significando.style.left);}
	if (this.y) { this.significando.style.top = this.y; this.y = parseInt(this.significando.style.top);}
	if (this.w) { this.significando.style.width = this.w; this.w = parseInt(this.significando.style.width);}
	if (this.x) { this.significando.style.height = this.h; this.h = parseInt(this.significando.style.height);}
}

function place_item()
{
	if (arguments.length!=2)
	{
		alert("Erro nos argumentos da função posiciona");
		return;
	}

	this.significando.style.left = arguments[0];
	this.x = parseInt(this.significando.style.left);
	this.significando.style.top = arguments[1];
	this.y = parseInt(this.significando.style.top);
	global.release_event(this.objecto);
}

function estica_item()
{
	var move = 2;
	if (arguments.length>0)
	{
		if (arguments.length<2)
		{
			alert("erro na função estica");
			return;
		}

		this.w_final = arguments[0];
		this.h_final = arguments[1];
		var inc = ((arguments[2])?arguments[2]:animacao_timer);
		this.incremento = ((arguments[3])?arguments[3]:incremento);
		this.timer_estica = window.setInterval(this.objecto+'.estica()',inc);
	}

	this.setVisible();

	if (this.w!=this.w_final)
	{
		var incremento_sig = ((this.w_final-this.w)/Math.abs(this.w_final-this.w))*this.incremento;

		if (Math.abs(incremento_sig)<Math.abs(this.w_final-this.w))
		{
			this.significando.style.width = this.w + incremento_sig;
		}
		else
		{
			this.significando.style.width= this.w_final;
		}

		this.w = parseInt(this.significando.style.width);
	}
	else
	{
		move--;
	}

	if (this.h!=this.h_final)
	{
		var incremento_sig = ((this.h_final-this.h)/Math.abs(this.h_final-this.h))*this.incremento;
		if (Math.abs(incremento_sig)<Math.abs(this.h_final-this.h))
		{
			this.significando.style.height = this.h + incremento_sig;
		}
		else
		{
			this.significando.style.height = this.h_final;
		}

		this.h = parseInt(this.significando.style.height);
	}
	else
	{
		move--;
	}

	if (!move)
	{
		window.clearInterval(this.timer_estica);
		timer_estica = null;
		global.release_event(this.objecto);
	}
}

function item(id,b,x,y,w,h,menu)
{
	this.significando = document.getElementById(id);

	this.contador = 0;
	this.limite = 28;
	this.rota = null;
	this.timer=null;
	this.timer_estica=null;
	this.timer_rota=null;
	this.x=x;
	this.y=y;
	this.x_final=null;
	this.y_final=null;
	this.w=w;
	this.h=h;
	this.w_final=null;
	this.h_final=null;
	this.objecto=b;
	this.desloca=move_item;
	this.posiciona=place_item;
	this.redimensiona=redim_item;
	this.init=init_item;
	this.estica=estica_item;
	this.innerHTML=chgHTML;
	this.bgFLASH=backgroundFlash;
	this.setVisible = showItem;
	this.setInvisible = hideItem;
	this.FadeOut= fade_out;
	this.FadeIn= fade_in;
	this.segueRota=rot;
	this.menu = ((menu)?menu:false);
	this.incremento = incremento;
	this.blink = blinker;
}

function blinker()
{
	global.add_event(this.objecto,'bgFLASH(1)')
	window.setTimeout("global.add_event('"+this.objecto+"','bgFLASH(2)');",600);
}

function fade_out()
{
	if (!document.all)
	{
		this.setInvisible();
		return;
	}

	this.significando.filters[0].Apply();
	this.setInvisible();
	this.significando.filters[0].Play();
	global.release_event(this.objecto);
}

function fade_in()
{
	if (!document.all)
	{
		this.setVisible();
		return;
	}

	this.significando.filters[0].Apply();
	this.setVisible();
	this.significando.filters[0].Play();
	global.release_event(this.objecto);
}

function rot(rota)
{

	if (rota)
	{
		this.rota = rota;
		this.timer_rota = window.setInterval(this.objecto+".segueRota();",40);
	}

	if (this.contador>=this.limite)
	{
		this.contador = this.limite-1;
	}

	this.contador++;
	var tmp = this.rota.pontos[this.contador];

	this.significando.style.left = tmp.x;
	this.significando.style.top = tmp.y;

	if ((this.contador>=this.limite) || (this.contador<=0))
	{
		this.rota = null;
		window.clearInterval(this.timer_rota);
	}

}

function showItem()
{
	this.significando.style.visibility = "visible";
	if (this.menu)
	{
		this.significando.style.backgroundColor = "rgb(23,55,150)";//#5E5E5E
	}
}

function hideItem()
{
	this.significando.style.visibility = "hidden";
}

function backgroundFlash(MOVE)
{
	if (!document.all)
	{
		if (this.menu)
		{
			this.innerHTML(this.menu);
		}

		return;
	}

	if (MOVE==1)
	{
		this.significando.filters[0].Apply();
		this.significando.style.backgroundColor = "#FFFFFF";
		this.significando.filters[0].Play();
		global.release_event(this.objecto);
	}
	else
	{
		this.significando.filters[0].Apply();
		if (this.menu)
		{
			this.innerHTML(this.menu);
			this.significando.style.backgroundColor = "rgb(23,55,150)";//#5E5E5E
		}
		else
		{
			this.significando.style.backgroundColor = "transparent";
		}
		this.significando.filters[0].Play();
		global.release_event(this.objecto);
	}
}

function chgHTML()
{
	this.significando.innerHTML = arguments[0];
	global.release_event(this.objecto);
}

function change_caixa(x,y)
{
	var equador = 1206;//1500
	var greenwich = 625;//287

	//var aux = Math.round(2.3242*(equador-y));
	//var calcN = Math.floor(aux/60)+"º"+(aux%60)+"'";
	//aux = Math.round(3.4903*Math.abs(greenwich-x));
	//var calcE =  Math.floor(aux/60)+"º"+(aux%60)+"'";

	var aux = Math.abs(equador - y) * 2.935;
	var calcN = Math.floor(aux / 59) + "º " + Math.round(aux % 59) + "'";
	var aux = Math.abs(greenwich - x) * 2.935;
	var calcE = Math.floor(aux / 59) + "º " + Math.round(aux % 59) + "'";

	var time = new Date();
	var correctionFactor = +60;
	var minutos = ((time.getMinutes() < 10 ) ? "0" : "") + time.getMinutes();

//	document.getElementById('caixa_coords').innerHTML = '<b>GMT'+
//	((time.getTimezoneOffset()!=-60)?((time.getTimezoneOffset()+correctionFactor<0)?'+':'')+((time.getTimezoneOffset()+correctionFactor)/-60):'')+
//	':</b> '+time.getHours()+':'+minutos+
//	'<br /><b>N:</b> '+calcN+
//	'<br /><b>'+(((greenwich-x)>0)?'W':'E')+':</b> '+calcE;

	document.getElementById('caixa_coords').innerHTML =
		((time.getTimezoneOffset() != -60)
			? (((time.getTimezoneOffset() + correctionFactor) < 0) ? '+' : '') + ((time.getTimezoneOffset() + correctionFactor ) / -60)
			: '')
		+ time.getHours() + ':' + minutos + ' GMT<br />'
		+ calcN + ' N<br />'
		+ calcE + (((greenwich - x) > 0 ) ? ' W' : ' E');

}

