var iPhone = {
  setup: function() {
    debug('running on iPhone');
  }

  ,updateLocation: function(callback) {
    window.open("location:", "_self");
  }

  ,pauseUpdates: function(pauseUpdates) {
  }
  
  ,showLocation: function(lat, lng) {
    window.open("http://maps.google.com/?q=" + lat +
                "%2C" + lng + "&ll=" + lat + "%2C" + lng, "_self");
  }
  
  ,openShop: function() {
    window.open('http://start.speedymarks.com', '_self')
  }
  
  ,sendMail: function(subject, body) {
    window.open("mailto:?subject=" + subject + "&body=" + body, "_self");  
  }
  
  ,openLink: function(url) {
    window.open(url, '_self');
  }

};

var gPhone = {
    setup: function() {
      debug("called");
    }

    ,updateLocation: function(callback) {
      window.android.updateLocation();
    }

    ,pauseUpdates: function(pauseUpdates) {
      window.android.setPause(pauseUpdates);
    }

    ,showLocation: function(lat, lng) {
      window.open("http://maps.google.com/?q=" + lat +
                  "%2C" + lng + "&ll=" + lat + "%2C" + lng, "_self");
    }
    
    ,openShop: function() {
      window.open('http://market.android.com/search?q=pub:SpeedyMarks', '_self')
    }  

    ,sendMail: function(subject, body) {
      body = body.replace(/<br>/g, "%0A");
      body = body.replace(/\&/g, "%26");
      window.open("mailto:?subject=" + subject + "&body=" + body, "_self");  
    }  

    ,openLink: function(url) {
      window.open(url, '_self');
    }

  };

var testPhone = {
    setup: function() {
      debug('running in browser: ' + navigator.geolocation);
      if (!navigator.geolocation && $("Unsupported")) {
        $("Unsupported").style.display = "block";
      }  
    }

    ,watchId: null

    ,updateLocation: function(callback) {
      if (navigator.geolocation) {
        startLocation();
        var callback = function(position) {
          setLocation(position.coords.latitude, position.coords.longitude, 
              position.coords.altitude, position.accuracy, position.speed, null);
          if (position.coords.bearing != null) {
            setBearing(position.coords.bearing);
          }  
        };
        navigator.geolocation.getCurrentPosition(callback, 
          function() {setLocation("error")}, {timeout:14000});
        this.watchId = navigator.geolocation.watchPosition(callback, 
          function() {setLocation("error")}, {timeout:14000});
      }
      else {
        setLocation(Math.random() * 90, Math.random() * 180, Math.random() * 9000);
      }  
    }
    
    ,pauseUpdates: function(pauseUpdates) {
      if (navigator.geolocation) {
        navigator.geolocation.clearWatch(this.watchId);
      }
    }
    
    ,showLocation: function(lat, lng) {
      window.open("http://maps.google.com/?q=" + lat +
                  "%2C" + lng + "&ll=" + lat + "%2C" + lng, "_blank");
    }
    
    ,openShop: function() {
      window.open('http://start.speedymarks.com', '_blank')
    }  

    ,sendMail: function(subject, body) {
      window.open("mailto:?subject=" + subject + "&body=" + body, "_self");  
    }  

    ,openLink: function(url) {
      window.open(url, '_blank');
    }

  }
