// JavaScript Document
var conteudoGMapas = "";
conteudoGMapas += '<div id="modulo_gmaps">';
conteudoGMapas += '<a class="close" href="javascript: fechaBox();" style="position:absolute; top:0px; right:0px; width:auto; height:auto; padding:2px; background-color:#A80623; font-weight:bold; text-decoration:none; color:#FFFFFF;"><img src="modulos/google_maps/img/btn_janela_close.png"/></a>';
conteudoGMapas += '<iframe name="detGoogleMaps" id="detGoogleMaps" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="modulos/google_maps/detGoogleMaps.php?codunidade=###CODUNIDADE###" width="500" height="500" style="overflow-x: hidden; margin-bottom:10px;"></iframe>';
conteudoGMapas += '</div>';

var map;
var directionDisplay;
var directionsService;
var geocoder;

function initialize(latitude, longitude) {
	directionsDisplay = new google.maps.DirectionsRenderer();
	directionsService = new google.maps.DirectionsService();
	geocoder = new google.maps.Geocoder();
	
	var latlng = new google.maps.LatLng(latitude, longitude);
	var myOptions = {
		zoom: 16,
		center: latlng,
		mapTypeControl: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	
	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	directionsDisplay.setMap(map);
	directionsDisplay.setPanel(document.getElementById("map_directions"));
	
	var marker1 = new google.maps.Marker({
		position: latlng, 
		map: map, 
		title: 'Mandaliti'
	});
}

function setDirections(latitude,longitude) {	
	var from = document.getElementById('from').value;
	var to = new google.maps.LatLng(latitude, longitude);
	
	if (geocoder) {
		geocoder.geocode({'address': from}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				var request = {
					origin: results[0].geometry.location, 
					destination:to,
					travelMode: google.maps.DirectionsTravelMode.DRIVING
				};
				directionsService.route(request, function(result, status) {
					if (status == google.maps.DirectionsStatus.OK) {
						directionsDisplay.setDirections(result);
					}
				});
			} else {
				alert(from + " não encontrado");
			}
		});
	}
}

function mudaFundo(codsisupload) {
	/*if (classe == '') {
		document.body.className.className = "";
	} else {
		document.body.className = classe;
	}*/
	if (codsisupload > 0) {
		document.body.style.backgroundImage = 'url(../../lib/upload/preview.php?codsisupload=' + codsisupload + ')';
	} else {
		document.body.style.backgroundImage = 'url(img/img_fundo2.gif)';
	}
}

function ativaZoom() {
	MagicZoom.refresh();
	MagicZoom.z1();
}
