$(document).ready(function() {
	
	resizeMap();
	$("#map_canvas").fadeIn(500);
	
	if ($(document).height()>1000) {
		$("#mapoverlay").css("top", $(document).height()-100);
	} else {
		$("#mapoverlay").remove();
	}
	
	$("#loadmore").click(function() {
		var ww = "/loadGuestbook.php?offset="+guestbookOffset;
		if (guestbookEntries>guestbookOffset) {
			$("#loadmore").text("Bezig met ophalen");
			$.ajax({
			  url: ww,
			  context: document.body,
			  success: function(value) {
				
				guestbookOffset = (guestbookOffset+10);
			
				$(".box:last").parent().append(value);
				
				if  (guestbookEntries>guestbookOffset) {
					$("#loadmore").text("Meer berichten laden...");
		  		} else {
					$("#loadmore").text("Er zijn geen oudere berichten meer");
				}
				
			}
			});	
		} else {
			$("#loadmore").text("Er zijn geen oudere berichten meer");
		}
	});
});
$(window).resize(function() {
	resizeMap();
});

function resizeMap() {
	if ($.browser.msie) {
		$("#map_canvas").width($(window).width());
		$("#map_canvas").height($(document).height());
	} else {
		$("#map_canvas").width($(window).width());
		$("#map_canvas").height($(document).height());
	}
}

function initialize() {
	

	
	var latlng = new google.maps.LatLng(initLat, initLng);
	
	var MY_MAPTYPE_ID = 'Pompert';
	
	var styler = [ { featureType: "all", elementType: "all", stylers: [ { hue: "#99CCFF" }, { lightness: -3 }, { saturation: -68 } ] },{ featureType: "poi", elementType: "all", stylers: [ { hue: "#99CCFF" }, { lightness: -8 }, { saturation: 18 } ] },{ featureType: "water", elementType: "all", stylers: [ { hue: "#99CCFF" }, { lightness: 8 }, { saturation: 18 } ] },{ featureType: "administrative", elementType: "all", stylers: [ { visibility: "on" }, { saturation: -9 }, { lightness: 49 }, { hue: "#99CCFF" } ] }, { featureType: "landscape", elementType: "all", stylers: [ { hue: "#99CCFF" }, { lightness: -3 }, { saturation: 18 } ] }, { featureType: "road.local", elementType: "all", stylers: [ { lightness: -7 }, { hue: "#99CCFF" }, { saturation: 22 } ] }, { featureType: "transit", elementType: "all", stylers: [ { lightness: -7 }, { hue: "#99CCFF" }, { saturation: 22 } ] }  , { featureType: "administrative.locality", elementType: "all", stylers: [ { hue: "#ff0000" }, { lightness: -8 }, { saturation: 40 }, { visibility: "off" } ] }   ];

 	var settings = {
		zoom: 15,
		center: latlng,
		mapTypeControl: false,
		navigationControl: false,
		streetViewControl: false,
		mapTypeControlOptions: {
			mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID]
		},
		mapTypeId: MY_MAPTYPE_ID
	}
 	map = new google.maps.Map(document.getElementById("map_canvas"), settings);
		var styledMapOptions = {
	    name: "Pompert"
	};

	var MapType = new google.maps.StyledMapType(styler, styledMapOptions);
	
	map.mapTypes.set(MY_MAPTYPE_ID, MapType);
	
	var contentString = '<div id="pincontent">'+
		varcontent +
		'</div>';
		
	var infowindow = new google.maps.InfoWindow({
		content: contentString
	});
	
	var companyImage0 = new google.maps.MarkerImage('/images/markerpeter.png',     
				new google.maps.Size(120, 140),
				new google.maps.Point(0,0),
				new google.maps.Point(60, 115)
	);
	var companyImage1 = new google.maps.MarkerImage('/images/markerkitty.png',     
				new google.maps.Size(120, 140),
				new google.maps.Point(0,0),
				new google.maps.Point(60, 115)
	);
	var companyShadow = new google.maps.MarkerImage('/images/marker_shadow.png',
        		new google.maps.Size(120, 140),
  				new google.maps.Point(0,0),
  				new google.maps.Point(60, 115)
	);

		  
	var companyPos = new google.maps.LatLng(0, 0);

	
	var companyPos1 = new google.maps.LatLng(0, 0);

	companyMarker[1] = new google.maps.Marker({
		position: companyPos1,
		map: map,
		icon: companyImage1,
		shadow: companyShadow,
		title:"Autorijschool Pompert",
		zIndex: 3}
	)
	
	
	companyMarker[0] = new google.maps.Marker({
		position: companyPos,
		map: map,
		icon: companyImage0,
		shadow: companyShadow,
		title:"Autorijschool Pompert",
		zIndex: 3}
	)
	
	

	
	google.maps.event.addListener(companyMarker, 'click', function() {
		infowindow.open(map,companyMarker);
	});
	loadcoords();
}
var d = setInterval("loadcoords()", 10000);



function loadcoords() {

	var ww = "/coords/index.php?plain=true&id=3";
	$.ajax({
	  url: ww,
	  context: document.body,
	  success: function(value){

		var cars = new Array(2);
		cars = value.split("\n");
		for (var o=0;o<2;o++) {
		 	var splitdata = new Array(2);
			splitdata = cars[o].split("&");
			var realloc = splitdata[1].replace("Netherlands", "NL");
			var loctime = splitdata[2];
			$("#location #was"+o).text("was ");	
			$("#location #locationstring"+o).text(realloc);
			$("#location #locationtime"+o).text('om '+loctime);
			$("#pincontent").text("Autorijschool Pompert: "+realloc);
		    var newcoords = new Array(2);
			newcoords = splitdata[0].split(',');
			var newx = parseFloat(newcoords[0]);
		  	var newy = parseFloat(newcoords[1]);
			var zoomlevel = (map.getZoom()-14);
			if(zoomlevel == 0) {
				zoomlevel = 0.5;
			} else if (zoomlevel < 0) {
				var temp = (zoomlevel)*-1;
				zoomlevel = (0.5/Math.pow(2,temp));
				
			}
			hcorrection = parseFloat(-1*(($(document).height()/2)-205)*(hrate/zoomlevel));
			wcorrection = parseFloat((($(window).width()/2)-915)*(wrate/zoomlevel));
			companyMarker[o].setPosition(new google.maps.LatLng(newx, newy)); 
			if (o==activeOne)	map.panTo(new google.maps.LatLng(parseFloat(newx+hcorrection), parseFloat(newy+wcorrection)));
			cachedlocsLat[o] = parseFloat(newx+hcorrection);
			cachedlocsLng[o] = parseFloat(newy+wcorrection);
		}
	
	  }
	});
	
}

function volg(id) {
	activeOne = parseInt(id);
	map.panTo(new google.maps.LatLng(cachedlocsLat[activeOne], cachedlocsLng[activeOne]));


	$(".volgen").toggle();
	$(".jevolgt").toggle();
	
}
