var tempo = 30000; // 30 segundos
var tempoTotal;

function startCountdown() {

	var objeto = document.getElementById( "countdown" );

	if ( objeto ) {

		if ( this.tempoTotal > 0 ) {

			this.tempoTotal = this.tempoTotal - 1000;

			var segundos = this.tempoTotal / 1000;

			objeto.innerHTML = "Codesul no mundo (o mapa será fechado em "+ ( segundos < 10 ? "0"+ segundos : segundos ) +" segundos)";
			setTimeout( "startCountdown()", 1000 );

		} else {

			objeto.innerHTML = "Codesul no mundo (<A href=\"#\" onClick=\"iniciar();\">abrir mapa</a>)";
			hideOutdoor();
		}
	}
}

function iniciar() {

	mostrarOutdoor();
	startCountdown();
}

function mostrarOutdoor() {

	this.tempoTotal = this.tempo;

	var objeto = document.getElementById("theLayer");

	if ( objeto ) {
		objeto.style.visibility = "visible";
	}
}

function hideOutdoor() {

	this.tempoTotal = 0;

	var objeto = document.getElementById("theLayer");

	if ( objeto ) {
		objeto.style.visibility = "hidden";
	}
}

function getRGB( number ) {

	switch ( number ) {
	
		case 10: return 'A';
		case 11: return 'B';
		case 12: return 'C';
		case 13: return 'D';
		case 14: return 'E';
		case 15: return 'F';
		default: return number;
	}
}

function getCores() {

	var cores = new Array();
	var cont = 0;

	for ( i = 0 ; i < 16 ; i ++ ) {

		for ( j = 0 ; j < 16 ; j ++ ) {

			cores[cont] = getRGB( i ) +""+ getRGB( j ) +""+ 
				getRGB( i ) +""+ getRGB( j ) +""+ getRGB( i ) +""+ getRGB( j );
			cont = cont + 1;
		}
	}

	return cores;
}

// 0 = vertical; 1 = horizontal
function exibeCores( posicao ) {

	var table = document.getElementById( "tbl" );

	if ( table != null ) {

		var cores = getCores();

		var row = table.insertRow( 0 );
		var cell = null;
		var content = null;
		var img = null;

		var posicaoRow = 0;
		var posicaoCell = 0;

		for ( i = 0 ; i < cores.length ; i ++ ) {

			if ( posicao == 0 ) {
				
				row = table.insertRow( i );
				posicaoCell = 0;

			} else {

				posicaoCell = i;			
			}

			
			cell = row.insertCell( posicaoCell );
			img = document.createElement("img");
			img.src = "images/pixel.gif"

			cell.style.backgroundColor = "#"+ cores[i];
			cell.height = "1px";
			cell.width = "1px";
			cell.appendChild( img );
		}
	}
}

var size = 798;

function posicaoMapa() {

	var incremento = ( ( this.screen.width - size ) / 2 );
	var objeto = document.getElementById("theLayer");
	var left = incremento + 220;

	if ( objeto ) {
		objeto.style.left = left;
	}
}

function showLateralExtra() {

	if ( this.screen.width > size ) {
		
		var largura = ( this.screen.width - size ) / 2;

		var direita = document.getElementById( "tdOcultoDireita" );
		direita.className = 'ocultoDireita';
		direita.style.display = "";
		direita.style.visibility = "visible";

		var esquerda = document.getElementById( "tdOcultoEsquerda" );
		esquerda.className = 'ocultoEsquerda';
		esquerda.style.display = "";
		esquerda.style.visibility = "visible";
	}
}

function selectTd( o ) {
	
	var obj = document.getElementById( o );
	obj.className = 'menuSelected';
}

function unselectTd( o ) {
	
	var obj = document.getElementById( o );
	obj.className = 'menuUnselected';
}

function openFoto( id ) {
	
	window.open( 'foto.php?id='+id, 'Foto', 'width=380,height=350,status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes');
}
