/**
 * Represents a checkpoint.
 *
 * param no			 Checkpoint number (MARKSFLAT.MARK_NO)
 * param courseId    MARKSFLAT.COURSE_ID
 * param current     '1', if the checkpoint belongs to the current race
 * param lat         Checkpoint latitude
 * param lon         Checkpoint longitude
 * param name        Checkpoint name
 * param courseName  Name of the course this checkpoint belongs to
 * param passedBoats Number of boats passed so far
 * param firstOnes   Names of the ? first boats to pass
 */
function Checkpoint(no, courseId, current, lat, lon, name, courseName, passedBoats, firstOnes) {
  this.no = no;
  this.courseId = courseId;
  //this.current = current;
  this.lat = lat;
  this.lon = lon;
  this.name = name;
  this.courseName = courseName;
  this.passedBoats = passedBoats;
  this.firstOnes = firstOnes;
  
  this.smallIcon = (current == 1) ? 'img/checkpoint.gif' : 'img/checkpoint_faded.gif';
  this.largeIcon = (current == 1) ? 'img/start_finish.gif' : 'img/start_finish_faded.gif';
  
  this.getIcon = function(small) {
    var icon = new GIcon();
    icon.image = (small) ? this.smallIcon : this.largeIcon;
    icon.iconSize = (small) ? new GSize(8, 8) : new GSize(15, 15);
    icon.iconAnchor = new GPoint(2, 2);
    icon.infoWindowAnchor = new GPoint(5, 1);
    return icon;  
  }
  
  this.getSmallIcon = function() { return this.getIcon(true); };
  this.getLargeIcon = function() { return this.getIcon(false); };
  
  this.toString = function() {
    return 'Checkpoint[no=' + this.no + ',courseId=' + this.courseId +
      ',lat=' + this.lat + ',lon=' + this.lon + ',name=' + this.name +
      ',passedBoats=' + this.passedBoats + ']';
  };
}

function BoatPosition(tstamp, lat, lon, sog, cog, current) {
  this.tstamp = tstamp;
  this.lat = lat;
  this.lon = lon;
  this.sog = sog;
  this.cog = cog;
  this.current = current;
  this.marker = null;
  
  this.getLatitude = function() { return this.lat; };
  this.getLongitude = function() { return this.lon; };
  this.getCog = function() { return this.cog; };
  this.getTstamp = function() { return this.tstamp; };
  this.getMarker = function() { return this.marker; };
  this.setMarker = function(marker) { this.marker = marker; };
}

function P(t, l1, l2, s, c1, c2) {
  this.tstamp = '2008-' + t;
  this.lat = l1;
  this.lon = l2;
  this.sog = s;
  this.cog = c1;
  this.current = c2;
  this.marker = null;
  
  this.getLatitude = function() { return this.lat; };
  this.getLongitude = function() { return this.lon; };
  this.getCog = function() { return this.cog; };
  this.getTstamp = function() { return this.tstamp; };
  this.getMarker = function() { return this.marker; };
  this.setMarker = function(marker) { this.marker = marker; };
}

function BoatData(id, name, skipper, description, status, link, symbol, positions) {
  //this.imgUrl = "http://www.fd2sms.net/lt/frontend/img/symbols/";
  this.imgUrl = "img/symbols/";
  this.name = name;
  this.id = id;
  this.skipper = skipper;
  this.description = description;
  this.status = status;
  this.link = link;
  this.positions = positions;
  this.symbol = symbol;
  this.line = null;
  
  this.getId = function() {
    return this.id;
  };
  
  this.getLastPosition = function() {
    return this.positions[this.positions.length - 1];
  }
  
  this.getIcon = function(cog) {
    var icon;
    if (cog >= 0 && cog <= 90) {
      icon = this.getLargeIcon(this.symbol.neImage);
    } else if (cog > 90 && cog <= 180) {
      icon = this.getLargeIcon(this.symbol.seImage);
    } else if (cog > 180 && cog <= 270) {
      icon = this.getLargeIcon(this.symbol.swImage);
    } else {
      icon = this.getLargeIcon(this.symbol.nwImage);
    }
    return icon;
  }
        
  this.getLargeIcon = function(image) {
    var icon = new GIcon();
    icon.image = this.imgUrl + image;
    icon.iconSize = new GSize(18, 19);
    icon.iconAnchor = new GPoint(10, 7);
    icon.infoWindowAnchor = new GPoint(5, 1);
    return icon; 
  }
  
  this.getSmallIcon = function() {
    var icon = new GIcon();
    icon.image = this.imgUrl + this.symbol.smallImage;
    //icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    icon.iconSize = new GSize(4, 4);
    //icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(2, 2);
    icon.infoWindowAnchor = new GPoint(5, 1);
    return icon;  
  }
  
  this.setLine = function(line) {
    this.line = line;
  }
  
  this.getLine = function() {
    return this.line;
  }
}

function BoatSymbol(neImage, seImage, swImage, nwImage, smallImage, lineColor) {
  this.neImage = neImage;
  this.seImage = seImage;
  this.swImage = swImage;
  this.nwImage = nwImage;
  this.smallImage = smallImage;
  this.lineColor = lineColor;
  
  this.toString = function() {
    return "neImage=" + this.neImage + ",seImage=" + this.seImage +
      ",swImage=" + this.swImage + ",nwImage=" + this.nwImage;
  };
}

function DegMinSecPos(degrees, mins, secs) {
  this.degrees = degrees;
  this.mins = mins;
  this.secs = secs;
  
  this.toString = function() {
    return this.degrees + '° ' + this.mins + '\' ' + this.secs + '"';
  };
}

