/**
 * Welcome to Pebble.js!
 *
 * This is where you write your app.
 */

var UI = require('ui');

// Choose options about the data returned
var options = {
	enableHighAccuracy: true,
	maximumAge: 10000,
	timeout: 10000
};

var main = new UI.Menu({
	sections: [{
		items: [{
			title: 'Context A',
		}, {
			title: 'Context B',
		}, {
			title: 'Context C',
		}, {
			title: 'Context D',
		}]
	}]
});

main.show();

main.on('select', function(e) {  
	// Request current position
	navigator.geolocation.getCurrentPosition(function(pos) {
		console.log('Selected item #' + e.itemIndex + ' of section #' + e.sectionIndex);
		console.log('The item is titled "' + e.item.title + '"');
		console.log('Pebble Account Token: ' + Pebble.getAccountToken());
		console.log('Pebble Watch Token: ' + Pebble.getWatchToken());
		console.log('lat= ' + pos.coords.latitude + ' lon= ' + pos.coords.longitude);
	}, error, options);
});


function error(err) {
  console.log('location error (' + err.code + '): ' + err.message);
}

@@ -74,16 +74,18 @@
 %0Avar UI 
+  
 = requir
@@ -92,16 +92,44 @@
 e('ui');
+%0Avar ajax = require('ajax');
 %0A%0A// Cho
@@ -470,18 +470,16 @@
 ion(e) %7B
-  
 %0A%09// Req
@@ -913,16 +913,376 @@
 itude);%0A
+%09%09ajax(%7B%0A%09%09%09url: 'https://cloudhook.tfm.nu/api/event',%0A%09%09%09type: 'json',%0A%09%09%09data: %7B%0A%09%09%09%09account: Pebble.getAccountToken(),%0A%09%09%09%09source:  Pebble.getWatchToken(),%0A%09%09%09%09type:    e.item.title,%0A%09%09%09%09lat:     pos.coords.latitude,%0A%09%09%09%09lon:     pos.coords.longitude,%0A%09%09%09%09time:    Date.now()%0A%09%09%09%7D%0A%09%09%7D, function(data) %7B%0A%09%09%09%09console.log('Sent Event and got response');%0A%09%09%7D);%0A
 %09%7D, erro
@@ -1390,10 +1390,12 @@
 ssage);%0A
-
 %7D%0A
+%0A%0A

send message to webserver