YE.onAvailable('featuredTitle', function() {this.innerHTML = 'New Galleries'}); 

function hasPath(sPath)
{
re = new RegExp("\/" + sPath + "(\/|$)");
return re.test(window.location)
}

if (hasPath("galleries"))
YD.addClass(document.body, "galleries");

function IsSmugmugView()
{
    return(YD.hasClass(document.body, "smugmug"));
}

function IsGalleryPage()
{
    return(YD.hasClass(document.body, "galleryPage"));
}

// code to insert a download button for any gallery that has originals enabled

onPhotoShow.subscribe(ProcessDownloadButton);

function ProcessDownloadButton()
{
    // set onlyInGalleries to true if you only want a download button in gallery views
    // set onlyInGalleries to false if you want a download button in other views too like (search, keywords, date, etc...)
    var onlyInGalleries = true;
    if (IsSmugmugView() && (IsGalleryPage() || !onlyInGalleries))
    {
        if (photoInfo[ImageID].albumOriginals && !photoInfo[ImageID]['protected'] && (photoInfo[ImageID].Format !== "MP4"))
        {
            var downloadParent = "cartButtonsWrapper";
            if (!document.getElementById("cartButtonsWrapper"))
            {
                downloadParent = "altViews";
            }
            InsertDownloadButton(downloadParent);
            //InsertDownloadButton("altViews");
        }
        else
        {
            // disable the button
            var downloadButton = YAHOO.widget.Button.getButton("downloadButtonId");
            if (downloadButton)
            {
                downloadButton.set("disabled", true);
            }
        }
    }
}

function InsertDownloadButton(parentId)
{
    // now add the download button
    var parentDiv = document.getElementById(parentId);
    var downloadButton = document.getElementById("downloadButtonId");
    if (downloadButton)
    {
        // make sure it is enabled
        YAHOO.widget.Button.getButton("downloadButtonId").set("disabled", false);
    }
    else if (parentDiv)
    {
        var downloadButtonInfo =
        {
            id: "downloadButtonId",
            label: "Download Image...",
            container: parentDiv,
            type: "button",
            className: "sm-button sm-button-small themesButton glyphButton",
            onclick: { fn: InitiateDownloadImage }
        };
        
        var dButtonObj = new YAHOO.widget.Button(downloadButtonInfo);
    }
}

function InitiateDownloadImage()
{
    // construct the download URL
    window.location = "/photos/" + ImageID + "_" + ImageKey + "-D.jpg";
}
 