var ExploreUtils = new Object();

ExploreUtils.glueOnImageError = function(img, cat, objKey)
{
    // Must set category or objectKey
    if (!cat && !objKey)
    {
        img.src = "http://s3.amazonaws.com/blueorganizer/images/default/bookmark.png"
        return;
    }

    if (img.src.indexOf("http://s3.amazonaws.com/adaptiveblue_img/") == 0)
    {
        img.src = "http://s3.amazonaws.com/blueorganizer/images/avatar/" + cat + ".png"
    } else if (img.src.indexOf("http://s3.amazonaws.com/blueorganizer/images/") == 0) {
        img.src = "http://s3.amazonaws.com/blueorganizer/images/default/bookmark.png"
    } else {
        img.src = "http://s3.amazonaws.com/adaptiveblue_img/" + objKey;
    }
};

ExploreUtils.showPane = function(objectKey, link, appname)
{
    // if glue is installed, just use ID (@TODO smartlinks should support objectkeys directly)
    if (isGlueInstalled())
    {
        var protocolUrl = "glue://" + objectKey + (objectKey.indexOf("users/") == 0 ? "" : "/people");
        
        if($.browser.msie)
        {
            Glue.ProtocolHandler.request(protocolUrl);
        } else {
            $.getScript(protocolUrl);
        }
        
    } else if (objectKey.indexOf("users/") != 0) { // Ignore users if glue is not installed

        // If link is missing or points to glue, look it up
        if (link == null || link == "" || link.indexOf("http://getglue.com/") == 0)
        {
            $.ajax({
                type: "GET",
                url: "../api/getObject.php?objectId=" + objectKey,
                dataType: "json",
                success: function(json) {
                    if (json && json.object && json.object.link)
                    {
                        AdaptiveBlue.BlueLinkPane.showBLWindow(null, json.object.link, null, null, null, null, null, "People", "EXPLORE_SPIDER");
                    }
                }
            });
        } else {  // Otherwsie just launch pane
            AdaptiveBlue.BlueLinkPane.showBLWindow(null, link, null, null, null, null, null, "People", "EXPLORE_" + appname);
        }
    }
};