// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');

//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff'
}); 

var mapview = Titanium.Map.createView();
mapview.top = 0;
mapview.width = Titanium.Platform.displayCaps.platformWidth;
mapview.right = 0;
mapview.height = Titanium.Platform.displayCaps.platformHeight;
mapview.bottom = 0;
mapview.region = {
	latitude:51.075950647,
	longitude: -0.648193359375,
	latitudeDelta: 0.03,
	longitudeDelta: 0.03
};
win1.add(mapview);

var annotation = Titanium.Map.createAnnotation({
	latitude: 51.075950647,
    longitude: -0.648193359375,
	title: 'Point One',
	subtitle:  'This is the first annotation / route point',
	pinImage: 'letter_a.png',
    leftButton: 'number_1.png'
});

var annotation2 = Titanium.Map.createAnnotation({
	latitude: 51.175980647,
    longitude: -0.659193359375,
	title: 'Point Two',
	subtitle:  'This is the second annotation / route point',
	pinImage: 'letter_b.png',
    leftButton: 'number_1.png'
});

var annotation3 = Titanium.Map.createAnnotation({
	latitude: 51.076873982,
    longitude: -0.698293359375,
	title: 'Point Three',
	subtitle:  'This is the third annotation / route point',
	pinImage: 'letter_c.png',
    leftButton: 'number_1.png'
});


var annotation5 = Titanium.Map.createAnnotation({
	latitude: 51.175950647,
    longitude: -0.548193359375,
	title: 'Point One',
	subtitle:  'This is the first annotation / route point',
	pinImage: 'letter_a.png',
    leftButton: 'number_1.png'
});

var annotation6 = Titanium.Map.createAnnotation({
	latitude: 51.275980647,
    longitude: -0.559193359375,
	title: 'Point Two',
	subtitle:  'This is the second annotation / route point',
	pinImage: 'letter_b.png',
    leftButton: 'number_1.png'
});

var annotation7 = Titanium.Map.createAnnotation({
	latitude: 51.176873982,
    longitude: -0.598293359375,
	title: 'Point Three',
	subtitle:  'This is the third annotation / route point',
	pinImage: 'letter_c.png',
    leftButton: 'number_1.png'
});

var annotation8 = Titanium.Map.createAnnotation({
	latitude: 51.376873982,
    longitude: -0.798293359375,
	title: 'Point Three',
	subtitle:  'This is the third annotation / route point',
	pinImage: 'letter_c.png',
    leftButton: 'number_1.png'
});


// var points = [];
// var entry = {latitude:annotation.latitude,longitude:annotation.longitude};
// points.push(entry);
// entry = {latitude:annotation2.latitude,longitude:annotation2.longitude};
// points.push(entry);
// entry = {latitude:annotation3.latitude,longitude:annotation3.longitude};
// points.push(entry);

// route object
var route  = Titanium.Map.createRoute({
	//name:"boston",
	color:"green",
	width:4,
	length:3//,
	//coords:points
	
	
});

// route object
var route2  = Titanium.Map.createRoute({
	//name:"boston",
	color:"blue",
	width:3,
	length:4//,
	//coords:points
});

var routePoints = [];

var classicWay = false;

if (classicWay) {
mapview.newRoute(route);
mapview.addRoutePoint(Titanium.Map.createPoint({latitude:annotation.latitude,longitude:annotation.longitude}));
mapview.addRoutePoint(Titanium.Map.createPoint({latitude:annotation2.latitude,longitude:annotation2.longitude}));
mapview.addRoutePoint(Titanium.Map.createPoint({latitude:annotation3.latitude,longitude:annotation3.longitude}));

mapview.newRoute(route2);
mapview.addRoutePoint(Titanium.Map.createPoint({latitude:annotation5.latitude,longitude:annotation5.longitude}));
mapview.addRoutePoint(Titanium.Map.createPoint({latitude:annotation6.latitude,longitude:annotation6.longitude}));
mapview.addRoutePoint(Titanium.Map.createPoint({latitude:annotation7.latitude,longitude:annotation7.longitude}));
mapview.addRoutePoint(Titanium.Map.createPoint({latitude:annotation8.latitude,longitude:annotation8.longitude}));
mapview.updateRoutes();
} else {
	//Routes detail
	mapview.newRoute(route);
	mapview.newRoute(route2);
	
	// points
	routePoints.push(Titanium.Map.createPoint({latitude:annotation.latitude,longitude:annotation.longitude}));
	routePoints.push(Titanium.Map.createPoint({latitude:annotation2.latitude,longitude:annotation2.longitude}));
	routePoints.push(Titanium.Map.createPoint({latitude:annotation3.latitude,longitude:annotation3.longitude}));

	routePoints.push(Titanium.Map.createPoint({latitude:annotation5.latitude,longitude:annotation5.longitude}));
	routePoints.push(Titanium.Map.createPoint({latitude:annotation6.latitude,longitude:annotation6.longitude}));
	routePoints.push(Titanium.Map.createPoint({latitude:annotation7.latitude,longitude:annotation7.longitude}));
	routePoints.push(Titanium.Map.createPoint({latitude:annotation8.latitude,longitude:annotation8.longitude}));
	
	//We add all points at a time
	mapview.addRoutePoints(routePoints);
}




//use the same annotations for the annotations selectors that we used for routing
var annotation4 = Titanium.Map.createAnnotation({
	latitude: 51.086873982,
    longitude: -0.708293359375,
	title: 'Point Four',
	subtitle: 'This is the fourth annotation point - it doesn\'t appear on the route',
	pinImage: 'number_1.png',
    leftButton: 'number_1.png'
});

mapview.addAnnotationLight(annotation);
mapview.addAnnotationLight(annotation2);
mapview.addAnnotationLight(annotation3);
mapview.addAnnotationLight(annotation4);
mapview.updateAnnotations();

// open window
win1.open();