/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50, sloppy: true, continue: true */
/*global $, Folder, app, DocumentFill, ActionDescriptor, ActionReference, DialogModes, File,
         TypeUnits, ActionList, SolidColor, executeAction, executeActionGet, PhotoshopSaveOptions, SaveOptions, PNGSaveOptions,
         LayerKind, cssToClip, svg, ColorModel, JSXGlobals, PSKey, PSClass, PSString, PSType, PSEnum, PSEvent */

var LAYERSTYLE = {};
LAYERSTYLE.saveLayerStyle = function () {
    var aslPath = Folder.temp.fsName + "/LayerStyle.asl";
    var pngPath = Folder.temp.fsName + "/LayerStyle.png";
    var aslFile = new File(aslPath);

    app.activeDocument.activeLayer.saveStyleFile(aslFile);

    try {
        app.thumbnailStyleFile(aslFile, new File(pngPath));
    } catch (ex) { }

    var strLayerName = $._ext_PHXS.getLayerName();
    var fileData = {
        'layerName': strLayerName,
        files: [aslPath],
        rendition: pngPath
    };

    return JSON.stringify(fileData);
};
LAYERSTYLE.applyLayerStyle = function (filePath) {
    LAYERSTYLE.clearLayerStyle();
    app.activeDocument.activeLayer.applyStyleFile(new File(filePath));
};
LAYERSTYLE.clearLayerStyle = function () {
    var eventClearStyle         = app.stringIDToTypeID("clearStyle");
    var classLayer            = app.charIDToTypeID('Lyr ');
    var typeOrdinal            = app.charIDToTypeID('Ordn');
    var enumTarget            = app.charIDToTypeID('Trgt');
    var keyTarget                = app.charIDToTypeID('null');

    var desc = new ActionDescriptor();
    var descTarget = new ActionReference();
    descTarget.putEnumerated(classLayer, typeOrdinal, enumTarget);
    desc.putReference(keyTarget, descTarget);
    executeAction(eventClearStyle, desc, DialogModes.NO);
};
