function mostrarNota(nota) {
	for (i = 1; i <= 5; i++) {
		if (i <= nota) {
			$('#nota' + i).attr('src', 'imgs/icones/estrela.png');
		} else {
			$('#nota' + i).attr('src', 'imgs/icones/estrela-2.png');
		}
	}
}

function atribuirNota(nota) {
	notaAtual = nota;
	$.post('local-nota', {nota: nota, local: idLocal});
}

$(document).ready( function() {

	$('#nota1').mouseover( function() {
		mostrarNota(1);
	}).mouseout( function() {
		mostrarNota(notaAtual);
	}).click( function() {
		atribuirNota(1);
	});

	$('#nota2').mouseover( function() {
		mostrarNota(2);
	}).mouseout( function() {
		mostrarNota(notaAtual);
	}).click( function() {
		atribuirNota(2);
	});

	$('#nota3').mouseover( function() {
		mostrarNota(3);
	}).mouseout( function() {
		mostrarNota(notaAtual);
	}).click( function() {
		atribuirNota(3);
	});

	$('#nota4').mouseover( function() {
		mostrarNota(4);
	}).mouseout( function() {
		mostrarNota(notaAtual);
	}).click( function() {
		atribuirNota(4);
	});

	$('#nota5').mouseover( function() {
		mostrarNota(5);
	}).mouseout( function() {
		mostrarNota(notaAtual);
	}).click( function() {
		atribuirNota(5);
	});
	
	mostrarNota(notaAtual);

});

google.load("maps", "2");

var nivelZoom = [];
nivelZoom[0] = 2;
nivelZoom[1] = 8;
nivelZoom[2] = 9;
nivelZoom[3] = 10;
nivelZoom[4] = 12;
nivelZoom[5] = 13;
nivelZoom[6] = 14;
nivelZoom[7] = 15;
nivelZoom[8] = 16;

var map;
var geocoder;

function initialize() {

	geocoder = new GClientGeocoder();
	geocoder.getLocations(endereco, fimPesquisa);

}

function fimPesquisa(resposta) {

	if (resposta.Status.code == G_GEO_SUCCESS) {

		$('#espacoMapa').html(
				'<h3>Mapa</h3><div id="mapa" style="height: 500px;"></div>');

		map = new google.maps.Map2(document.getElementById("mapa"));

		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());

		var local = resposta.Placemark[0];
		var ponto = local.Point.coordinates;
		var acc = resposta.Placemark[0].AddressDetails.Accuracy;
		var p = new GLatLng(ponto[1], ponto[0]);

		marcador = new GMarker(p);
		GEvent.addListener(marcador, "click", function() {
			exibeInfo();
		});

		map.setCenter(p, nivelZoom[acc]);
		map.addOverlay(marcador);

		exibeInfo();

	}

}

function exibeInfo() {
	marcador
			.openInfoWindowHtml('<p style="color: #000000; text-align: center; font-size: 12px; font-weight: bold;">'
					+ nome
					+ '</p><p style="color: #000000; text-align: center;">'
					+ endereco + '</p>');
}

google.setOnLoadCallback(initialize);