// Copyright 2006 comparetracks.com 
// Written by Terje Henriksen 
// Copy, modification or reuse of code is herby granted 

Route = function() {
  this.north = -90;
  this.south = 90;
  this.east = -180;
  this.west = 180;
  this.inited = false;
  this.name = "";
  this.gPoints = new Array();
  this.trackPoints = new Array();
  this.splitPoints = new Array();
  this.markers = new Array();
  this.iconImage = null;
  this.icon=null;
  this.computeBoundaries = computeBoundaries;
  this.createMarker = createMarker;
  this.description = description;


  function computeBoundaries() {
    for(var j=0;j<this.trackPoints.length;j++) {
      if(this.trackPoints[j].lat < this.south)
        this.south = this.trackPoints[j].lat;
      if(this.trackPoints[j].lat > this.north)
        this.north = this.trackPoints[j].lat;
      if(this.trackPoints[j].lon > this.east)
        this.east = this.trackPoints[j].lon;
      if(this.trackPoints[j].lon < this.west)
        this.west = this.trackPoints[j].lon;
     }
     
     this.iconImage = "http://www.sportsim.com/splitLive/images/splitMarker.png";
     this.icon = new GIcon();
     this.icon.image = this.iconImage; 
     this.icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
     this.icon.iconSize = new GSize(32, 32);
     this.icon.shadowSize = new GSize(32, 32);
     this.icon.iconAnchor = new GPoint(16, 16);
     this.icon.infoWindowAnchor = new GPoint(16,16);
     this.inited = true;
  }
  
  function createMarker(inx) {
    
    //this.markers.push(new GMarker(new GLatLng(this.splitPoints[inx].lat,this.splitPoints[inx].lon),this.icon));
    this.markers.push(new GMarker(new GLatLng(this.splitPoints[inx].lat,this.splitPoints[inx].lon)));
    //var pdMarker = new PdMarker(new GLatLng(this.splitPoints[inx].lat,this.splitPoints[inx].lon));
    //this.markers.push(pdMarker);
	  //pdMarker.setTooltip("Vancouver");

    GEvent.addListener(this.markers[inx], 'click', function() {
      selectSplit(inx);
    }); 
    
        //this.splitPoints[inx].marker = new GMarker(new GLatLng(this.splitPoints[inx].lat,this.splitPoints[inx].lon),this.icon);           
        //GEvent.addListener(this.splitPoints[inx].marker, 'click', function() {
        //  selectSplit(inx);
        //}); 
    }
    
    function description(inx) {
        //return "<b>" + this.splitPoints[inx].name + "</b><br><b>" + parseInt(this.splitPoints[inx].meter / 1000) + "</b> km";
        return "<b>" + this.splitPoints[inx].name + "</b><br>";
    }
};
