<!DOCTYPE HTML SYSTEM "-//Adobe//DWExtension layout-engine 10.0//dialog">
<!-- MENU-LOCATION=NONE -->
<html xmlns:MMString="http://www.macromedia.com/schemes/data/string/">
<head>
<!-- Copyright 2009 Adobe Systems Incorporated.  All rights reserved. -->
<title><MMString:LoadString id="Commands/LaunchWidgetBrowser/Title" /></title>
<script type="text/javascript" src="../Shared/OAWidget/OAWidgetManager.js" ></script>
<script type="text/javascript">

function getWidgetBrowserAppPath()
{
    var path = null;
    var wbXMLPath = OAWidgetManager.getAdobeCommonWidgetsDirectory() + "WidgetBrowser.xml";
    if (DWfile.exists(wbXMLPath))
    {
        var dom = dw.getDocumentDOM(wbXMLPath);
        if (dom)
        {
            var app = dom.getElementsByTagName("application").item(0);
            if (app)
                path = app.getAttribute("installPath");
        }
    }
    return path;
}

function launchWidgetBrowser() {
    var wbPath = getWidgetBrowserAppPath();
    if (wbPath) // we found location of Widget Browser from the WidgetBrowser.xml file that the Widget Browser creates on launch
    {
        // The Widget Browser exists so launch it and then close this
        // dialog. This forces the user to relaunch the dialog when they
        // are done with the Widget Browser, which allows us to pick up
        // any new widgets they have added to Dreamweaver.

        try
        {
            dw.launchApp(wbPath);
        }
        catch (e) { alert("Caught JS exception: " + e); }

    }
    else   // no WidgetBrowser.xml so use the Dw install directory to find the Widget Browser (note this fails if you install to a non default directory)
    {
                wbPath = dw.getRootDirectory();		// get Dreamweaver application directory
				var fileSeparator = "\\";			// default to Windows \ file separator
				if (dwscripts.IS_MAC)				// if mac use : for file separator
					fileSeparator = ":";
				if (wbPath[wbPath.length - 1] == fileSeparator)		// remove trailing \
				    wbPath = wbPath.substr(0,wbPath.length - 2);
				var endPos = wbPath.lastIndexOf(fileSeparator);		// Look for \Adobe Dreamweaver CS5
				wbPath = wbPath.substr(0,endPos + 1);				// chop it off
				if (dwscripts.IS_MAC)	// add appropriate path to Widget Browser depending on platform
					wbPath = wbPath + "Adobe" + fileSeparator + "Adobe Widget Browser.app";
				else
					wbPath = wbPath + "Adobe Widget Browser" + fileSeparator + "Adobe Widget Browser.exe";
	           	
				if (wbPath.length > 0 ) {
					try
					{
							dw.launchApp(wbPath);
							window.close();
					}
					catch (e) { alert("Caught JS exception: " + e); }
				} else
        // The Widget Browser doesn't exist so launch a browser that
        // takes them to the Widget Browser landing page. They will be
        // able to download and install the Widget Browser from this page.
        			dw.browseDocument(dw.loadString("insertbar/oawidget/widgetBrowserLink"));
    }
}

</script>
</head>
<body onLoad="launchWidgetBrowser();">
</body>
</html>
