define(['scripts/data/store', 'scripts/drawing/helpers/elements', 'scripts/drawing/helpers/variables', 'scripts/drawing/helpers/calculate','scripts/drawing/nodes/hover'], function(store, elements, variables, calculate, hover) {

  function draw() {
    var paper = elements.paper();
    var set = elements.meetings();

    var arrow_height = 25;
    var arrow_width = 30;

    for (var i = 0; i < store.Meeting().length; i++) {
      var current_set = paper.set();
      var current_event = store.Meeting()[i];
      var horizontal = calculate.horizontal(current_event);

      var stroke = 0;
      if (current_event.Analyzed == "Yes") {
        stroke = variables.drawing().stroke_width;
      }

      var center_x = horizontal.x;
      var center_y = variables.drawing().events_y;

      var shape = paper.path("M{0},{1},{2},{3},{4},{5}z", center_x, center_y - (arrow_height / 2), center_x + (arrow_width / 2), center_y + (arrow_height / 2), center_x - (arrow_width / 2), center_y + (arrow_height / 2));

      shape.attr({
        "fill": "white",
        "stroke": "black",
        "stroke-width": stroke
      });

      var code = paper.text(horizontal.x, variables.drawing().events_y + 6, "Me" + current_event.id);
      code.attr({
        "text-anchor": "middle",
        'font-size': 8,
        "font-family": "Georgia",
        "fill": "#000"
      });

      //hover values
      var hover_left = horizontal.x + 10;
      var hover_top = variables.drawing().events_y;
      var hover_width = 200;
      var hover_height = 150;
      hover_set = hover.create(hover_left, hover_top, hover_width, hover_height, 0, "Me" + current_event.id,"Goal: " + current_event.Goal + ", Result: " + current_event.Result);

      //add both to a set
      current_set.push(shape, code, hover_set);

      var hoverIn = function() {
        this[0].attr({"cursor": "pointer"});
        this[1].attr({"cursor": "pointer"});
        this[2].show().animate({ opacity : 1 }, 100);
      };

      var hoverOut = function() {
        this[0].attr({"cursor": "default"});
        this[1].attr({"cursor": "default"});
        this[2].animate({ opacity : 0 }, 100, function () { this.hide(); });
      }

      current_set.hover(hoverIn, hoverOut, current_set, current_set);
      set.push(current_set);

      //remember the middle point for relations
      store.Meeting()[i].x = horizontal.x;
      store.Meeting()[i].y = variables.drawing().events_y;

      shape.type = "meeting";
      shape.instance = current_event;
      shape.text = code;
    }

  }

  return {
    draw: draw
  };

});
