/*
Este arquivo está codificado com utf-8 sem BOM.
Você deveria ver as letras aeiou com acentos na linha abaixo se o arquivo foi aberto corretamente
àêíõü
*/

function updateAddress(address) {
	window.location.hash = address;
}

function updateFlashVars(address) {
	flashvars.setAttribute("value", "página=" + address);
}

function updateLocation() {
	if (hashAtual != window.location.hash) {
		hashAtual = window.location.hash;
		var address = hashAtual;
		//remove o caractere # se o navegador usar
		if(address.substring(0, 1) == '#') {
			address = address.substring(1, address.length);
		}
		//remove a barra inicial
		if(address.substring(0, 1) == '/') {
			address = address.substring(1, address.length);
		}
		updateFlashVars(address);
		if (flashObject["updateFlashAddress"] != null) {//só por segurança
			flashObject.updateFlashAddress(address);
		}
	}
}

function iniciar() {
	flashvars = document.getElementById("flashvars");
	flashObject = document.getElementById("index");
	hashAtual = window.location.hash;
}

var flashvars = null;
var flashObject = null;
var hashAtual = "";

var addEvent;
if (document.addEventListener) {
	addEvent = function(element, type, handler) {
		element.addEventListener(type, handler, false);
	}
} else if (document.attachEvent) {
	addEvent = function(element, type, handler) {
		element.attachEvent("on" + type, handler);
	}
}

addEvent (window, 'load', iniciar);

/*
entre outros, dispara quando o usuário digita alguma
coisa na barra de endereço e aperta enter
*/
addEvent(window, 'focus', updateLocation);
