var map;
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var pubPosition;
var pubTitle;

var addressMarker;

function initMap(lat, lng, title)
{
	directionsDisplay = new google.maps.DirectionsRenderer();

	pubPosition = new google.maps.LatLng(lat, lng);
	pubTitle = title;

	var myOptions = {
	  zoom: 10,
	  center: pubPosition,
	  mapTypeId: google.maps.MapTypeId.TERRAIN
	};
	icon = 'http://'+document.location.host+'/_clip/master-single-shadow.png';
	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	directionsDisplay.setMap(map);
	directionsDisplay.setPanel(document.getElementById("directions"));
	var marker = new google.maps.Marker({position: pubPosition,icon: icon, map: map, title: pubTitle});
}

function calcRoute() {
	var start = $('#fromAddress').val();
	var request = {
		origin:start,
		destination:pubPosition,
		travelMode: google.maps.DirectionsTravelMode.DRIVING
	};
	directionsService.route(request, function(result, status) {
		if (status == google.maps.DirectionsStatus.OK) {
		  directionsDisplay.setDirections(result);
		}
	});
}


//function load() {
//	  if (GBrowserIsCompatible()) {
//		map = new GMap2(document.getElementById('map_canvas'));
//		map.addControl(new GSmallMapControl());
//		gdir = new GDirections(map, document.getElementById('directions'));
//		GEvent.addListener(gdir, 'load', onGDirectionsLoad);
//		GEvent.addListener(gdir, 'error', handleErrors);
//
//        if (Get_Cookie('GLatLng'))
//        	{
//        	cookie_GlatLng = Get_Cookie('GLatLng').split(",");
//        	center  = 	cookie_GlatLng[0] +','+ cookie_GlatLng[1];
//        	}
//        else
//        	center = 'Česká republika';
//		setDirections(center);}
//	}
//
//
//	function setDirections(fromAddress) {
//
//	  gdir.load('from: ' + fromAddress + ' to: ' + '<?php echo $this->data['geo_latitude'].','.$this->data['geo_longitude']; ?>');
//	}
//
//	function handleErrors(){
//		alert('Adresa nenalezena, chyba: ' + gdir.getStatus().code);
//	}
//
//	function onGDirectionsLoad(){
//	  // Use this function to access information about the latest load()
//	  // results.
//
//	  // e.g.
//	  //document.getElementById('getStatus').innerHTML = gdir.getStatus().code;
//	  // and yada yada yada...
//	}
