/*
@@@BUILDINFO@@@ browseScheme.jsx 466 16-March-2007
*/

/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
*  Copyright 2005 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.
**************************************************************************/

if( ( stockphoto.timeKeeperOn != undefined )&&( stockphoto.timeKeeperOn ) )
{
	stockphoto.timeKeeper.browseScheme        = {};
	stockphoto.timeKeeper.browseScheme.StTime = new Date();
}

stockphoto.browseScheme = {};
stockphoto.browseScheme.sessionUrl = undefined;

// TODO: Version string should be defined only at one place
// Right now it is present in both browseScheme.jsx and st00Core.jsx
stockphoto.core.BM_VersionMajor       = 1;
stockphoto.core.BM_VersionMinor       = 5;
stockphoto.core.BM_VersionVertertiary = 0;
stockphoto.browseScheme.refreshVerInfo=function()
{
	try
	{
		var dir;
		
		if (stockphoto.isMac)
		{
		  dir = stockphoto.startUpFolderForMac + "/Resources/Scripts";
		}
		else
		{
		  dir = Folder.startup + "/../Adobe Stock Photos CS3";
		}
		  
	} catch(e) { ; }
}
stockphoto.browseScheme.refreshVerInfo();

stockphoto.core.BM_3Version = stockphoto.core.BM_VersionMajor+"."+stockphoto.core.BM_VersionMinor+"."+stockphoto.core.BM_VersionVertertiary;
	
// Browse scheme
stockphoto.core.browseScheme = function (event)
{
    var thumbnail = event.object;
    var func = event.functionName;
    var args = event.arguments;
    var result = { handled: false, returnValue: undefined };
    switch (func)
    {
    	case "GetParent":
    		$.level=2;
    		switch (thumbnail.path)
    		{
				case "stockphoto://comps":
				case "stockphoto://searches/recent":
				case "stockphoto://purchases":
					result.handled = true;
					result.returnValue = stockphoto.places.home;
    		}
    		break;
    	case "Make":
    		$.level=2;
    		switch (thumbnail.path)
    		{
				case "stockphoto://home":
				case "stockphoto://scFooter":
		    		with (thumbnail)
		    		{
						name = stockphoto.core.consts.localizedMenuString[0];
						displayMode = "web";
						displayPath = stockphoto.core.html.loadUrl();
						iconPath = stockphoto.core.makeIconPath("AdobeStockPhotos");
					}
					result.handled = true;
					break;

				case "stockphoto://shoppingcart":
					with (thumbnail)
					{
						displayMode = "web";
						displayPath = stockphoto.core.folder.getMyShoppingCartFolder() + "/" + stockphoto.core.consts.ShoppingCartName;
					}
					result.handled = true;
					break;

				case "stockphoto://searches/recent":
					with (thumbnail)
					{
						displayMode = "filesystem";
						displayPath = stockphoto.core.folder.getMySearchesFolder();
					}
					result.handled = true;
					break;
			}
			break;

        case "GetURL":
        	$.level=2;
            var specifier = thumbnail.path.substr( thumbnail.path.indexOf("://") + 3 );
            var path = undefined;
			switch( specifier )
            {
                case "home":
					// register URL Filter and remember what's the BM's Home Page URL
					if( ( thumbnail != undefined )&&
						( thumbnail.displayPath != undefined ) )
					{
						// Now construct a true Homepage URL by adding country/language/billing
						var lcb=stockphoto.core.html.GetLanguageCountryBilling();
						stockphoto.core.html.urlForBMHPatBrowseSche 
//							= stockphoto.core.html.urlForBMHome+"?language="+lcb.szLanguage+"&country="+lcb.szCountry+"&billing="+lcb.szBilling;
							= stockphoto.core.html.urlForBMHome+"?language="+lcb.szLanguage+"&country="+lcb.szCountry+"&billing="+lcb.szBilling+"&version="+stockphoto.core.BM_3Version;
						thumbnail.displayPath = stockphoto.core.html.urlForBMHPatBrowseSche;
						if( ( this != undefined )&&
							( this.app != undefined )&&
							( this.app.document != undefined ) )
						{
							this.app.document.visitUrl = stockphoto.core.html.doBMUrlFilter;
						}
						stockphoto.core.log.logString(0, "browseScheme/ HomeURL="+thumbnail.displayPath );
					}
                    break;
		
                case "comps":
                    path = stockphoto.core.folder.getMyCompFolder();
                    break;

                case "purchases":
                    path = stockphoto.core.folder.getMyPurchasesFolder();
                    break;

                case "searches/recent":
                    path = stockphoto.core.folder.getMySearchesFolder();
                    break;
            }
            if (path != undefined)
            {
                var folder = Folder(path);
                result.returnValue = unescape(folder.fsName);
                result.handled = true;
            }
            break;

        case "Reveal":
            $.level=2;
            stockphoto.core.log.logString(0,"browse to Reveal1");
            var path = convertStockUrlToLocalFileSpec( thumbnail.path );
            app.document.thumbnail = path;
            stockphoto.core.log.logString(0,"browse to Reveal2");
            result.returnValue = true;
            result.handled = true;
            break;

 		case "CanSetName":
 			$.level=2;
			switch (thumbnail.path)
			{
				case "stockphoto://scFooter":
					result.returnValue = true;
					break;
				default:
					result.returnValue = ( thumbnail.name.length == 0 );
			}
			result.handled = true;			
			break;

		case "GetFileSpec":
            $.level=2;
            result.returnValue = thumbnail.displayPath;
            result.handled = true;
            break;

		case "CanCreateNewFolder":
		case "CanGetFileSpec":
			$.level=2;
            result.returnValue = true;
            result.handled = true;
            break;

		// When the checkout ScriptNode is requested, make sure the Bridge knows whether to display the local shopping cart,
		// or the URL returned from the e-commerce engine.
		case "GetDisplayPath":
    		$.level=2;
    		switch (thumbnail.path)
    		{
    			case "stockphoto://checkout":
					with (thumbnail)
					{
						if (stockphoto.browseScheme.sessionUrl != undefined)		// If we've registered the online shopping cart url, return it
						{
							result.returnValue = stockphoto.browseScheme.sessionUrl;
						}
						else														// If no remote shopping cart is registered return url to local cart
						{
							result.returnValue = stockphoto.core.folder.getMyShoppingCartFolder() + "/" + stockphoto.core.consts.ShoppingCartName;
						}
					}
					result.handled = true;
    				break;
    		}
			break;
    }
    return result;
}

app.registerBrowseScheme( "stockphoto", stockphoto.core.browseScheme );

if( ( stockphoto.timeKeeperOn != undefined )&&( stockphoto.timeKeeperOn ) )
{
	stockphoto.timeKeeper.browseScheme.EdTime = new Date();
}
