       frame = that.layerFrames[s][name]
       if frame.point
         that.ctx.drawImage(that.layerImgs[s], frame.pos.x, frame.pos.y, frame.width, frame.height, frame.point.x, frame.point.y, frame.width, frame.height)
-      return
 
   setLayerPoint: (s, frameName, point) ->
     if @layerFrames[s].hasOwnProperty frameName

  constructor: (idTag, layers) ->
    @tag = $('#' + idTag)
    @layers = layers
    @ctx = @tag[0].getContext('2d')
    @layerImgs = []
    frameUrl = @tag.attr('data-frame')
    @frames = []
    bgName = 'map'+@tag.attr('data-area')+'-'+@tag.attr('data-info')
    @bgLayers = [bgName, bgName+'_point']
    that = @
    $.ajax
      url: frameUrl
      async: false
      dataType: 'json'
      success: (data) ->
        data.forEach (d) ->
          that.frames[d.name] = {pos: {x: d.posX, y: d.posY}, width: d.width, height: d.height}
    @layerFrames = []
    @layers.forEach (s) ->
      $.getJSON frameUrl + '?suffix=' + s, (data) ->
        that.layerFrames[s] = {}
        data.forEach (d) ->
          that.layerFrames[s][d.name] = {pos: {x: d.posX, y: d.posY}, width: d.width, height: d.height}
    @loadImage()
    @tag.click (event) ->
      dElm = document.documentElement
      dBody = document.body


class @SeaMap
  constructor: (idTag) ->
    @tag = $('#' + idTag)
    @positions = []
    @cellInfos = {}
    @toAlpha = []
    @layers = []
    layerUrl = @tag.attr('data-layer')
    if layerUrl
      that = @
      $.getJSON layerUrl, (data) ->
        that.layers = data
        image = new MapImage(idTag, that.layers)
        image.onclick = that.runClick
        that.image = image
        that.load()
    else
      @image = new MapImage(idTag, @layers)
      @image.onclick = @runClick
      @load()

  load: () ->
    posUrl = @tag.attr('data-position')
    infoUrl = @tag.attr('data-cellinfo')
    that = @
    @image.onload = () ->
      $.when(
        $.getJSON(posUrl),
        if infoUrl then $.getJSON(infoUrl) else null
