/*/***
* Gestione di google maps di Internet Servizi
* @author Alexander.Chernov
* @version 1.0.0
*/

function isMap(){
	var directionsService;
	var directionDisplay;
	var mappaGoogle;

	this.markerHotel;

	//nome contenitore mappa
	var container;
	var directionContainer;

	function isMap(){}

	//proprieta di default
	this.options = {
		zoom:14,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}

	/**
	* Imposta il contenitore per la mappa
	*/
	this.setContainer = function(containerName){
		container = containerName;
		return this;
	}
	/**
	* Imposta il nome del contenitore per le direzioni
	*/
	this.setDirectionContainer = function (containerName){
		directionContainer = containerName;
		return this;
	}


	/**
	* imposta il centro in base alle coordinante sotto forma "lat,lan"
	*/
	this.setTextCenter = function(txtCenter){
		this.options.center = textToLat(txtCenter);
		return this;
	}

	/**
	* Carica la mappa
	*/
	this.loadMap = function ()
	{
		mappaGoogle = new google.maps.Map(document.getElementById(container), this.options);
		directionsService = new google.maps.DirectionsService();
		directionsDisplay = new google.maps.DirectionsRenderer();
		directionsDisplay.setMap(mappaGoogle);
		directionsDisplay.setPanel(document.getElementById(directionContainer));
		return this;
	}

	this.createPoint = function (options, popupText){
		options.map = mappaGoogle;
		options.position = textToLat(options.position);
		var marker = new google.maps.Marker(options);
		if (popupText.length>0){
			creaInfoWindow(marker,popupText)
		}
		return marker;
	}
	this.setZoom = function (zoomLevel){
		this.options.zoom = zoomLevel;
		return this;
	}
	function creaInfoWindow(marker,contentString){
		var infowindow = new google.maps.InfoWindow({
			content: contentString
		});
		google.maps.event.addListener(marker, 'click', function() {
			infowindow.open(mappaGoogle, marker);
		});
	}
	function textToLat(text)
	{
		var temp = new Array();
		temp = text.split(",");
		return new google.maps.LatLng(temp[0], temp[1]);
	}
	/**
	* Calcola la rotta, da aggiungere aPiedi = 1 per percorso a piedi
	*/
	this.calcRoute = function (start, end, aPiedi) {
		var request = {
			origin:start,
			destination:end,
			travelMode: google.maps.DirectionsTravelMode.DRIVING
		};
		if (aPiedi == "1"){
			request.travelMode = google.maps.DirectionsTravelMode.WALKING;
		}

		directionsService.route(request, function(response, status) {
			if (status == google.maps.DirectionsStatus.OK) {
				directionsDisplay.setDirections(response);
			} else {
				alert("Errore durante ritrovamento dei dati\n" + status);
			}
		});
	}
}

/*
var directionsService;
var directionDisplay;
var mappaGoogle;
var origine;
var markerHotel;

$.getScript('http://maps.google.com/maps/api/js?sensor=true&language=it&v=3&key=ABQIAAAAbdZC_HnydUyvY6Dt7Hl4PhQ0D0iPOMW-ZO4eYfMJHKGZK7EVRxSuA_jHnJ8aBhH4IzoQmT-9PGLbVg&callback=caricaMappa');

function caricaMappa(){
	directionsService = new google.maps.DirectionsService();
	directionsDisplay = new google.maps.DirectionsRenderer();
	//albergo
	origine = new google.maps.LatLng(44.013873, 12.643944);

	var myOptions = {
		zoom:14,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		center: origine
	}
	//dichiarazioni
	mappaGoogle = new google.maps.Map(document.getElementById($("#nameDivMap").val()), myOptions);
	directionsDisplay.setMap(mappaGoogle);
	directionsDisplay.setPanel(document.getElementById($("#nameDivDirections").val()));

	//punti
	markerHotel = new google.maps.Marker({
		map:mappaGoogle,
		draggable:false,
		animation: google.maps.Animation.DROP,
		position: origine,
		title: 'Uluru (Ayers Rock)'
	});
	creaInfoWindow(markerHotel,"<b>Hotel Belmar</b>");
}

function calcRoute(start, end) {
	var request = {
		origin:start,
		destination:end,
		travelMode: google.maps.DirectionsTravelMode.DRIVING
	};

	directionsService.route(request, function(response, status) {
		if (status == google.maps.DirectionsStatus.OK) {
			directionsDisplay.setDirections(response);
		} else {
			alert("Errore durante ritrovamento dei dati\n" + status);
		}
	});
}
function creaInfoWindow(marker,contentString){
	var infowindow = new google.maps.InfoWindow({
		content: contentString
	});
	google.maps.event.addListener(marker, 'click', function() {
		infowindow.open(mappaGoogle, marker);
	});
}

*/
