// ----------------------------------------------------------------------------
// TrimCategoryPhotoCount
//
// Takes a category of subcategory description that would typically
// look like this:
//
// 1 gallery with 11 photos 
// 4 galleries with 140 photos
// 
// And changes it to remove the photo count so it just looks like this:
//
// 1 gallery
// 4 galleries
// ----------------------------------------------------------------------------
function TrimCategoryPhotoCount()
{
    var miniBoxes = YD.getElementsByClassName("miniBox", "div", this);
    for (var i = 0; i < miniBoxes.length; i++)
    {
        var descriptions = YD.getElementsByClassName("description", "p", miniBoxes[i]);
        try 
        {
            var match = descriptions[0].innerHTML.match(/^\d+ galler(y|ies)/);
            descriptions[0].innerHTML = match[0];
        } catch (e) {}
    }
}
YE.onContentReady("categoriesBox", TrimCategoryPhotoCount);
YE.onContentReady("subcategoriesBox", TrimCategoryPhotoCount);

// script to replace a user's name in the breadcrumb with "Home"
YE.onContentReady("breadCrumbTrail", ReplaceTopOfBreadcrumbWithHome);

function ReplaceTopOfBreadcrumbWithHome()
{
    var str = this.innerHTML.replace(/\n/g, " ");
    this.innerHTML = str.replace(/\>[^\<]+<\/a>/i, ">Home</a>");
}

// Move filmstrip thumbs below the main image
YE.onDOMReady(PutFilmstripBelow);

function PutFilmstripBelow()
{
    if (YD.hasClass(document.body, "filmstrip"))
    {
        var moveWrapper = document.getElementById("moveWrapper");
        var photos = document.getElementById("photos");
        if (moveWrapper && photos)
        {
            var photosObj = photos.parentNode.removeChild(photos);
            moveWrapper.parentNode.insertBefore(photosObj, moveWrapper);
            photos.style.display = "block";
        }    
    }
}

function delHover() {
    oLst = YD.getElementsBy(function(el) {return (YD.hasClass(el,'imgBorder') || YD.hasClass(el,'imgBorderOn'))},'img');
    for (i=0; i < oLst.length ; i++) {
        if (oLst[i].title && oLst[i].title != '') oLst[i].title = '';
        if (oLst[i].alt && oLst[i].alt != '') oLst[i].alt = '';
    }
}
YE.onContentReady('bodyWrapper', function() {if (!YD.hasClass(document.body, 'smugmug_ajax')) delHover()});
onPhotoShow.subscribe(function(){YE.onAvailable('mainImage', delHover)});