// ==UserScript==
// @name           Link to Quakr (from Google Maps)
// @namespace      http://www.quakr.co.uk
// @description    A script to link from Google Maps to a geotagged photo in quakr
// @include        http://maps.google.*
// @exclude	   */mapfiles/*
// ==/UserScript==


function GoogleMapsQuakrLink() {

    // copy the 'link to this page' href
    var linktothispagelink = document.getElementById('link').href;
    // check there is a lat and long
    var startindex = linktothispagelink.indexOf("&ll=");
    if(startindex == -1) {return true;};
    // parse the link to get at the comma separated values
    var tail = linktothispagelink.substring(startindex+4);
    var stopindex = tail.indexOf("&");
    var ll = tail.substring(0,stopindex);
    // parse the comma separated values into an array
    var latlong_array = ll.split(",");
    // use those values as lat and long
    var lat = latlong_array[0];
    var long = latlong_array[1];

    // redirect
    document.location="http://www.quakr.co.uk/viewr/?lat="+lat+"&lon="+long+"&tag=";
}

function GoogleMapsQuakrLinkSetup() {


	// create the link to the javascript function
	var l = document.createElement('a');
	l.innerHTML = "<span style='background-color:#ffff99;padding:6px;border:1px solid #ff9900'>View this location in Quakr</span>";

	var linktothispagelink = document.getElementById('link');
	linktothispagelink.parentNode.appendChild(l);

	l.href = "javascript:void(0)";

	l.addEventListener("click", GoogleMapsQuakrLink, true);
}


GoogleMapsQuakrLinkSetup();
