//challenge.js
//contains:
// addPolyline (color, polyline, weight)
// tmr (interval)
// createMarker (point, icon, indes)
// createImageMarker (point, icon, index, temp)
// dreateCommentMarker (point, icon, index, temp)
// leadingzero (number)
// sectotime (sec)

function addPolyline (color, polyline, weight){
mainmap.addOverlay(new GPolyline.fromEncoded({ color: color,
                               weight: weight, 
                               points: polyline,
                               opacity: 1, 
                               levels: 'P?P', 
                               zoomFactor: 0, 
                               numLevels: 0}));
  }

function tmr(interval){
    if (interval==0){
    window.clearInterval(tm);
    }else{
    window.clearInterval(tm);
    tm=window.setInterval(update,interval);
    }
}

      function createMarker(point, icon, index) {
        var marker = new GMarker(point, icon);

        tp[index] = new ELabel(point, " ", "style1", new GSize(13,-13), 80);
        marker.tooltip = tp[index];
        mainmap.addOverlay(marker.tooltip);
        
        marker.tooltip.hide();

        GEvent.addListener(marker,"mouseover", function() {
         if (!$('li[user='+index+']').hasClass('ui-state-active')){
          this.tooltip.show();
         }
        });        
        GEvent.addListener(marker,"mouseout", function() {
         if (!$('li[user='+index+']').hasClass('ui-state-active')){
          this.tooltip.hide();
         }
        });
        GEvent.addListener(marker,"click", function() {
         if (!$('li[user='+index+']').hasClass('ui-state-active')){
          this.tooltip.show();
          $('li[user='+index+']').addClass('ui-state-active')
         } else {
          this.tooltip.hide();
          $('li[user='+index+']').removeClass('ui-state-active')
         }
        });
        return marker;        
      }
      function createImageMarker(point, icon, index, temp) {
        var marker = new GMarker(point, icon);
        if (temp==0){
        tpimage[index] = new ELabel(point, " ", "styleimage", new GSize(13,-13), 100);
        marker.tooltip = tpimage[index];
        mainmap.addOverlay(marker.tooltip);
        
        marker.tooltip.hide();

        GEvent.addListener(marker,"mouseover", function() {
          this.tooltip.show();
        });        
        GEvent.addListener(marker,"mouseout", function() {
          this.tooltip.hide();
        });
        }
        return marker;        
      }
      function createCommentMarker(point, icon, index, temp) {
        var marker = new GMarker(point, icon);
        if (temp==0){
        tpcomment[index] = new ELabel(point, " ", "stylecomment", new GSize(13,-13), 100);
        marker.tooltip = tpcomment[index];
        mainmap.addOverlay(marker.tooltip);
        
        marker.tooltip.hide();

        GEvent.addListener(marker,"mouseover", function() {
          this.tooltip.show();
        });        
        GEvent.addListener(marker,"mouseout", function() {
          this.tooltip.hide();
        });
        }
        return marker;        
      }



function leadingzero (number) {
    return (number < 10) ? '0' + number : number;
}
function SecToTime(sek){
      var h = Math.floor(sek/ 3600);
      var m = Math.floor((sek% 3600) / 60);
      var s = sek% 60;
      return  leadingzero(h) + ':' + leadingzero(m) + ':' + leadingzero(s);

}
