function AddReferralCode()  {
   var footerDiv = YD.get("footer");
   if (footerDiv)  {
     var links = footerDiv.getElementsByTagName("A");
     if (links && (links.length != 0)) {
       var smugLink = links.item(0);
       smugLink.href = "http://www.smugmug.com/?referrer=HjP4UrF5a0v0U";
     }
  }
}
YE.onAvailable('footer', AddReferralCode);


var myVideo1 = '<object width="425" height="236"><param name="movie" value="http://www.lookingglassphotography.com.au/ria/ShizVidz-2008120101.swf" /><param name="allowFullScreen" value="true" /><param name="flashVars" value="s=ZT0xJmk9NDY4NDQ2ODM2Jms9WWpzWjcmYT03Mjc3N TAzX21Ia3FyJnU9bG9va2luZ2dsYXNzcGhvdG9ncmFwaHk=" /><embed src="http://www.lookingglassphotography.com.au/ria/ShizVidz-2008120101.swf" flashVars="s=ZT0xJmk9NDY4NDQ2ODM2Jms9WWpzWjcmYT03M jc3NTAzX21Ia3FyJnU9bG9va2luZ2dsYXNzcGhvdG9ncmFwaHk =" width="425" height="236" type="application/x-shockwave-flash" allowFullScreen="true"></embed></object>';

var myVideo2 = '<object width="425" height="240"><param name="movie" value="http://cdn.smugmug.com/ria/ShizVidz-2008120101.swf" /><param name="allowFullScreen" value="true" /><param name="flashVars" value="s=ZT0xJmk9NDcxNTk0Mjk4Jms9UUxHV2MmYT03MzEzNjQ0X0dZcHdEJnU9bG9va2luZ2dsYXNzcGhvdG9ncmFwaHk=" /><embed src="http://cdn.smugmug.com/ria/ShizVidz-2008120101.swf" flashVars="s=ZT0xJmk9NDcxNTk0Mjk4Jms9UUxHV2MmYT03MzEzNjQ0X0dZcHdEJnU9bG9va2luZ2dsYXNzcGhvdG9ncmFwaHk=" width="425" height="240" type="application/x-shockwave-flash" allowFullScreen="true"></embed></object>';


var myVideo3 = '<object width="425" height="240"><param name="movie" value="http://cdn.smugmug.com/ria/ShizVidz-2008120101.swf" /><param name="allowFullScreen" value="true" /><param name="flashVars" value="s=ZT0xJmk9NDc1OTY4OTA5Jms9MlhRakgmYT03Mzg0MDcyX3ZBUW5RJnU9bG9va2luZ2dsYXNzcGhvdG9ncmFwaHk=" /><embed src="http://cdn.smugmug.com/ria/ShizVidz-2008120101.swf" flashVars="s=ZT0xJmk9NDc1OTY4OTA5Jms9MlhRakgmYT03Mzg0MDcyX3ZBUW5RJnU9bG9va2luZ2dsYXNzcGhvdG9ncmFwaHk=" width="425" height="240" type="application/x-shockwave-flash" allowFullScreen="true"></embed></object>';

var myVideo4 = '<object width="425" height="240"><param name="movie" value="http://www.lookingglassphotography.com.au/ria/ShizVidz-2008120101.swf" /><param name="allowFullScreen" value="true" /><param name="flashVars" value="s=ZT0xJmk9NDczMzY5MDkzJms9UkpLWFcmYT03Mjc3MTgwX3Jrd3pVJnU9bG9va2luZ2dsYXNzcGhvdG9ncmFwaHk=" /><embed src="http://www.lookingglassphotography.com.au/ria/ShizVidz-2008120101.swf" flashVars="s=ZT0xJmk9NDczMzY5MDkzJms9UkpLWFcmYT03Mjc3MTgwX3Jrd3pVJnU9bG9va2luZ2dsYXNzcGhvdG9ncmFwaHk=" width="425" height="240" type="application/x-shockwave-flash" allowFullScreen="true"></embed></object>';

function addCategoryTitleToBreadcrumb(description) 
{
    var breadCrumb = YD.get("breadcrumb");
    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(titleOnly) 
{
    var categoryDescription = {
        "Travel.Cambodia"  : myVideo1,
        "Travel" : myVideo2,
        "Central Coast New South Wales Australia.Surfing" : myVideo3,
        "Travel.Vietnam"  : myVideo4
    };
    
    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]);
                }
                if (!titleOnly)
                {
                    // 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 (!titleOnly && YD.hasClass(document.body, "homepage")) 
    {
        addCategoryTitleToThumbs(categoryDescription, "categoriesBox");
    }
}

function addCategoryDescriptionTitleOnly()
{
    addCategoryDescription(true);
}

YE.onDOMReady(addCategoryDescriptionTitleOnly);


