var categoryDescription = {
  // list "categoryname" : "category title",
  // or "categoryname.subcategoryname" : "subcategory title",
  // Examples:
  // "Kenya"  : "Our vacation to Kenya",
  // "Kenya.Highlights" : "The highlights galleries from our vacation to Kenya",

"Portraits.Champions_2009":
"Welcome to the Champions Westlake photo gallery for 2009!<br/>Parents:<br/>Online ordering makes it easier than ever to purchase Champions portraits.  Enjoy browsing through your child's photos and create your own portrait package!  Choose from 8x10's, 5x7's, 4x6's, wallets, and many other sizes and products like buttons, magnets, mugs, and more!  Get started by locating your child's class below.  If you have any questions, feel free to <a href=\"mailto:nimai_malle@yahoo.com\">contact me</a>.<br/>",
"Dance.Zenith_2009":
"Welcome to my huge gallery of Zenith photos!  I've tried to make it as easy as possible for you to find the photos you're looking for.  I've made a gallery for each dance number and performance, and put photos from Thursday, Friday, and Saturday together in each.<br/><div style=\"text-align:center\"><img border=\"0\" align=\"center\" height=\"256\" alt=\"Zenith 2009 Panorama\" src=\"http://img57.imageshack.us/img57/5467/zenith2009sm.jpg\"/><br/>If you would like a large print of this panorama, or have any questions, please <a href=\"mailto:nimai_malle@yahoo.com\">contact me</a>.</div><br/>For all of the other Hyline photos from 2008-2009, click <a href=\"http://nimai.smugmug.com/School/621067\">here</a>."
};

function addCategoryTitleToBreadcrumb(description) 
{
    var breadCrumb = YD.get("subCatGalleryTitle");
    if (breadCrumb)
    {
        var divTag = document.createElement("div");
        divTag.className = "categoryDescription";
        divTag.innerHTML = description;
        breadCrumb.parentNode.insertBefore(divTag, breadCrumb.nextSibling);
    }
}

function addCategoryTitleToThumbs(descriptionObject, boxObjectName) 
{
    var re = /\>([^\<]+)<\/a>/i;    // pattern to find the category name between the <a> and </a> tags
    var divTag = YD.get(boxObjectName);
    if (divTag) 
    {
        var divTags = YD.getElementsByClassName("albumTitle", "p", divTag);
        for (var i = 0; i < divTags.length; i++) 
        {
            var matches = re.exec(divTags[i].innerHTML);    // get just the category name
            // if we found a category name and the category name exists in our categoryDescription object, then add the description
            if (matches && (matches.length > 1) && descriptionObject[matches[1]] != undefined) 
            {
                var pTag = document.createElement("p");
                pTag.className = "categoryDescription";
                pTag.innerHTML = descriptionObject[matches[1]];
                divTags[i].parentNode.insertBefore(pTag, divTags[i].nextSibling);
            }
        }
    }
}

/* Category descriptions */
function addCategoryDescription() 
{    
    var re, matches, i;        // various local variables

    // now fix it so that it works automatically even if the category or sub-category name has spaces in it
    // we replace those spaces with underscores (which is what the classname does) and add those to our object so we can match those too
    for (i in categoryDescription) 
    {
        var newName = i.replace(/ /g, "_");
        categoryDescription[newName] = categoryDescription[i];    // add a property to the object that has only underscores in the name
    }
    // on the homepage, we want to check for category names and add a description if a match found
    // on a category page, we want to check to see if the category that the page is needs a description under the breadcrumb
    //      and, we need to see if any of the sub-category items on the page need us to add a description under the name
    // on a sub-category page, we want to check to see if the sub-category that the page is needs a description under the breadcrumb
    if (YD.hasClass(document.body, "category")) 
    {
        // fetch the category name
        re = /category_(\S+)/i;
        matches = re.exec(document.body.className);
        if (matches && (matches.length > 1)) 
        {
            var categoryName = matches[1];
            // now see if we have a subcategory too
            if (YD.hasClass(document.body, "subcategory")) 
            {
                re = /subcategory_(\S+)/i;
                matches = re.exec(document.body.className);
                if (matches && (matches.length > 1)) 
                {
                    var subcatName = matches[1];
                    // category and subcategory so we are on a subcategory page showing a list of galleries in this subcategory
                    // we need to just add a subcategory title to this page if the category-subcategory matches
                    var fullName = categoryName + "." + subcatName;
                    if (categoryDescription[fullName])
                    {
                        addCategoryTitleToBreadcrumb(categoryDescription[fullName]);
                    }
                }
            }
            // here we're on a category page
            // we need to add a category description for the category page
            // and potentially add subcategory descriptions to the subcategory names displayed on this page
            else 
            {
                if (categoryDescription[categoryName])
                {
                    addCategoryTitleToBreadcrumb(categoryDescription[categoryName]);
                }
                // now we need to build a temporary subcategoryDescription object that has only the subcategory names in it that are in this category
                var subcatDescriptions = {};
                re = new RegExp("^" + categoryName + "\\.(.+)$", "i");
                for (i in categoryDescription)
                {
                    matches = re.exec(i);
                    if (matches && (matches.length > 1))
                    {
                        subcatDescriptions[matches[1]] = categoryDescription[i];
                    }
                }
                addCategoryTitleToThumbs(subcatDescriptions, "subcategoriesBox");
            }
        }
    }

    // then see if we're on the homepage
    if (YD.hasClass(document.body, "homepage")) 
    {
        addCategoryTitleToThumbs(categoryDescription, "categoriesBox");
    }
}

YE.onDOMReady(addCategoryDescription);


//
// Move sub-categories to the top of the galleries box, and hide the sub-cat box
//
// 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]);
	}
}

