/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
*  Copyright 2006 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
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/

// this should run only once when the application loads
// we need not check every time
var isBridgeExist = false;
isBridgeExist = JSBridge.isInstalled("bridge");

JSBridge.browseInBridge = function (browsePath)
{    
    if(!isBridgeExist) 
    {        
        return false;
    }
    
    var scriptSavePath = browsePath.replace(/['"\\]/g, "\\$&");
	var script = "app.document.thumbnail = new Thumbnail(decodeURI('" + scriptSavePath + "'));";
	var result;
	var	bt = new BridgeTalk;
    
	// Send the script to bridge and give it 10 sec to launch (if necessary) before assuming an error.
	bt.target = "bridge";
	bt.body = script;
	result = bt.send(10);
	
	if (result)
		BridgeTalk.bringToFront('bridge');
		
	return result;
};

function receiveArguments()
{
	if (!JSBridge.browseInBridge(dw.getLastSavedDirectory()))
		alert(ALERT_BrowseInBridgeFailed);
}

function canAcceptCommand()
{
    if (dw.isPreviewMode())
        return false;
    if (typeof JSBridge != 'undefined' && isBridgeExist)
		return true;
	else
		return false;
}
