// JavaScript Document
var conteudoGMapas = "";
conteudoGMapas += '<div id="modulo_gmaps">';
conteudoGMapas += '<a class="close" href="javascript: fechaBox();"><img src="modulos/google_maps/img/btn_janela_close.png" style="width:auto; height:auto" /></a>';

conteudoGMapas += '<iframe name="detGoogleMaps" id="detGoogleMaps" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="modulos/google_maps/detGoogleMaps.php" width="480" height="410" style="overflow-x: hidden; margin-bottom:10px;"></iframe>';
conteudoGMapas += '</iframe>';

//conteudoGMapas += '<strong class="name">Nome Empresa</strong> - ';
//conteudoGMapas += '<a style="color:#196F30;" href="http://maps.google.com.br/maps?f=q&source=s_q&hl=pt-BR&geocode=&q=&sll=<?=$latitude?>,<?=$longitude?>&sspn=&ie=UTF8&ei=&sig2=&cd=&ll=-29.675618,-51.092927&spn=0.009471,0.019205&z=16&iwloc=r1" target="_blank">Como chegar</a><br />';
conteudoGMapas += '<span class="street">%GTR_DESLOGRADOURO%</span><br />';
conteudoGMapas += '<span class="city_state">%GTR_DESBAIRRO%, %GTR_DESCIDADE% - %GTR_DESESTADO%</span>, Cep: <span class="zipcode">%GTR_DESCEP%</span><br />';
conteudoGMapas += '<span class="phone">%GTR_DESCEP%</span>';

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: 'Itabom'
	});
}

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();
}
