/**************************************************************************
 *                                                                        *
 *  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 AI_MIN_DIMENSION=50,getScaleFactor=function(){var e=1,t=getDocumentDimensions(),n=t.width,r=t.height;return n>=MIN_DIMENSION_WIDTH&&n<=MAX_DIMENSION_WIDTH&&r<MIN_DIMENSION_HEIGHT?e=MIN_DIMENSION_HEIGHT/r:n>=MIN_DIMENSION_WIDTH&&n<=MAX_DIMENSION_WIDTH&&r>MAX_DIMENSION_HEIGHT?e=MAX_DIMENSION_HEIGHT/r:n<MIN_DIMENSION_WIDTH&&r>=MIN_DIMENSION_HEIGHT&&r<=MAX_DIMENSION_HEIGHT?e=MIN_DIMENSION_WIDTH/n:n>MAX_DIMENSION_WIDTH&&r>=MIN_DIMENSION_HEIGHT&&r<=MAX_DIMENSION_HEIGHT?e=MAX_DIMENSION_WIDTH/n:n<MIN_DIMENSION_WIDTH&&r<MIN_DIMENSION_HEIGHT?e=r/MIN_DIMENSION_HEIGHT<n/MIN_DIMENSION_WIDTH?MIN_DIMENSION_HEIGHT/r:MIN_DIMENSION_WIDTH/n:n>MAX_DIMENSION_WIDTH&&r>MAX_DIMENSION_HEIGHT&&(e=r/MAX_DIMENSION_HEIGHT>n/MAX_DIMENSION_WIDTH?MAX_DIMENSION_HEIGHT/r:MAX_DIMENSION_WIDTH/n),e},validateAiDocument=function(){var e=null,t=getDocumentDimensions(),n=t.width,r=t.height;return n<AI_MIN_DIMENSION&&r<AI_MIN_DIMENSION?e=e||createRecoverableErrorResult(localize("Recoverable_error_document_too_small"),localize("Recoverable_error_document_too_small_share_larger")):n<AI_MIN_DIMENSION?e=e||createRecoverableErrorResult(localize("Recoverable_error_document_width_too_small"),localize("Recoverable_error_document_width_too_small_share_wider")):r<AI_MIN_DIMENSION&&(e=e||createRecoverableErrorResult(localize("Recoverable_error_document_height_too_small"),localize("Recoverable_error_document_height_too_small_share_taller"))),e},saveActiveDocument=function(e){var t=validateDocument()||validateAiDocument();if(t)return t;var n=createErrorResult(localize("Error_saving_document"));try{var r=getScaleFactor(),i=new ExportOptionsJPEG;i.antiAliasing=!0,i.qualitySetting=100,i.artBoardClipping=!0,i.verticalScale=r*100,i.horizontalScale=r*100,app.activeDocument.exportFile(new File(e),ExportType.JPEG,i),n=createSuccessResult(app.activeDocument.name)}catch(s){}return n};