module.exports = Entity

function Entity(paper, relative) {
    var entity = paper.rect()
    var sayText
    entity.hide()
    entity.attr("height", 10)
    entity.attr("width", 10)

    relative.on("visible", onvisible)

    relative.on("invisible", onhide)

    var remove = relative(function (pos) {
        entity.attr("x", pos.x)
        entity.attr("y", pos.y)

        if (sayText) {
            sayText.attr("x", pos.x + 5)
            sayText.attr("y", pos.y - 10)
        }
    })

    entity.cleanup = cleanup
    entity.setSay = setSay

    return entity
    //Raynos, you have a weird code style with functions after the return...

    function cleanup() {
        remove()
        relative.removeListener("visible", onvisible)
        relative.removeListener("invisible", onhide)
        entity.remove()
    }

    function onvisible() {
        entity.show()
    }

    function onhide() {
        entity.hide()
    }


    function setSay(name) {
        if (!sayText) {
            sayText = paper.text(relative.x + 50
                , relative.y - 30, name)
            sayText.attr("fill", "red")
        } else {
            sayText.attr("text", name)
        }
    }
}

@@ -18,16 +18,54 @@
 Entity%0A%0A
+//the Row should be passed in here...%0A
 function
@@ -121,16 +121,48 @@
 .rect()%0A
+//  var bounds = paper.circle()%0A
     var 
@@ -169,16 +169,17 @@
 sayText%0A
+%0A
     enti
@@ -214,17 +214,17 @@
 eight%22, 
-1
+5
 0)%0A    e
@@ -247,13 +247,630 @@
 h%22, 
-1
+5
 0)%0A%0A
+//    bounds.hide()%0A//    entity.attr(%22r%22, 50)%0A//    bounds.attr(%22fill%22, %22grey%22)%0A%0A%0A    /*%0A      Raynos, this stuff is weird.%0A      it would be easier to understand if it was more procedural.%0A%0A      I want to access the model here... but instead I just have this%0A      screen point thing.%0A%0A      something this:%0A%0A      row.on('change', function () %7B%0A%0A        if(screen.isVisible(row)) %7B%0A          view.attr('x', screen.rel('x', row.get('x')))%0A          view.attr('y', screen.rel('y', row.get('y')))%0A          view.show()%0A        %7D%0A        else%0A          view.hide()%0A%0A      %7D)%0A%0A      would be WAY more obvious.%0A    */%0A%0A
     
@@ -981,24 +981,131 @@
 ion (pos) %7B%0A
+%0A//      console.log('REL', pos.x, pos.y)%0A//      bounds.attr(%22x%22, pos.x)%0A//      bounds.attr(%22y%22, pos.y)%0A%0A
         enti
@@ -1122,16 +1122,21 @@
 %22, pos.x
+ - 25
 )%0A      
@@ -1151,32 +1151,37 @@
 .attr(%22y%22, pos.y
+ - 25
 )%0A%0A        if (s
@@ -1228,17 +1228,18 @@
 pos.x + 
-5
+20
 )%0A      
@@ -1271,17 +1271,17 @@
 os.y - 1
-0
+5
 )%0A      
@@ -1648,24 +1648,46 @@
 visible() %7B%0A
+//      bounds.show()%0A
         enti
@@ -1723,24 +1723,48 @@
  onhide() %7B%0A
+    //    bounds.hide()%0A
         enti
@@ -1780,17 +1780,16 @@
 %0A    %7D%0A%0A
-%0A
     func

comment for Raynos