// Copyright (c) 2009 The Chromium Authors. All rights reserved.  Use of this
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.

function isHighVersion() {
  var version = navigator.userAgent.match(/Chrome\/(\d+)/)[1];
  return version > 9;
}

function $(id) {
  return document.getElementById(id);
}
function i18nReplace(id, messageKey) {
  return $(id).innerHTML = chrome.i18n.getMessage(messageKey);
}

var bg = chrome.extension.getBackgroundPage();
var canvas = new Canvas();
var photoshop = {
  canvas: document.createElement("canvas"),
  tabTitle: '',
  startX: 0,
  startY: 0,
  endX: 0,
  endY: 0,
  dragFlag: false,
  flag: 'rectangle',
  layerId: 'layer0',
  canvasId: '',
  color: '#ff0000',
  highlightColor: '',
  lastValidAction: 0,
  markedArea: [],
  isDraw: true,
  offsetX: 0,
  offsetY: 36,
  nowHeight: 0,
  nowWidth: 0,
  highlightType: 'border',
  highlightMode: 'rectangle',
  text: '',

  i18nReplace: i18nReplace,

  initCanvas: function() {
    $('canvas').width = $('mask-canvas').width = $('photo').style.width =
        photoshop.canvas.width = bg.screenshot.canvas.width;
    $('canvas').height = $('mask-canvas').height = $('photo').style.height =
        photoshop.canvas.height = bg.screenshot.canvas.height;
    var context = photoshop.canvas.getContext('2d');
    context.drawImage(bg.screenshot.canvas, 0, 0);
    context = $('canvas').getContext('2d');
    context.drawImage(photoshop.canvas, 0, 0);
    $('canvas').style.display = 'block';
  },

  init: function() {
    photoshop.initTools();
    photoshop.initCanvas();
    photoshop.tabTitle = bg.screenshot.tab.title;
    var showBoxHeight = function() {
      $('showBox').style.height = window.innerHeight - photoshop.offsetY - 1;
    }
    setTimeout(showBoxHeight, 50);
  },

  markCurrentElement: function(element) {
    if (element && element.parentNode) {
      var children = element.parentNode.children;
      for (var i = 0; i < children.length; i++) {
        var node = children[i];
        if (node == element) {
          element.className = 'mark';
        } else {
          node.className = '';
        }
      }
    }
  },

  setHighLightMode: function() {
    photoshop.highlightType = localStorage.highlightType || 'border';
    photoshop.color = localStorage.highlightColor || '#FF0000';
    $(photoshop.layerId).style.border = '2px solid ' + photoshop.color;
    if (photoshop.highlightType == 'rect') {
      $(photoshop.layerId).style.backgroundColor = photoshop.color;
      $(photoshop.layerId).style.opacity = 0.5;
    }
    if (photoshop.flag == 'rectangle') {
      $(photoshop.layerId).style.borderRadius = '0 0';
    } else if (photoshop.flag == 'radiusRectangle') {
      $(photoshop.layerId).style.borderRadius = '6px 6px';
    } else if (photoshop.flag == 'ellipse') {
      $(photoshop.layerId).style.border = '0';
      $(photoshop.layerId).style.backgroundColor = '';
      $(photoshop.layerId).style.opacity = 1;
    }

  },

  setBlackoutMode: function() {
    photoshop.color = '#000000';
    $(photoshop.layerId).style.opacity = 1;
    $(photoshop.layerId).style.backgroundColor = '#000000';
    $(photoshop.layerId).style.border = '2px solid #000000';
  },

  setTextMode: function() {
    localStorage.fontSize = localStorage.fontSize || '16';
    photoshop.color = localStorage.fontColor =
        localStorage.fontColor || '#FF0000';
    $(photoshop.layerId).setAttribute('contentEditable', true);
    $(photoshop.layerId).style.border = '1px dotted #333333';
    $(photoshop.layerId).style.cursor = 'text';
    $(photoshop.layerId).style.lineHeight = localStorage.fontSize + 'px';
    $(photoshop.layerId).style.fontSize = localStorage.fontSize + 'px';
    $(photoshop.layerId).style.color = photoshop.color;
    $(photoshop.layerId).innerHTML = '<br/>';
    var layer = $(photoshop.layerId);
    var id = photoshop.layerId;
    layer.addEventListener('blur', function() {
      photoshop.setTextToArray(id);
    }, true);
    layer.addEventListener('click', function() {
      this.style.border = '1px dotted #333333';
    }, true);
    layer.addEventListener('mouseout', function() {
      if (!photoshop.dragFlag) {
        this.style.borderWidth = 0;
      }
    }, false);
    layer.addEventListener('mousemove', function() {
      this.style.border = '1px dotted #333333';
    }, false);
  },

  setTextToArray: function(id) {
    var str = $(id).innerText.split("\n");
    if (photoshop.markedArea.length > 0) {
      for (var i = photoshop.markedArea.length - 1; i >= 0; i--) {
        if (photoshop.markedArea[i].id == id) {
          photoshop.markedArea[i].context = str;
          break;
        }
      }
      $(id).style.borderWidth = 0;
    }
  },

  openOptionPage: function() {
    chrome.tabs.create({url: chrome.extension.getURL("options.html")});
  },

  closeCurrentTab: function() {
    chrome.tabs.getSelected(null, function(tab) {
      chrome.tabs.remove(tab.id);
    });
  },

  finish: function() {
    var context = $('canvas').getContext('2d');
    context.drawImage(photoshop.canvas, 0, 0);
  },

  colorRgba: function(color, opacity) {
    var sColor = color.toLowerCase();
    var sColorChange = [];
    for (var i = 1; i < sColor.length; i += 2) {
      sColorChange.push(parseInt("0x" + sColor.slice(i,i + 2)));
    }
    return "rgba(" + sColorChange.join(",") + "," + opacity + ")";
  },

  /**
  * Undo the current operation
  */
  toDo: function(element, what) {
    photoshop.flag = what;
    photoshop.isDraw = true;
    photoshop.markCurrentElement(element);
  },

  setDivStyle: function(x, y) {
    $(photoshop.layerId).setAttribute("style", "");
    $(photoshop.layerId).setAttribute("contentEditable", false);
    switch(photoshop.flag) {
      case 'rectangle':
      case 'radiusRectangle':
      case 'ellipse':
        photoshop.setHighLightMode();
        break;
      case 'redact':
        photoshop.setBlackoutMode();
        break;
      case 'text':
        photoshop.setTextMode();
        break;
      case 'line':
      case 'arrow':
        photoshop.drawLineOnMaskCanvas(x, y, x, y, 'lineStart',
            photoshop.layerId);
        break;
      case 'blur':
        photoshop.createCanvas(photoshop.layerId);
        break;
    }
  },

  /**
  * Create a layer and set style
  */
  createDiv: function() {
    photoshop.lastValidAction++;
    photoshop.layerId = 'layer' + photoshop.lastValidAction;
    if ($(photoshop.layerId)) {
      photoshop.removeElement(photoshop.layerId);
    }
    var divElement = document.createElement('div');
    divElement.id = photoshop.layerId;
    divElement.className = 'layer';
    $('photo').appendChild(divElement);
    if (photoshop.flag  == 'blur') {
      photoshop.createCanvas(photoshop.layerId);
    }
    return divElement;
  },

  createCanvas: function(parentId) {
    photoshop.canvasId = 'cav-' + parentId;
    if (!$(photoshop.canvasId)) {
      var cav = document.createElement('canvas');
      cav.id = photoshop.canvasId;
      cav.width = 10;
      cav.height = 10;
      $(photoshop.layerId).appendChild(cav);
      return cav;
    }
    return $(photoshop.canvasId);

  },

  createCloseButton: function(parent, id, left, top, flag) {
    var imgElement = document.createElement('img');
    imgElement.id = id;
    imgElement.src = 'images/cross.png';
    imgElement.className = 'closeButton';
    imgElement.style.left = left - 15 + 'px';
    if (photoshop.flag == 'line' || photoshop.flag == 'arrow') {
      imgElement.style.left = left / 2 - 5 + 'px';
      imgElement.style.top = top / 2 - 5 + 'px';
    }
    imgElement.onclick = function() {
      $(parent).style.display = 'none';
      photoshop.removeLayer(parent);
    };
    $(parent).onmousemove = function() {
      if (!photoshop.dragFlag) {
        photoshop.showCloseButton(id);
        $(parent).style.zIndex = 110;
        photoshop.isDraw = (flag == 'text' ? false : photoshop.isDraw);
      }
    };
    $(parent).onmouseout = function() {
      photoshop.hideCloseButton(id);
      $(parent).style.zIndex = 100;
      photoshop.isDraw = true;
    };
    $(parent).appendChild(imgElement);
    return imgElement;
  },

  showCloseButton: function(id) {
    $(id).style.display = 'block';
  },

  hideCloseButton: function(id) {
    $(id).style.display = 'none';
    photoshop.isDraw = true;
  },

  removeLayer: function(id) {
    for (var i = 0; i < photoshop.markedArea.length; i++) {
      if (photoshop.markedArea[i].id == id) {
        photoshop.markedArea.splice(i, 1);
        break;
      }
    }
    photoshop.removeElement(id);
  },

  /**
  *  Set the starting point(x,y) when mouse pressed
  */
  onMouseDown: function(event) {
    if (photoshop.isDraw && event.button != 2) {
      photoshop.startX = event.pageX + $('showBox').scrollLeft -
          photoshop.offsetX;
      photoshop.startY = event.pageY + $('showBox').scrollTop -
          photoshop.offsetY;
      photoshop.setDivStyle(photoshop.startX, photoshop.startY);
      photoshop.dragFlag = true;

      $(photoshop.layerId).style.left = photoshop.startX + 'px';
      $(photoshop.layerId).style.top = photoshop.startY + 'px';
      $(photoshop.layerId).style.height = 0;
      $(photoshop.layerId).style.width = 0;
      $(photoshop.layerId).style.display = 'block';
    }
  },

  onMouseUp: function(event) {
    $('mask-canvas').style.zIndex = 10;
    photoshop.endX = event.pageX + $('showBox').scrollLeft -
           photoshop.offsetX;
      if (photoshop.endX > photoshop.canvas.width) {
        photoshop.endX = photoshop.canvas.width ;
      }

      if (photoshop.endX < 0) {
        photoshop.endX = 0;
      }

      photoshop.endY = event.pageY + $('showBox').scrollTop -
           photoshop.offsetY;
      if (photoshop.endY > photoshop.canvas.height) {
        photoshop.endY = photoshop.canvas.height ;
      }
      if (photoshop.endY < 0) {
        photoshop.endY = 0;
      }
    if (photoshop.isDraw && photoshop.dragFlag && (photoshop.endX !=
        photoshop.startX || photoshop.endY != photoshop.startY)) {
      if (photoshop.flag == 'line' || photoshop.flag == 'arrow') {
        photoshop.drawLineOnMaskCanvas(photoshop.startX, photoshop.startY,
            photoshop.endX, photoshop.endY, 'drawEnd', photoshop.layerId);
      } else if (photoshop.flag == 'blur') {
        canvas.blurImage(photoshop.canvas, $(photoshop.canvasId),
            photoshop.layerId, photoshop.startX, photoshop.startY,
            photoshop.endX, photoshop.endY);
      } else if (photoshop.flag == 'ellipse') {
        photoshop.drawEllipseOnMaskCanvas(photoshop.endX,
            photoshop.endY, 'end', photoshop.layerId);
      }
      photoshop.markedArea.push({
        'id': photoshop.layerId,
        'startX': photoshop.startX,
        'startY': photoshop.startY,
        'endX': photoshop.endX,
        'endY': photoshop.endY,
        'width': photoshop.nowWidth,
        'height': photoshop.nowHeight,
        'flag': photoshop.flag,
        'highlightType': photoshop.highlightType,
        'fontSize': localStorage.fontSize,
        'color': photoshop.color,
        'context': ''
      });
      $(photoshop.layerId).focus();
      var imageBtnId = 'close_' + photoshop.layerId;
      photoshop.createCloseButton(photoshop.layerId, imageBtnId,
          photoshop.nowWidth, photoshop.nowHeight, photoshop.flag);
      photoshop.createDiv();
    } else if (photoshop.endX ==
        photoshop.startX && photoshop.endY == photoshop.startY) {
      photoshop.removeElement(photoshop.layerId);
      photoshop.createDiv();
    }
    photoshop.dragFlag = false;

  },

  /**
  * Refresh div‘s height and width when the mouse move
  */
  onMouseMove: function(event) {
    if(photoshop.dragFlag) {
      $('mask-canvas').style.zIndex = 200;
      photoshop.endX = event.pageX + $('showBox').scrollLeft -
           photoshop.offsetX;
      if (photoshop.endX > photoshop.canvas.width) {
        photoshop.endX = photoshop.canvas.width ;
      }

      if (photoshop.endX < 0) {
        photoshop.endX = 0;
      }

      photoshop.endY = event.pageY + $('showBox').scrollTop -
           photoshop.offsetY;
      if (photoshop.endY > photoshop.canvas.height) {
        photoshop.endY = photoshop.canvas.height ;
      }
      if (photoshop.endY < 0) {
        photoshop.endY = 0;
      }
      photoshop.nowHeight = photoshop.endY - photoshop.startY - 1 ;
      photoshop.nowWidth = photoshop.endX - photoshop.startX - 1 ;

      if(photoshop.nowHeight < 0) {
        $(photoshop.layerId).style.top = photoshop.endY + 'px';
        photoshop.nowHeight = -1 * photoshop.nowHeight;
      }
      if(photoshop.nowWidth < 0) {
        $(photoshop.layerId).style.left = photoshop.endX + 'px';
        photoshop.nowWidth = -1 * photoshop.nowWidth;
      }

      $(photoshop.layerId).style.height = photoshop.nowHeight - 3;
      $(photoshop.layerId).style.width = photoshop.nowWidth - 3;
      if (photoshop.flag == 'line' || photoshop.flag == 'arrow') {
        photoshop.drawLineOnMaskCanvas(photoshop.startX, photoshop.startY,
            photoshop.endX, photoshop.endY, 'lineDrawing', photoshop.layerId);
      } else if (photoshop.flag == 'blur') {
        $(photoshop.layerId).style.height = photoshop.nowHeight ;
        $(photoshop.layerId).style.width = photoshop.nowWidth ;
        canvas.blurImage(photoshop.canvas, $(photoshop.canvasId),
            photoshop.layerId, photoshop.startX, photoshop.startY,
            photoshop.endX, photoshop.endY);
      } else if (photoshop.flag == 'ellipse') {
        photoshop.drawEllipseOnMaskCanvas(photoshop.endX,
            photoshop.endY, 'drawing', photoshop.layerId);
      }
    }

  },

  /**
  * Remove a div
  */
  removeElement: function(id) {
    if($(id)) {
      $(id).parentNode.removeChild($(id));
    }
  },

  /**
  * Use fillStyle, fillText and fillRect functions to draw rectangles,
  * and render to canvas
  */
  draw: function() {
    var context = $('canvas').getContext('2d');
    for (var j = 0; j < photoshop.markedArea.length; j++) {
      var mark = photoshop.markedArea[j];
      var x = (mark.startX < mark.endX) ? mark.startX : mark.endX;
      var y = (mark.startY < mark.endY) ? mark.startY : mark.endY;
      var width = mark.width;
      var height = mark.height;
      var color = mark.color;
      switch(mark.flag) {
        case 'rectangle':
          if (mark.highlightType == 'border') {
            canvas.drawStrokeRect(context, color, x, y, width, height, 2);
          } else {
            var color = changeColorToRgba(color, 0.5);
            canvas.drawFillRect(context, color, x, y, width, height);
          }
          break;
        case 'radiusRectangle':
          canvas.drawRoundedRect(
              context, color, x, y, width, height, 6, mark.highlightType);
          break;
        case 'ellipse':
          x = (mark.startX + mark.endX) / 2;
          y = (mark.startY + mark.endY) / 2;
          var xAxis = Math.abs(mark.endX - mark.startX) / 2;
          var yAxis = Math.abs(mark.endY - mark.startY) / 2;
          canvas.drawEllipse(
              context, color, x, y, xAxis, yAxis, 3, mark.highlightType);
          break;
        case 'redact':
          canvas.drawFillRect(context, color, x, y, width, height);
          break;
        case 'text':
          for (var i = 0; i < mark.context.length; i++) {
            canvas.setText(
                context, mark.context[i], color, mark.fontSize, 'arial',
                mark.fontSize, x, y + mark.fontSize * i, width);
          }
          break;
        case 'blur':
          var imageData = context.getImageData(
              x, y, photoshop.markedArea[j].width,
              photoshop.markedArea[j].height);
          imageData = canvas.boxBlur(
              imageData, photoshop.markedArea[j].width,
              photoshop.markedArea[j].height, 10);
          context.putImageData(
              imageData, x, y, 0, 0, photoshop.markedArea[j].width,
              photoshop.markedArea[j].height);
          break;
        case 'line':
          canvas.drawLine(
              context, color, 'round', 2,
              mark.startX, mark.startY, mark.endX, mark.endY);
          break;
        case 'arrow':
          canvas.drawArrow(
              context, color, 2, 4, 10, 'round',
              mark.startX, mark.startY, mark.endX, mark.endY);
          break;
      }
    }
  },

  save: function() {
    photoshop.draw();
    chrome.storage.local.get('screenshotQuality', formatParam => {
      var formatParam = formatParam || 'png';
      var dataUrl;
      var isJpeg = formatParam == 'jpeg';
      $('canvas').toBlob(function(blob) {
        saveAs(blob, chrome.extension.getBackgroundPage().screenshot.screenshotName+".png");
      }, 'image/' + (isJpeg ? 'jpeg' : 'png'), (isJpeg ? 0.5 : null));
      photoshop.finish();
    });
  },

  drawLineOnMaskCanvas: function(startX, startY, endX, endY, type, layerId) {
    var ctx = $('mask-canvas').getContext('2d');
    ctx.clearRect(0, 0, $('mask-canvas').width, $('mask-canvas').height);
    if (type == 'drawEnd') {
      var offset = 20;
      var width = Math.abs(endX - photoshop.startX) > 0 ?
          Math.abs(endX - photoshop.startX): 0;
      var height = Math.abs(endY - photoshop.startY) > 0 ?
          Math.abs(endY - photoshop.startY): 0;
      var offsetLeft = parseInt($(layerId).style.left);
      var offsetTop = parseInt($(layerId).style.top);
      startX = startX - offsetLeft + offset / 2;
      startY = startY - offsetTop + offset / 2;
      endX = endX - offsetLeft + offset / 2;
      endY = endY - offsetTop + offset / 2;
      $(layerId).style.left = offsetLeft - offset / 2;
      $(layerId).style.top = offsetTop - offset / 2;
      var cavCopy = photoshop.createCanvas(layerId);
      cavCopy.width = width + offset;
      cavCopy.height = height + offset;
      ctx = cavCopy.getContext('2d');
    }
    if (localStorage.lineType == 'line') {
      canvas.drawLine(ctx, localStorage.lineColor, 'round', 2,
        startX, startY, endX, endY);
    } else {
      canvas.drawArrow(ctx, localStorage.lineColor, 2, 4, 10, 'round',
          startX, startY, endX, endY)
    }

  },

  createColorPadStr: function(element, type) {
    var colorList = ['#000000', '#0036ff', '#008000', '#dacb23', '#d56400',
      '#c70000', '#be00b3', '#1e2188', '#0090ff', '#22cc01', '#ffff00',
      '#ff9600', '#ff0000', '#ff008e', '#7072c3', '#49d2ff', '#9dff3d',
      '#ffffff', '#ffbb59', '#ff6b6b', '#ff6bbd'];

    var div = document.createElement("div");
    div.id = "colorpad";
    element.appendChild(div);

    for(var i = 0; i < colorList.length; i++) {
      var a = document.createElement("a");
      var color = colorList[i];
      a.id = color;
      a.title = color;
      a.style.backgroundColor = color;
      if (color == '#ffffff') {
        a.style.border = "1px solid #444";
        a.style.width = "12px"
        a.style.height = "12px";
      }
      a.addEventListener('click', function(e) {
        photoshop.colorPadPick(e.target.id, type);
        return false;
      });
      div.appendChild(a);
    }
  },

  colorPadPick: function(color, type) {
    photoshop.color = color;
    if(type == 'highlight') {
      localStorage.highlightColor = color;
      photoshop.setHighlightColorBoxStyle(color);
    } else if(type == 'text') {
      localStorage.fontColor = color;
      $('fontColorBox').style.backgroundColor = color;
    } else if (type == 'line') {
      localStorage.lineColor = color;
      photoshop.setLineColorBoxStyle();
    } else if (type == 'ellipse') {
      $('ellipseBox').style.borderColor = color;
    }
  },

  setHighlightColorBoxStyle: function(color) {
    var highlightColorBox = $('highlightColorBox');
    highlightColorBox.style.borderColor = color;
    localStorage.highlightType = localStorage.highlightType || 'border';
    if (localStorage.highlightType == 'border') {
      highlightColorBox.style.background = '#ffffff';
      highlightColorBox.style.opacity = 1;
      $('borderMode').className = 'mark';
      $('rectMode').className = '';
    } else if (localStorage.highlightType == 'rect') {
      highlightColorBox.style.background = color;
      highlightColorBox.style.opacity = 0.5;
      $('borderMode').className = '';
      $('rectMode').className = 'mark';
    }
    if (photoshop.flag == 'rectangle') {
      highlightColorBox.style.borderRadius = '0 0';
    } else if (photoshop.flag == 'radiusRectangle') {
      highlightColorBox.style.borderRadius = '3px 3px';
    } else if (photoshop.flag == 'ellipse') {
      highlightColorBox.style.borderRadius = '12px 12px';
    }
    photoshop.markCurrentElement($(photoshop.flag));
  },

  setBlackoutColorBoxStyle: function() {
    localStorage.blackoutType = localStorage.blackoutType || 'redact';
    if (localStorage.blackoutType == 'redact') {
      $('blackoutBox').className = 'rectBox';
      $('redact').className = 'mark';
      $('blur').className = '';
    } else if (localStorage.blackoutType == 'blur') {
      $('blackoutBox').className = 'blurBox';
      $('redact').className = '';
      $('blur').className = 'mark';
    }
  },

  setFontSize: function(size) {
    var id = 'size_' + size;
    localStorage.fontSize = size;
    $('size_10').className = '';
    $('size_16').className = '';
    $('size_18').className = '';
    $('size_32').className = '';
    $(id).className = 'mark';
  },

  setLineColorBoxStyle: function() {
    localStorage.lineType = localStorage.lineType || 'line';
    photoshop.color = localStorage.lineColor =
        localStorage.lineColor || '#FF0000';
    var ctx = $('lineIconCav').getContext('2d');
    ctx.clearRect(0, 0, 14, 14);
    if (localStorage.lineType == 'line') {
      $('straightLine').className = 'mark';
      $('arrow').className = '';
      canvas.drawLine(ctx, photoshop.color, 'round', 2, 1, 13, 13, 1);
    } else if (localStorage.lineType == 'arrow') {
      $('straightLine').className = '';
      $('arrow').className = 'mark';
      canvas.drawArrow(ctx, photoshop.color, 2, 4, 7, 'round',1, 13, 13, 1);
    }

  },

  initTools: function() {
    photoshop.i18nReplace('tHighlight', 'highlight');
    photoshop.i18nReplace('tRedact', 'redact');
    photoshop.i18nReplace('redactText', 'solid_black');
    photoshop.i18nReplace('tText', 'text');
    photoshop.i18nReplace('tSave', 'save');
    photoshop.i18nReplace('tClose', 'close');
    photoshop.i18nReplace('border', 'border');
    photoshop.i18nReplace('rect', 'rect');
    photoshop.i18nReplace('blurText', 'blur');
    photoshop.i18nReplace('lineText', 'line');
    photoshop.i18nReplace('size_10', 'size_small');
    photoshop.i18nReplace('size_16', 'size_normal');
    photoshop.i18nReplace('size_18', 'size_large');
    photoshop.i18nReplace('size_32', 'size_huge');
    var fontSize = localStorage.fontSize = localStorage.fontSize || 16;
    if (fontSize != 10 && fontSize != 16 && fontSize != 18 && fontSize != 32) {
      localStorage.fontSize = 16;
    }
    localStorage.highlightMode = photoshop.flag =
        localStorage.highlightMode || 'rectangle';
    localStorage.highlightColor = localStorage.highlightColor || '#FF0000';
    localStorage.fontColor = localStorage.fontColor || '#FF0000';
    localStorage.highlightType = photoshop.highlightType =
        localStorage.highlightType || 'border';
    localStorage.blackoutType = localStorage.blackoutType || 'redact';
    localStorage.lineType = localStorage.lineType || 'line';
    localStorage.lineColor = localStorage.lineColor || '#FF0000';
    photoshop.setHighlightColorBoxStyle(localStorage.highlightColor);
    $('fontColorBox').style.backgroundColor =
        localStorage.fontColor || '#FF0000';
    $('btnHighlight').addEventListener('click', function() {
      photoshop.toDo(this, localStorage.highlightMode);
      photoshop.setHighlightColorBoxStyle(localStorage.highlightColor);
    }, false);

    $('btnBlackout').addEventListener('click', function() {
      photoshop.toDo(this, localStorage.blackoutType);
      photoshop.setBlackoutColorBoxStyle();
    }, false);

    $('btnText').addEventListener('click', function() {
      photoshop.toDo(this, 'text');
    }, false);

    $('btnLine').addEventListener('click', function() {
      photoshop.toDo(this, localStorage.lineType);
      photoshop.setLineColorBoxStyle();
    }, false);



    photoshop.setHighlightColorBoxStyle(localStorage.highlightColor);
    $('borderMode').addEventListener('click', function() {
      localStorage.highlightType = 'border';
    }, false);
    $('rectMode').addEventListener('click', function() {
      localStorage.highlightType = 'rect';
    }, false);
    $('rectangle').addEventListener('click', function() {
      localStorage.highlightMode = photoshop.flag = 'rectangle';
      photoshop.markCurrentElement(this);
    }, false);
    $('radiusRectangle').addEventListener('click', function() {
      localStorage.highlightMode = photoshop.flag = 'radiusRectangle';
      photoshop.markCurrentElement(this);
    }, false);
    $('ellipse').addEventListener('click', function() {
      localStorage.highlightMode = photoshop.flag = 'ellipse';
      photoshop.markCurrentElement(this);
    }, false);
    photoshop.setBlackoutColorBoxStyle();
    $('redact').addEventListener('click', function() {
      localStorage.blackoutType = 'redact';
    }, false);
    $('blur').addEventListener('click', function() {
      localStorage.blackoutType = 'blur';
    }, false);

    photoshop.setLineColorBoxStyle();

    photoshop.createColorPadStr($('highlightColorPad'), 'highlight');
    photoshop.createColorPadStr($('fontColorPad'), 'text');
    photoshop.createColorPadStr($('lineColorPad'), 'line');

    $('straightLine').addEventListener('click', function() {
      localStorage.lineType = 'line';
      photoshop.setLineColorBoxStyle();
    }, false);
    $('arrow').addEventListener('click', function() {
      localStorage.lineType = 'arrow';
      photoshop.setLineColorBoxStyle();
    }, false);

    photoshop.setFontSize(localStorage.fontSize);
    $('size_10').addEventListener('click', function() {
      photoshop.setFontSize(10);
    }, false);
    $('size_16').addEventListener('click', function() {
      photoshop.setFontSize(16);
    }, false);
    $('size_18').addEventListener('click', function() {
      photoshop.setFontSize(18);
    }, false);
    $('size_32').addEventListener('click', function() {
      photoshop.setFontSize(32);
    }, false);
  },

  drawEllipseOnMaskCanvas: function(endX, endY, type, layerId) {
    var ctx = $('mask-canvas').getContext('2d');
    ctx.clearRect(0, 0, $('mask-canvas').width, $('mask-canvas').height);
    var x = (photoshop.startX + endX) / 2;
    var y = (photoshop.startY + endY) / 2;
    var xAxis = Math.abs(endX - photoshop.startX) / 2;
    var yAxis = Math.abs(endY - photoshop.startY) / 2;
    canvas.drawEllipse(ctx, photoshop.color, x, y, xAxis, yAxis, 3,
        photoshop.highlightType);
    if (type == 'end') {
      var offsetLeft = parseInt($(layerId).style.left);
      var offsetTop = parseInt($(layerId).style.top);
      var startX = photoshop.startX - offsetLeft ;
      var startY = photoshop.startY - offsetTop ;
      var newEndX = photoshop.endX - offsetLeft ;
      var newEndY = photoshop.endY - offsetTop ;
      x = (startX + newEndX) / 2;
      y = (startY + newEndY) / 2;
      xAxis = Math.abs(newEndX - startX) / 2;
      yAxis = Math.abs(newEndY - startY) / 2;
      var cavCopy = photoshop.createCanvas(layerId);
      cavCopy.width = Math.abs(endX - photoshop.startX);
      cavCopy.height = Math.abs(endY - photoshop.startY);
      var ctxCopy = cavCopy.getContext('2d');
      canvas.drawEllipse(ctxCopy, photoshop.color, x, y,
          xAxis, yAxis, 3, photoshop.highlightType);
      ctx.clearRect(0, 0, $('mask-canvas').width, $('mask-canvas').height);
    }
  },

  showTip: function(className, message, delay) {
    delay = delay || 2000;
    var div = document.createElement('div');
    div.className = className;
    div.innerHTML = message;
    document.body.appendChild(div);
    div.style.left = (document.body.clientWidth - div.clientWidth) / 2 + 'px';
    window.setTimeout(function() {
      document.body.removeChild(div);
    }, delay);
  }
};

photoshop.init();
$('photo').addEventListener('mousemove', photoshop.onMouseMove, true);
$('photo').addEventListener('mousedown', photoshop.onMouseDown, true);
$('photo').addEventListener('mouseup', photoshop.onMouseUp, true);
document.addEventListener('mouseup', photoshop.onMouseUp, true);
document.addEventListener('mousemove', photoshop.onMouseMove, true);

$('canvas').addEventListener(
    'selectstart', function f(e) { return false });
$('mask-canvas').addEventListener(
    'selectstart', function f(e) { return false });
$('btnSave').addEventListener('click', photoshop.save);
$('btnClose').addEventListener('click', photoshop.closeCurrentTab);
