/**************************************************************************
 *                                                                        *
 *  Copyright 2013 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 2.0.0.16 */
function CSXSWindowType(){}function Version(e,t,n,r){this.major=e,this.minor=t,this.micro=n,this.special=r}function VersionBound(e,t){this.version=e,this.inclusive=t}function VersionRange(e,t){this.lowerBound=e,this.upperBound=t}function Runtime(e,t){this.name=e,this.versionRange=t}function Extension(e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v){this.id=e,this.name=t,this.mainPath=n,this.basePath=r,this.windowType=i,this.width=s,this.height=o,this.minWidth=u,this.minHeight=a,this.maxWidth=f,this.maxHeight=l,this.defaultExtensionDataXml=c,this.specialExtensionDataXml=h,this.requiredRuntimeList=p,this.isAutoVisible=d,this.isPluginExtension=v}function CSEvent(e,t,n,r){this.type=e,this.scope=t,this.appId=n,this.extensionId=r}function SystemPath(){}function ColorType(){}function RGBColor(e,t,n,r){this.red=e,this.green=t,this.blue=n,this.alpha=r}function Direction(e,t){this.x=e,this.y=t}function GradientStop(e,t){this.offset=e,this.rgbColor=t}function GradientColor(e,t,n,r){this.type=e,this.direction=t,this.numStops=n,this.arrGradientStop=r}function UIColor(e,t,n){this.type=e,this.antialiasLevel=t,this.color=n}function AppSkinInfo(e,t,n,r,i,s,o){this.baseFontFamily=e,this.baseFontSize=t,this.appBarBackgroundColor=n,this.panelBackgroundColor=r,this.appBarBackgroundColorSRGB=i,this.panelBackgroundColorSRGB=s,this.systemHighlightColor=o}function HostEnvironment(e,t,n,r,i,s,o){this.appName=e,this.appVersion=t,this.appLocale=n,this.appUILocale=r,this.appId=i,this.isAppOnline=s,this.appSkinInfo=o}function HostCapabilities(e,t,n,r,i){this.EXTENDED_PANEL_MENU=e,this.EXTENDED_PANEL_ICONS=t,this.DELEGATE_APE_ENGINE=n,this.SUPPORT_HTML_EXTENSIONS=r,this.DISABLE_FLASH_EXTENSIONS=i}function ApiVersion(e,t,n){this.major=e,this.minor=t,this.micro=n}function CSInterface(){}function AAMStatus(e,t,n){this.status=e,this.callerId=t,this.payload=n}function IMSInterface(){}define("lib/CEPGlobals",[],function(){return window.cep}),define("window",[],function(){return window}),define("config",["window"],function(e){var t="c2hhcmUtb24tYmVoYW5jZQ==",n="NmExODlhOGItY2JjOC00ODgyLWFhZGUtMDBkNzUxODYyYTFk",r="aHR0cHM6Ly9vb2JlLmFkb2JlLmNvbS8=";return{aameeServiceName:"ShareOnBehance",behanceDomain:"https://www.behance.net",behanceIFrameUrl:"https://www.behance.net/connect/adobe/to",behanceHelpUrl:"https://www.behance.net/faq",behancePingUrl:"https://www.behance.net/xd.php",imsCi:e.atob(t),imsCs:e.atob(n),imsRu:e.atob(r),logging:!0,timeout:3e4,version:"2.0.0",whiteListedDomains:["adobe.com","behance.net","prosite.com"],fetchAccessTokenTimeout:6e4}}),define("log",["config"],function(e){var t=(new Date).getTime();return{error:function(n){e.logging&&console.log("ERROR ("+((new Date).getTime()-t)+"): "+n)},info:function(n){e.logging&&console.log("INFO ("+((new Date).getTime()-t)+"): "+n)},stringify:function(t){if(!e.logging)return"";try{return JSON.stringify(t)}catch(n){return t+""}}}}),CSXSWindowType._PANEL="Panel",CSXSWindowType._MODELESS="Modeless",CSXSWindowType._MODAL_DIALOG="ModalDialog",EvalScript_ErrMessage="EvalScript error.",Version.MAX_NUM=999999999,CSEvent.prototype.data="",SystemPath.USER_DATA="userData",SystemPath.COMMON_FILES="commonFiles",SystemPath.MY_DOCUMENTS="myDocuments",SystemPath.APPLICATION="application",SystemPath.EXTENSION="extension",SystemPath.HOST_APPLICATION="hostApplication",ColorType.RGB="rgb",ColorType.GRADIENT="gradient",ColorType.NONE="none",CSInterface.THEME_COLOR_CHANGED_EVENT="com.adobe.csxs.events.ThemeColorChanged",CSInterface.prototype.hostEnvironment=JSON.parse(window.__adobe_cep__.getHostEnvironment()),CSInterface.prototype.getHostEnvironment=function(){return this.hostEnvironment=JSON.parse(window.__adobe_cep__.getHostEnvironment()),this.hostEnvironment},CSInterface.prototype.closeExtension=function(){window.__adobe_cep__.closeExtension()},CSInterface.prototype.getSystemPath=function(e){var t=decodeURI(window.__adobe_cep__.getSystemPath(e)),n=this.getOSInformation();return n.indexOf("Windows")>=0?t=t.replace("file:///",""):n.indexOf("Mac")>=0&&(t=t.replace("file://","")),t},CSInterface.prototype.evalScript=function(e,t){if(t==null||t==undefined)t=function(e){};window.__adobe_cep__.evalScript(e,t)},CSInterface.prototype.getApplicationID=function(){var e=this.hostEnvironment.appId;return e},CSInterface.prototype.getHostCapabilities=function(){var e=JSON.parse(window.__adobe_cep__.getHostCapabilities());return e},CSInterface.prototype.dispatchEvent=function(e){typeof e.data=="object"&&(e.data=JSON.stringify(e.data)),window.__adobe_cep__.dispatchEvent(e)},CSInterface.prototype.addEventListener=function(e,t,n){window.__adobe_cep__.addEventListener(e,t,n)},CSInterface.prototype.removeEventListener=function(e,t,n){window.__adobe_cep__.removeEventListener(e,t,n)},CSInterface.prototype.requestOpenExtension=function(e,t){window.__adobe_cep__.requestOpenExtension(e,t)},CSInterface.prototype.getExtensions=function(e){var t=JSON.stringify(e),n=window.__adobe_cep__.getExtensions(t),r=JSON.parse(n);return r},CSInterface.prototype.getNetworkPreferences=function(){var e=window.__adobe_cep__.getNetworkPreferences(),t=JSON.parse(e);return t},CSInterface.prototype.initResourceBundle=function(){var e=JSON.parse(window.__adobe_cep__.initResourceBundle()),t=document.querySelectorAll("[data-locale]");for(var n=0;n<t.length;n++){var r=t[n],i=r.getAttribute("data-locale");if(i)for(var s in e)if(s.indexOf(i)==0){var o=e[s];if(s.indexOf(".")==-1)r.innerHTML=o;else{var u=s.substring(s.indexOf(".")+1);r[u]=o}}}return e},CSInterface.prototype.dumpInstallationInfo=function(){return window.__adobe_cep__.dumpInstallationInfo()},CSInterface.prototype.getOSInformation=function(){var e=navigator.userAgent;if(navigator.platform=="Win32"||navigator.platform=="Windows"){var t="Windows platform";e.indexOf("Windows NT 5.0")>-1?t="Windows 2000":e.indexOf("Windows NT 5.1")>-1?t="Windows XP":e.indexOf("Windows NT 5.2")>-1?t="Windows Server 2003":e.indexOf("Windows NT 6.0")>-1?t="Windows Vista":e.indexOf("Windows NT 6.1")>-1?t="Windows 7":e.indexOf("Windows NT 6.2")>-1&&(t="Windows 8");var n="32-bit";return e.indexOf("WOW64")>-1&&(n="64-bit"),t+" "+n}if(navigator.platform=="MacIntel"||navigator.platform=="Macintosh"){var r=new String;r=e;var i=r.indexOf(")")-r.indexOf("Mac OS X"),s=r.substr(r.indexOf("Mac OS X"),i),o=s.replace("_",".");return o=o.replace("_","."),o}return"Unknown Operation System"},CSInterface.prototype.openURLInDefaultBrowser=function(e){return cep.util.openURLInDefaultBrowser(e)},CSInterface.prototype.getExtensionID=function(){return window.__adobe_cep__.getExtensionId()},CSInterface.prototype.getScaleFactor=function(){return window.__adobe_cep__.getScaleFactor()},CSInterface.prototype.setScaleFactorChangedHandler=function(e){window.__adobe_cep__.setScaleFactorChangedHandler(e)},CSInterface.prototype.getCurrentApiVersion=function(){var e=JSON.parse(window.__adobe_cep__.getCurrentApiVersion());return e},define("lib/CSInterface-5.0.0",function(){}),define("lib/CSInterface",["lib/CSInterface-5.0.0"],function(e){var t=new CSInterface;return t.resourceBundle=t.initResourceBundle(),t.SystemPath=SystemPath,t.EvalScript_ErrMessage=EvalScript_ErrMessage,t}),define("localize",["lib/CSInterface","log"],function(e,t){return function(t){if(e.resourceBundle[t]){var n=e.resourceBundle[t],r=1;while(n.indexOf("$"+r)!==-1)n=n.replace("$"+r,arguments[r]),r++;return n}return""}}),define("utils",["lib/CEPGlobals","lib/CSInterface","config","localize","log","window"],function(e,t,n,r,i,s){var o="Photoshop";t.hostEnvironment.appName==="ILST"?o="Illustrator":t.hostEnvironment.appName==="IDSN"&&(o="InDesign"),i.info("Application name is: "+o);var u=s.navigator.platform.toLowerCase().indexOf("win")>-1;i.info("Platform is: "+(u?"Windows":"Mac"));var a=t.getSystemPath(t.SystemPath.EXTENSION);i.info("Extension directory is: "+a);var f="/";u&&(f=t.getSystemPath(t.SystemPath.COMMON_FILES).substring(0,3)),i.info("Root directory is: "+f);var l="com.adobe.behance.shareonbehance.html.extension",c="/tmp/"+l;u&&(c=t.getSystemPath(t.SystemPath.USER_DATA)+"/../Local/Temp/"+l),e.fs.makedir(c),e.fs.chmod(c,511);var h=function(e){i.info("Pinging "+n.behancePingUrl+" to check internet connection");var t=new s.XMLHttpRequest;t.open("GET",n.behancePingUrl,!0),t.onerror=function(){e.recoverableError(r("Recoverable_error_connecting_to_Behance"),r("Recoverable_error_connecting_to_Behance_check_internet"))},t.send()},p=function(e){i.info("Getting network preferences");var n=t.getNetworkPreferences();i.info("Found network preferences: "+i.stringify(n));if(n&&n.isAppOnline===!1){e.recoverableError(r("Recoverable_error_network_permissions"),r("Recoverable_error_network_permissions_fix_permissions"));return}h(e)},d=function(e){var t=s.document.createElement("a");t.href=e;var n=t.hostname.split(".");return n=n.slice(n.length-2,n.length),{protocol:t.protocol,domain:n.join(".")}},v=function(t){if(!t){i.error("URL is null");return}var r=d(t);if(r.protocol!=="http:"&&r.protocol!=="https:"){i.error("Invalid protocol: "+r.protocol);return}var s=!1;for(var o=0;o<n.whiteListedDomains.length;o++){var a=n.whiteListedDomains[o];if(a===r.domain){s=!0;break}}if(!s){i.error("Invalid domain: "+r.domain);return}var l="/usr/bin/open";u&&(l=f+"Windows/explorer.exe"),i.info("Opening browser to url: "+t),e.process.createProcess(l,t)};return{applicationName:o,checkInternetConnection:p,extensionDir:a,isWindows:u,openInDefaultBrowser:v,rootDir:f,tempDir:c}}),define("aamee",["lib/CEPGlobals","config","log","utils","window"],function(e,t,n,r,i){return{isExtensionEnabled:function(){n.info("Checking to see if AAMEE has the extension enabled or disabled");var s="/Library/Application Support/Adobe/CDI/override.xml";r.isWindows&&(s=r.rootDir+"ProgramData/Adobe/CDI/override.xml");var o=e.fs.readFile(s);if(!o||!o.data||o.data.length===0||o.err!==0)return n.info("Unable to read override.xml, assuming extension should be enabled"),!0;var u=null;try{var a=new i.DOMParser;u=a.parseFromString(o.data,"text/xml")}catch(f){return n.error("Error parsing override file, assuming extension is enabled"),!0}var l=u.documentElement.getAttribute("suppress");if(l==="true")return n.info("Global suppression is turned on, disable"),!1;var c=u.getElementsByTagName("Service");for(var h=0;h<c.length;h++){var p=c[h];if(p.getAttribute("name")===t.aameeServiceName&&p.getAttribute("suppress")==="true")return n.info("Found service specific suppression, disable"),!1}return n.info("Unable to find an entry that suppresses this extension, assuming enabled"),!0}}}),IMSInterface.prototype.addEventListener=function(e,t){window.__adobe_cep__.addEventListener(e,t)},IMSInterface.prototype.removeEventListener=function(e,t){window.__adobe_cep__.removeEventListener(e,t)},IMSInterface.prototype.imsConnect=function(){var e=window.__adobe_cep__.imsConnect();return e},IMSInterface.prototype.imsDisconnect=function(e){window.__adobe_cep__.imsDisconnect(e)},IMSInterface.prototype.imsFetchAccounts=function(e,t){var n=window.__adobe_cep__.imsFetchAccounts(e,t);return n},IMSInterface.prototype.imsFetchAccessToken=function(e,t,n,r,i,s){return window.__adobe_cep__.imsFetchAccessToken(e,t,n,r,i,s)},IMSInterface.prototype.imsRevokeDeviceToken=function(e,t,n,r,i){return window.__adobe_cep__.imsFetchAccessToken(e,t,n,r,i,"REVOKE")},IMSInterface.prototype.imsSetProxyCredentials=function(e,t){window.__adobe_cep__.imsSetProxyCredentials(e,t)},IMSInterface.prototype.showAAM=function(e,t,n,r,i,s){return window.__adobe_cep__.showAAM(e,t,n,r,i,s)},IMSInterface.prototype.imsGetCurrentUserId=function(){var e=window.__adobe_cep__.getCurrentImsUserId();return e},define("lib/IMSInterface-5.0.0",function(){}),define("lib/IMSInterface",["lib/IMSInterface-5.0.0"],function(e){return new IMSInterface}),define("host",["lib/CSInterface","localize","log"],function(e,t,n){var r=t("Error_generic_scripting");return{evalScript:function(i,s){n.info("Evaling script: "+i),e.evalScript(i,function(i){n.info("Received result from eval script: "+i);if(!i||i.length===0||i===e.EvalScript_ErrMessage){s.error(r);return}var o=JSON.parse(i);switch(o.status){case"success":s.success(o.value);break;case"error":s.error(t(o.message));break;case"recoverableError":s.recoverableError(t(o.message),t(o.subMessage));break;case"cancel":e.closeExtension();break;default:s.error(r)}})}}}),define("ui",["lib/CSInterface","lib/spin","config","localize","log","utils","window"],function(e,t,n,r,i,s,o){var u=!1,a=!1,f=!1,l=o.document.getElementsByTagName("body")[0],c=o.document.getElementsByClassName("close-button")[0],h=o.document.getElementsByClassName("error")[0],p=o.document.getElementsByClassName("error-message")[0],d=o.document.getElementsByClassName("error-sub-message")[0],v=o.document.getElementsByClassName("help")[0],m=o.document.getElementsByClassName("behance-iframe")[0],g=o.document.getElementsByClassName("loading")[0],y=o.document.getElementsByClassName("loading-message")[0],b=function(){return m.contentWindow},w=function(t){i.info("Initializing iframe");var r=e.hostEnvironment,s=n.behanceIFrameUrl;s+="?destination=wipframe",s+="&extVersion="+n.version,s+="&appId="+r.appName,s+="&appVersion="+r.appVersion,s+="&appLocale="+r.appUILocale,s+="&accessToken="+t,i.info("Pointing iframe to "+s),m.src=s,u=!0},E=function(){h.style.display="none",m.style.display="none",g.style.display="none"},S=function(){i.info("Attempting to display iframe"),a?i.info("Already displaying error"):(f=!0,E(),m.style.display="block",i.info("Successfully displayed iframe"))},x=function(e,t){i.error("Attempting to display recoverable error: "+e),a?i.info("Already displaying error"):(a=!0,E(),p.innerHTML=e,t&&(d.innerHTML=t),v.innerHTML=r("UI_recoverable_error_footer"),A(),h.style.display="block",i.info("Successfully displayed recoverable error"))},T=function(e){i.info("About to display error"),setTimeout(function(){i.error("Attempting to display error: "+e),a?i.info("Already displaying error"):(a=!0,E(),v.innerHTML=r("UI_error_footer",e),A(),h.style.display="block",i.info("Successfully displayed error"))},100)},N=function(t){t.keyCode===27?(i.info("Caught esc key, attempting to close extension"),e.closeExtension()):t.keyCode===13&&a&&(i.info("Caught enter key while displaying error, attempting to close extension"),e.closeExtension())},C=function(){i.info("Help link clicked, opening browser to help url"),s.openInDefaultBrowser(n.behanceHelpUrl)},k=function(){i.info("Close button clicked, closing extension"),e.closeExtension()},L=function(){var e={lines:30,length:0,width:2,radius:9,corners:0,color:"#1769ff",speed:2,trail:100,hwaccel:!0,className:"spinner",zIndex:2e9,top:"19px",left:"20px"};return(new t(e)).spin(y)},A=function(){var e=o.document.getElementsByClassName("help-link")[0];e.addEventListener("click",C)},O=function(){p.innerHTML=r("UI_error_title_message"),d.innerHTML=r("UI_error_subtitle_message");var t=e.hostEnvironment;t.appUILocale!="en_US"?y.innerHTML=r("UI_loading")+"<br>"+r("UI_entering_english_only_site"):y.innerHTML=r("UI_loading"),c.innerHTML=r("UI_close");var n=r("Error_unknown");v.innerHTML=r("UI_error_footer",n)},M=function(){i.info("Initializing UI"),O(),L(),o.document.addEventListener("keydown",N),A(),c.addEventListener("click",k),i.info("Done initializing UI")};return M(),{getIFrameWindow:b,hasInitializedIFrame:function(){return u},hasShownIFrame:function(){return f},initIFrame:w,showIFrame:S,showRecoverableError:x,showError:T}}),define("response",["log","ui"],function(e,t){return{create:function(n){return n||(n={}),n.success||(n.success=function(){e.info("Generic success callback triggered")}),n.recoverableError||(n.recoverableError=function(e,n){t.showRecoverableError(e,n)}),n.error||(n.error=function(e){t.showError(e)}),n}}}),define("ims",["lib/IMSInterface","config","host","localize","log","response","utils"],function(e,t,n,r,i,s,o){var u="com.adobe.csxs.events.internal.ims.FetchAccessToken",a="openid,AdobeID,creative_cloud,sao.behance",f=t.imsCi,l=t.imsCs,c=t.imsRu,h=!1;return{getAccessToken:function(c){i.info("Connecting to IMS");var p=e.imsConnect(f);i.info("Connected to IMS, with ims reference: "+p);var d=function(){try{e.removeEventListener(u,v),e.imsDisconnect(p),i.info("Successfully cleaned up IMS")}catch(t){i.error("Error cleaning up IMS: "+i.stringify(t))}},v=function(e){i.info("Handling fetch access token callback: "+i.stringify(e)),h=!0,e&&e.data&&e.data.access_token?(d(),c.success(e.data.access_token)):(d(),c.error(r("Error_fetching_access_token")))};e.addEventListener(u,v),i.info("Getting current user id"),n.evalScript("getUserId()",s.create({success:function(n){i.info("Received callback from evalScript: "+n),n===null||n.length===0?(d(),c.recoverableError(r("Recoverable_error_not_signed_in"),r("Recoverable_error_not_signed_in_therefore_sign_in",o.applicationName))):(i.info("Found a user, fetch access token"),e.imsFetchAccessToken(p,f,l,n,"",a),setTimeout(function(){h||c.error(r("Error_fetching_access_token"))},t.fetchAccessTokenTimeout))}}))}}}),define("message",["lib/CSInterface","config","log","ui","utils","window"],function(e,t,n,r,i,s){var o=!1,u=[],a=function(e){n.info("Attempting to send message of type: "+e.type);if(o){n.info("Behance iframe is ready, sending message");var i=r.getIFrameWindow();i.postMessage(JSON.stringify(e),t.behanceDomain)}else n.info("Behance iframe is not ready, queueing message"),u.push(e)},f=function(){n.info("Flushing queued messages");for(var e=0;e<u.length;e++)a(u[e]);u=[]};return s.onmessage=function(s){if(t.behanceDomain!==s.origin){n.info("Unable to respond to message from domain: "+s.origin);return}if(s.source!==r.getIFrameWindow()){n.info("Unable to respond to message from different iframe window");return}var u=JSON.parse(s.data);if(u){n.info("Received message: "+n.stringify(u)+", from origin: "+s.origin);switch(u.type){case"close":e.closeExtension();break;case"openBrowser":i.openInDefaultBrowser(u.url);break;case"ready":r.showIFrame();break;case"readyAcceptImage":o=!0,f()}}},{sendWip:function(e){a({type:"wip",image:e})}}}),define("wip",["lib/CEPGlobals","host","localize","log","response","utils"],function(e,t,n,r,i,s){var o={},u=function(e){var t=e.split(".");return t.length>1&&t[t.length-1].length>0&&t.pop(),t.join(".")},a=function(t){var n=null;try{r.info("Reading file: "+t),n=e.fs.readFile(t,e.encoding.Base64).data.replace(/\s/g,""),r.info("Successfully read file")}catch(i){r.error("Error reading file")}return n},f=function(t){try{r.info("Deleting file: "+t);var n=e.fs.deleteFile(t);!n||n.err!==0?r.error("Error deleting file"):r.info("Successfully deleted file")}catch(i){r.error("Error deleting file: "+r.stringify(i))}};return o.isLoaded=function(){return o.value&&o.value.length>0},o.load=function(e){r.info("Loading wip module");var l=s.tempDir+"/wip.jpg";r.info("Saving temporary image to "+l),t.evalScript("saveActiveDocument('"+l+"')",i.create({success:function(t){r.info("Received callback from evalScript: "+t);if(t===null){e.error(n("Error_saving_document"));return}r.info("Successfully saved active document"),o.mime="image/jpeg",o.encoding="base64",o.title=u(t),o.value=a(l),f(l),o.value&&o.value.length>0?(r.info("Successfully read WIP, sending to iframe"),e.success()):e.error(n("Error_reading_document"))}}))},o}),require(["aamee","config","ims","localize","log","message","response","ui","utils","wip"],function(e,t,n,r,i,s,o,u,a,f){var l=function(){i.info("Starting timeout countdown"),setTimeout(function(){i.info("Checking to see if iframe has been shown: "+u.hasShownIFrame()),u.hasShownIFrame()||u.showError(r("Error_connection_timeout"))},t.timeout)},c=function(){f.load(o.create({success:function(){s.sendWip(f),u.hasInitializedIFrame()&&l()}}))},h=function(){i.info("Starting Behance extension"),document.title=r("UI_share_on_Behance");if(!e.isExtensionEnabled()){u.showError(r("Error_extension_disabled"));return}a.checkInternetConnection(o.create()),n.getAccessToken(o.create({success:function(e){u.initIFrame(e),f.isLoaded()&&l()}})),setTimeout(c,100)};h()}),define("main",function(){});