/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global $, window, location, CSInterface, SystemPath, themeManager*/

(function () {
    'use strict';

    var csInterface = new CSInterface();
        
    // Reloads extension panel
    function reloadPanel() {
        location.reload();
    }
     function initPersistent() {
    var event = new CSEvent("com.adobe.PhotoshopPersistent", "APPLICATION");
    event.extensionId = 'PixelJuggler';
    csInterface.dispatchEvent(event);
  }
    
    
    function init() {
                
        themeManager.init();
        initPersistent();
        
        $('#mid-gray').click(function() {
    var fileName = 'MidGreyLayer.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });  
      
    
     $('#rotate90').click(function() {
    var fileName = 'Rotate 90 CCW.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });  
      
 
  $('#rotate90cw').click(function() {
    var fileName = 'Rotate 90 CW.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });  
      
 
    
     $('#flip-horizontal').click(function() {
    var fileName = 'Flip Horizontal.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });  
   
    
    $('#flip-vertical').click(function() {
    var fileName = 'Flip Vertical.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });  
      

    
    $('#merge-layers').click(function() {
    var fileName = 'Merge Layers.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });  
      

    
    $('#stamp-layers').click(function() {
    var fileName = 'StampLayer.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });  
      

    
    $('#clipping-mask').click(function() {
    var fileName = 'Clipping Mask.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });  

    
    $('#highlights-mask').click(function() {
    var fileName = 'HighlightsMask.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });  

    
    $('#shadows-mask').click(function() {
    var fileName = 'ShadowsMask.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });  

    
    $('#image-size').click(function() {
    var fileName = 'Image Size.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });  
 
    
    $('#canvas-size').click(function() {
    var fileName = 'Canvas Size.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });  
   
    
    $('#flatten-image').click(function() {
    var fileName = 'Flatten Image.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });

    $('#cmyk').click(function() {
    var fileName = 'cmyk.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });

    $('#lab').click(function() {
    var fileName = 'lab.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });

    $('#rgb').click(function() {
    var fileName = 'rgb.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });
        
        $(".lasso-icon").click(function() {
    var fileName = 'Lasso Tool.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });
        
        $(".pen-icon").click(function() {
    var fileName = 'pen tool.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });
        
        $(".pencil-icon").click(function() {
    var fileName = 'Brush Tool.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });
        
        $(".stamp-icon").click(function() {
    var fileName = 'Clone Stamp Tool.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });
        
        $(".healing-icon").click(function() {
    var fileName = 'Healing Brush Tool.jsxbin';
    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";
    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');
    });




     $('#link').click(function () {
      var csInterface = new CSInterface();
      var rootDir = "/";
      var isWindows = window.navigator.platform.toLowerCase().indexOf("win") > -1;
      if (isWindows) {
        rootDir = csInterface.getSystemPath(SystemPath.COMMON_FILES).substring(0, 3);
      }
 
     var processPath = "/usr/bin/open";
       if (isWindows) {
        processPath = rootDir + "Windows/explorer.exe";
     }

     var url = "http://www.retouchingacademy.com/";
     window.cep.process.createProcess(processPath, url);
    });
    }
         
    init();

}());
    
