window.cmu = window.cmu || {};

(function (ns) {

    ns.line = function (spec, my) {
        var that;

        spec = spec || {};
        spec.elementId = spec.elementId || 'lineCanvas';
        spec.container = spec.container || $('#header > .inner');
        spec.lineFrom = spec.lineFrom || [0, 0];
        spec.lineTo = spec.lineTo || [-67, 111];
        spec.lineOffset = spec.lineOffset || [4, 4];
        spec.canvasWidth = spec.canvasWidth || null;
        spec.canvasHeight = spec.canvasHeight || null;

        // ------------------------------------------------------------------
        // Shared properties
        // ------------------------------------------------------------------

        my = my || {};
        my.logger = my.logger || gj.logging.getLogger('cmu.line');

        // ------------------------------------------------------------------
        // Private methods
        // ------------------------------------------------------------------

        my.initExtra = function () {
            my.logger.debug('initExtra()');

            my.canvas.width = spec.canvasWidth || Math.abs(spec.lineTo[0]) + spec.lineOffset[0];
            my.canvas.height = spec.canvasHeight || Math.abs(spec.lineTo[1]) + spec.lineOffset[1];
        };

        my.draw = my.draw || function () {
            my.logger.debug('draw()');

            var ctx = my.ctx;
            ctx.save();

            ctx.translate(my.canvas.width, 0);

            ctx.lineWidth = 5;
            ctx.beginPath();
            ctx.moveTo(
                spec.lineFrom[0] + spec.lineOffset[0] * -1,
                spec.lineFrom[1] + spec.lineOffset[1]
            );
            ctx.lineTo(spec.lineTo[0], spec.lineTo[1]);
            ctx.stroke();

            ctx.restore();
        };

        // Important: inherit from canvasDrawer()
        that = gj.canvasDrawer(spec, my);

        // ------------------------------------------------------------------
        // Public methods
        // ------------------------------------------------------------------

        that.draw = my.draw;

        // ------------------------------------------------------------------
        // Constructor
        // ------------------------------------------------------------------

        my.init();
        return that;
    };

})(window.cmu);

