function getGeoLocation(position) {
	mapZoom = 16;
	var lat = position.coords.latitude;
	var lng = position.coords.longitude;
	var mapCenter= new google.maps.LatLng(lat,lng); //rework this funktion so that it updates chache
	map.setCenter(mapCenter);
	map.setZoom(mapZoom);
}

function getGeoLocationError() {
	mapZoom = 3;
	var mapCenter = new google.maps.LatLng(48.20833, 16.373064);
	map.setCenter(mapCenter);
	map.setZoom(mapZoom);
}

function zoomIn() {
	mapZoom ++;
	map.setZoom(mapZoom);
}

function zoomOut() {
	mapZoom --;
	map.setZoom(mapZoom);
}

function createMap() {	
	var myOptions = {
		zoom:3,
		mapTypeId: mapTypeArr[mapTypSel],
		disableDoubleClickZoom: true,
		mapTypeControl: false,
		navigationControl: false,
		scrollwheel:false,
		backgroundColor:'#333333'
	};
		
	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	getGeoLocationError();
		
	if (typeof navigator.geolocation != 'undefined') { 
		navigator.geolocation.getCurrentPosition(getGeoLocation,getGeoLocationError,{maximumAge:10000});
	} 

	var styledMapOptions = {
    map: map,
    name: "nolli map"
  }
  
  var NolliStyles = [ 
  	  { featureType: "road", elementType: "geometry", stylers: [ { visibility: "simplified" }, { lightness: 99 } ] },
  	  { featureType: "road", elementType: "labels", stylers: [ { gamma: 9.99 }, { visibility: "off" } ] },
  	  { featureType: "transit", elementType: "all", stylers: [ { visibility: "off" } ] },	
  	  { featureType: "poi", elementType: "labels", stylers: [ { visibility: "off" } ] },
  	  { featureType: "landscape.man_made", elementType: "all", stylers: [ { lightness: -99 } ] },
  	  { featureType: "water", elementType: "all", stylers: [ { saturation: -100 }, { lightness: -50 } ] },
  	  { featureType: "poi.attraction", elementType: "all", stylers: [ { lightness: -100 } ] },
  	  { featureType: "poi.business", elementType: "all", stylers: [ { lightness: -100 } ] },
  	  { featureType: "poi.government", elementType: "all", stylers: [ { lightness: -100 } ] },
  	  { featureType: "poi.medical", elementType: "all", stylers: [ { lightness: -100 } ] },
  	  { featureType: "poi.park", elementType: "all", stylers: [ { saturation: -100 } ] },
  	  { featureType: "poi.place_of_worship", elementType: "all", stylers: [ { lightness: -100 } ] },
  	  { featureType: "poi.school", elementType: "all", stylers: [ { lightness: -99 } ] },
  	  { featureType: "poi.sports_complex", elementType: "all", stylers: [ { lightness: -99 } ] },
  	  { featureType: "landscape.natural", elementType: "all", stylers: [ { saturation: -100 } ] } 
  ];
	
	var Nolli = new google.maps.StyledMapType(NolliStyles, styledMapOptions);
	
	map.mapTypes.set('nolli', Nolli);
	mapTypeArr.push('nolli');
	
	
  styledMapOptions = {
    map: map,
    name: "outline map"
  }
  
   var OutlineStyles = [ 
     { featureType: "all", elementType: "labels", stylers: [ { saturation: -100 }] },
     { featureType: "road.local", elementType: "geometry", stylers: [{ gamma: 0.01 }, { saturation: -100 } ] },
  	  { featureType: "road.highway", elementType: "geometry", stylers: [ { saturation: -100 } ] },
  	  { featureType: "road.aterial", elementType: "geometry", stylers: [ { saturation: -100 } ] },
  	  { featureType: "transit", elementType: "all", stylers: [ { visibility: "off" } ] },	
  	  { featureType: "poi", elementType: "labels", stylers: [ { visibility: "off" } ] },
  	  { featureType: "landscape.man_made", elementType: "all", stylers: [ { lightness: -99 }, {invert_lightness:true} ] },
  	  { featureType: "water", elementType: "all", stylers: [ { saturation: -100 }, { lightness: -50 }, {invert_lightness:true} ] },
  	  { featureType: "poi.attraction", elementType: "all", stylers: [ { lightness: -100 }, {invert_lightness:true} ] },
  	  { featureType: "poi.business", elementType: "all", stylers: [ { lightness: -100 }, {invert_lightness:true} ] },
  	  { featureType: "poi.government", elementType: "all", stylers: [ { lightness: -100 } , {invert_lightness:true}] },
  	  { featureType: "poi.medical", elementType: "all", stylers: [ { lightness: -100 }, {invert_lightness:true} ] },
  	  { featureType: "poi.park", elementType: "all", stylers: [ { saturation: -100 },{ lightness: -20 } ] },
  	  { featureType: "poi.place_of_worship", elementType: "all", stylers: [ { lightness: -100 }, {invert_lightness:true} ] },
  	  { featureType: "poi.school", elementType: "all", stylers: [ { lightness: -99 }, {invert_lightness:true} ] },
  	  { featureType: "poi.sports_complex", elementType: "all", stylers: [ { lightness: -99 }, {invert_lightness:true} ] },
  	  { featureType: "landscape.natural", elementType: "all", stylers: [ { saturation: -100 } ] } 
  ];
  
  	var Outline = new google.maps.StyledMapType(OutlineStyles, styledMapOptions);
	
	map.mapTypes.set('outline', Outline);
	mapTypeArr.push('outline');
}

function changeMapType() {
	mapTypSel ++;
	mapTypSel %= mapTypeArr.length;
	map.setMapTypeId(mapTypeArr[mapTypSel]);
}

function convertPoint(latLng) {
	var topRight=map.getProjection().fromLatLngToPoint(map.getBounds().getNorthEast());
	var bottomLeft=map.getProjection().fromLatLngToPoint(map.getBounds().getSouthWest());
	var scale=Math.pow(2,map.getZoom());
	var worldPoint=map.getProjection().fromLatLngToPoint(latLng);
	return new google.maps.Point((worldPoint.x-bottomLeft.x)*scale,(worldPoint.y-topRight.y)*scale);
} 

