﻿<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="WA Petrol Prices"
             description="See the cheapest fuel prices in Perth, Western Australia"
             author="Reto Meier"
             author_email="petrol@radioactiveyak.com"
             author_affiliation="Radioactive Yak Software"
             author_location="London, UK"
             author_link="http://blog.radioactiveyak.com"
             screenshot="http://www.radioactiveyak.com/mapplets/petrol/wapetrolprices.png"
             thumbnail="http://www.radioactiveyak.com/mapplets/petrol/wapetrolprices-thm.png"
             height="150">
  <Require feature="sharedmap"/>
  <Require feature="setprefs" />
  <Require feature="analytics"/>
</ModulePrefs>
<UserPref    
  name="SuburbOne"    
  display_name="Suburb 1"
  default_value="West Perth"    
  datatype="string"/>
<UserPref    
  name="SuburbTwo"    
  display_name="Suburb 2"
  default_value="Duncraig"    
  datatype="string"/>
<UserPref    
  name="SuburbThree"    
  display_name="Suburb 3"
  default_value="Bicton"   
  datatype="string"/>
<Content type="html"><![CDATA[

   <script>
     // Track this gadget using Google Analytics.
     _IG_Analytics("UA-51268-11", "/WAPetrolPriceMapplet");
   </script>
   
<input type="button" value="Refresh Prices" onclick="buttonClicked();">   
<p>
<b>Find the Cheapest Fuel on Your Journey</b><br/>
'Edit settings' to select the suburbs you regularly travel through.
</p>
<div id="message" style="margin-top:1em"></span>

<script>
// Get user preferences     
var prefs = new _IG_Prefs(__MODULE_ID__);     
var message = document.getElementById("message");
var map = new GMap2();

centerMapOnPerth();
showCounter();

// Get the markers
function applyMarkers() {
  var s1 = prefs.getString("SuburbOne");
  var s2 = prefs.getString("SuburbTwo");
  var s3 = prefs.getString("SuburbThree");

  s1 = s1.replace(/ /g, "+");
  s2 = s2.replace(/ /g, "+");
  s3 = s3.replace(/ /g, "+");

  var basePath = "http://pipes.yahoo.com/pipes/pipe.run?_id=rNY8onsw3BG_flEKzKky6g&_render=kml&_run=1";  
  var lookupString = basePath + "&textinput1=" + s1 + "&textinput2=" + s2 + "&textinput3=" + s3;  
    
  var geoXml = new GGeoXml(lookupString);
  map.clearOverlays();
  map.addOverlay(geoXml);
}

// Show the current value of the counter     
function showCounter() {
	   applyMarkers();
       var s1 = prefs.getString("SuburbOne");
       var s2 = prefs.getString("SuburbTwo");
       var s3 = prefs.getString("SuburbThree");
       var tail = '<br/><br/><small>Petrol Prices courtesy of <a href="http://www.fuelwatch.com.au">Fuel Watch</a>.<br/>How was this made: at <a href="http://blog.radioactiveyak.com">The Radioactive Yak</a>.</small>';
       message.innerHTML = "Currently viewing the lowest petrol prices from:" + "<br/>" + s1 + "<br/>" + s2 + "<br/>" + s3 + tail;       
}

function buttonClicked(){
  centerMapOnPerth();
  applyMarkers();
}

function centerMapOnPerth() {
  var latlng = new GLatLng(-31.913119,115.885162);
  map.setCenter(latlng, 11);
}

</script>

]]></Content>
</Module>
