// change the link on the SmugMug Logo

YE.onAvailable('homelink', function(e) {
    this.href = "http://theseverinis.com/";
    this.firstChild.alt = "Severini Photopgrahy";
    this.firstChild.title = "Severini Photography";
});

// removes the pipes characters in the toolbar header

YE.onAvailable('toolbar', function(e) {
this.innerHTML = this.innerHTML.replace(new RegExp(/\|/g),"");
});

// ------------------------------------------------------------------------------------------------------------------------------------
// Script to change the breadcrumb link to your homepage to point to your galleries page instead of your slideshow
// It also changes that link to say "Galleries" instead of your user name

function AdjustBreadcrumb()
{
	// there are something like six different forms of the breadcrumb including search and keyword and date and communities, categories and galleries that we have to make this work for
	var tags = YD.getElementsByClassName("nav", "a", this);		// get all the <a> tags with class "nav"
	var filteredTags = new Array;
	// filter out any that aren't at the top level in the breadCrumbTrail (this gets rid of the relatedDate tags)
	for (var i in tags)
	{
		if (tags[i].parentNode == this)
		{
			filteredTags.push(tags[i]);
		}
	}
	if (filteredTags.length == 0)
	{
		return;
	}
	// default to targeting the first filtered tag
	var targetTag = filteredTags[0];
	
	// see if we have a community here
	if (filteredTags.length > 1)
	{
		// if we have a community here, then the user top level is in the 2nd position
		if (filteredTags[0].href.search(/\/community\//) != -1)
		{
			targetTag = filteredTags[1];
		}
	}
	// if there's a ?xxxx parameter, make sure that stays at the end
	var str = targetTag.href;
	var parms = "";
	var pos = str.search(/\?/);
	if (pos != -1)
	{
		parms = str.substr(pos);
		str = str.substr(0, pos);
	}
	// make sure URL ends with a slash
	if (str.search(/\/$/) == -1)
	{
		str += "/";
	}
	str +="";						// can be changed to point to a category
	str += parms;							// put parms back on
	targetTag.href = str;
	targetTag.innerHTML = "Galleries";		// can be changed to whatever you want the top level to be called
}

YE.onContentReady("breadCrumbTrail", AdjustBreadcrumb);

// END OF
// Script to change the breadcrumb link to your homepage to point to your galleries page instead of your slideshow
// It also changes that link to say "Galleries" instead of your user name
// ------------------------------------------------------------------------------------------------

// This is a script to combine the categories with the gallery listing to have just one continuous listing of thumbs
YE.onContentReady("subcategoriesBox", CombineCategoriesWithGalleries);

function IsArrayEmpty(testVal)
{
    return(!testVal || (testVal.length == 0));
}

function CombineCategoriesWithGalleries()
{
    // get miniBoxes in the subcategoriesBox object
    var miniBoxes = YD.getElementsByClassName("miniBox", "div", this);
    // get target galleriesBox object
    var galleriesObj = document.getElementById("galleriesBox");
    var galleryMiniBoxes = new Array;

    // now find the right miniBox in the galleriesBox in order to insert the sub-categories
    if (galleriesObj)
    {
        galleryMiniBoxes = YD.getElementsByClassName("miniBox", "div", galleriesObj);
    }
    
    // if we don't have everything we need, then return without doing anything
    if (!galleriesObj || IsArrayEmpty(miniBoxes) || IsArrayEmpty(galleryMiniBoxes) || (window.location.hash == "#stop"))
    {
        this.style.display = "block";        
        return;
    }
    
    // move all the sub-categories over to the gallery listing
    for (var i in miniBoxes)
    {
        miniBoxes[i].parentNode.removeChild(miniBoxes[i]);
        galleryMiniBoxes[0].parentNode.insertBefore(miniBoxes[i], galleryMiniBoxes[0]);
    }
}
