/*
 * geouri javascript parser 0.1
 *
 * Copyright (c) 2007 Alex Mayrhofer, Christian Spanring
 * geouri.org
 * Licensed under the GPL.
 * 
 */

$(document).ready(function() {
	
	// append geourimap
	$("body").append("<div id='geourimap' style='width: 500px; height: 300px'></div>");
	$("body").unload( function() { GUnload(); });
	
	if (GBrowserIsCompatible()) {
		var geourimap = new GMap2(document.getElementById("geourimap"));
		geourimap.addControl(new GSmallMapControl());
		geourimap.addControl(new GMapTypeControl());
		geourimap.setCenter(new GLatLng(48.208333,16.372778), 13);
		
		geouribounds = new GLatLngBounds();
	}
	     
	$("a").each(function(i) {
		
		if (this.href.substr(0,4) == "geo:") {
			
			// lat = coord[0] , lng = coord[1]
			coord = this.href.substr(4,this.href.length - 4).split(",");
			
			geouripoint = new GLatLng(coord[0],coord[1]);
			geourimarker = new GMarker(geouripoint, {title: this.text});
			geourimap.addOverlay(geourimarker);
			geouribounds.extend(geouripoint);
		}
	});

	// calculate and set center
	geouricenterlat = (geouribounds.getNorthEast().lat() + geouribounds.getSouthWest().lat()) /2;
	geouricenterlng = (geouribounds.getNorthEast().lng() + geouribounds.getSouthWest().lng()) /2;
	geourimap.setCenter(new GLatLng(geouricenterlat,geouricenterlng));
	
	// set optimized zoom
	geourimap.setZoom(geourimap.getBoundsZoomLevel(geouribounds));
});