/**************************************************************************
 *                                                                        *
 *  Copyright 2014 Adobe Systems Incorporated                             *
 *  All Rights Reserved.                                                  *
 *                                                                        *
 * NOTICE:  All information contained herein is, and remains the property *
 * of Adobe Systems Incorporated and its suppliers, if any.               *
 * The intellectual and technical concepts contained herein are           *
 * proprietary to Adobe Systems Incorporated and its suppliers and may be *
 * covered by U.S. and Foreign Patents, patents in process, and are       *
 * protected by trade secret or copyright law.                            *
 * Dissemination of this information or reproduction of this material     *
 * strictly forbidden unless prior written permission is obtained from    *
 * Adobe Systems Incorporated.                                            *
 *                                                                        *
 **************************************************************************/

/* ShareOnBehance 3.0.0.17 */
var MIN_DIMENSION_WIDTH=640,MIN_DIMENSION_HEIGHT=320,MAX_DIMENSION_WIDTH=1500,MAX_DIMENSION_HEIGHT=1500,MAX_FILE_SIZE=3242880,MAX_PIXELS=MAX_DIMENSION_WIDTH*MAX_DIMENSION_HEIGHT,MAX_ASPECT_RATIO=10,localize=function(e){return e},escapeForJson=function(e){var t=e;return t=t.replace(/\\/g,"\\\\"),t=t.replace(/"/g,'\\"'),t},createSuccessResult=function(e){return'{"status": "success", "value": "'+escapeForJson(e)+'"}'},createErrorResult=function(e){return'{"status": "error", "message": "'+escapeForJson(e)+'"}'},createRecoverableErrorResult=function(e,t){return'{"status": "recoverableError", "message": "'+escapeForJson(e)+'", "subMessage": "'+escapeForJson(t)+'"}'},createCancelResult=function(){return'{"status": "cancel"}'},getDocumentDimensions=function(){return{width:parseInt(app.activeDocument.width,10),height:parseInt(app.activeDocument.height,10)}},getDocumentTooWideError=function(){return createRecoverableErrorResult(localize("Recoverable_error_document_too_narrow"),localize("Recoverable_error_document_too_narrow_share_taller"))},getDocumentTooTallError=function(){return createRecoverableErrorResult(localize("Recoverable_error_document_too_narrow"),localize("Recoverable_error_document_too_narrow_share_wider"))},validateDocument=function(){var e=null;if(app.documents.length===0)e=createRecoverableErrorResult(localize("Recoverable_error_no_documents_open"),localize("Recoverable_error_no_documents_open_therefore_open_one"));else{var t=getDocumentDimensions(),n=t.width,r=t.height;r*MAX_ASPECT_RATIO<n?e=getDocumentTooWideError():n*MAX_ASPECT_RATIO<r&&(e=getDocumentTooTallError())}return e};var hasUserCanceledOperation=function(e){return e.number===8007},ResizeImage=function(e,t){e>=MIN_DIMENSION_WIDTH&&e<=MAX_DIMENSION_WIDTH&&t>=MIN_DIMENSION_HEIGHT&&t<=MAX_DIMENSION_HEIGHT||(e>=MIN_DIMENSION_WIDTH&&e<=MAX_DIMENSION_WIDTH&&t<MIN_DIMENSION_HEIGHT?app.activeDocument.resizeImage(null,MIN_DIMENSION_HEIGHT):e>=MIN_DIMENSION_WIDTH&&e<=MAX_DIMENSION_WIDTH&&t>MAX_DIMENSION_HEIGHT?app.activeDocument.resizeImage(null,MAX_DIMENSION_HEIGHT):e<MIN_DIMENSION_WIDTH&&t>=MIN_DIMENSION_HEIGHT&&t<=MAX_DIMENSION_HEIGHT?app.activeDocument.resizeImage(MIN_DIMENSION_WIDTH):e>MAX_DIMENSION_WIDTH&&t>=MIN_DIMENSION_HEIGHT&&t<=MAX_DIMENSION_HEIGHT?app.activeDocument.resizeImage(MAX_DIMENSION_WIDTH):e<MIN_DIMENSION_WIDTH&&t<MIN_DIMENSION_HEIGHT?app.activeDocument.resizeImage(t/MIN_DIMENSION_HEIGHT<e/MIN_DIMENSION_WIDTH?null:MIN_DIMENSION_WIDTH,t/MIN_DIMENSION_HEIGHT<e/MIN_DIMENSION_WIDTH?MIN_DIMENSION_HEIGHT:null):e>MAX_DIMENSION_WIDTH&&t>MAX_DIMENSION_HEIGHT&&app.activeDocument.resizeImage(t/MAX_DIMENSION_HEIGHT>e/MAX_DIMENSION_WIDTH?null:MAX_DIMENSION_WIDTH,t/MAX_DIMENSION_HEIGHT>e/MAX_DIMENSION_WIDTH?MAX_DIMENSION_HEIGHT:null))},doSaveActiveDocument=function(e){try{app.activeDocument.quickMaskMode=!1,app.activeDocument.flatten()}catch(t){if(hasUserCanceledOperation(t))return createCancelResult()}app.activeDocument.mode===DocumentMode.BITMAP&&app.activeDocument.changeMode(ChangeMode.GRAYSCALE),app.activeDocument.changeMode(ChangeMode.RGB),app.activeDocument.bitsPerChannel=BitsPerChannelType.EIGHT;var n=getDocumentDimensions(),r=n.width,i=n.height;ResizeImage(r,i);var s=new JPEGSaveOptions;return s.quality=12,app.activeDocument.saveAs(new File(e),s,!0),null},saveActiveDocument=function(e){var t=app.preferences.rulerUnits,n=app.displayDialogs;app.preferences.rulerUnits=Units.PIXELS,app.displayDialogs=DialogModes.NO;var r=null,i=createErrorResult(localize("Error_saving_document"));try{var s=validateDocument();if(s)i=s;else{var o=app.activeDocument.name;r=app.activeDocument.duplicate(),s=doSaveActiveDocument(e),i=s||createSuccessResult(o)}}catch(u){hasUserCanceledOperation(u)&&(i=createCancelResult())}finally{return r&&r.close(SaveOptions.DONOTSAVECHANGES),app.preferences.rulerUnits=t,app.displayDialogs=n,i}};