/*==================================================*/
/* Provide the Copyright Notice When Right-Clicking */
/* =================================================*/
rightClickWarning = "All photos are the property of Chris Rabior Photography.  All rights reserved.  Unauthorized use is prohibited.  If you would like to obtain an image from this site, contact the photographer to discuss licensing and/or print availability:  photos@chrisrabior.com"

function norobotmail(aUser, aDomain) { document.location = "mailto:" + aUser + "@" + aDomain; }

/*==================================================*/
/* Custom Site Titles for each page on site ======= */
/* =================================================*/
/*
--------------------------------------------------
    ContextualizeTitle Settings
--------------------------------------------------
*/
var titleSettings = {
    separator    : ": ",    // Text to insert between parts of title.
    maxLength    : -1,      // Limits length of title (-1 == no limit).
    doPhotos     : true,    // true == append photo captions
    doAlbums     : true,    // true == append album names
    doGalleries  : true,    // true == append gallery names
    stripSmugmug : true,    // true == remove " - powered by SmugMug" from title bar text
    inverse      : false,   // true == reverse order of home/gallery/album/photo
    siteTitle    : null     // null == use normal site title. "" == suppress site title. "Any Value" == replaces normal site title.
};
 
/*
--------------------------------------------------
    ContextualizeTitle Class
--------------------------------------------------
*/
function ContextualizeTitle ()
{
    var pieces = new TitlePieces();
    var newTitle = "";
    if (titleSettings.inverse)
    {
        newTitle = MakeTitleBackward();
    }
    else
    {
        newTitle = MakeTitleForward();
    }
    if (titleSettings.maxLength > -1)
    {
        newTitle = newTitle.substr(0, titleSettings.maxLength);
    }
    if (titleSettings.stripSmugmug == false)
    {
        newTitle += " - powered by SmugMug";
    }
    document.title = newTitle;
 
    // METHODS
 
    function MakeTitleBackward ()
    {
        var title = "";
        title += pieces.Photo
        if (title.length > 0
            && pieces.Album.length > 0)
        {
            title += titleSettings.separator;
        }
        title += pieces.Album;
        if (title.length > 0
            && pieces.Gallery.length > 0)
        {
            title += titleSettings.separator;
        }
        title += pieces.Gallery;
        if (title.length > 0
            && pieces.Main.length > 0)
        {
            title += titleSettings.separator;
        }
        title += pieces.Main;
        return title;
    }
 
    function MakeTitleForward ()
    {
        var title = "";
        title += pieces.Main;
        if (title.length > 0
            && pieces.Gallery.length > 0)
        {
            title += titleSettings.separator;
        }
        title += pieces.Gallery;
        if (title.length > 0
            && pieces.Album.length > 0)
        {
            title += titleSettings.separator;
        }
        title += pieces.Album;
        if (title.length > 0
            && pieces.Photo.length > 0)
        {
            title += titleSettings.separator;
        }
        title += pieces.Photo
        return title;
    }
 
    // CLASSES
 
    function TitlePieces ()
    {
        this.Main = GetMainTitle();
        this.Gallery = GetGalleryTitle();
        this.Album = GetAlbumTitle();
        this.Photo = GetPhotoTitle();
 
        function GetMainTitle ()
        {
            var value = titleSettings.siteTitle;
            if (value == null)
            {
                var index = document.title.indexOf("- powered by SmugMug");
                value = document.title.substr(0, index);
            }
            return value;
        }
 
        function GetGalleryTitle ()
        {
            var value = "";
            if (titleSettings.doGalleries)
            {
                var element = document.getElementById("galleryTitle");
                if (element)
                {
                    value = GetTextContent(element);
                    if (value.length > 0)
                    {
                         // remove " galleries" from title
                        var index = value.indexOf(" galleries");
                        if (index > -1)
                        {
                            value = value.substr(0, index);
                        }
                    }
                }
            }
            return value;
        }
 
        function GetAlbumTitle ()
        {
            var value = "";
            if (titleSettings.doAlbums)
            {
                var element = document.getElementById("albumTitle");
                if (element)
                {
                    value = GetTextContent(element);
                }
            }
            return value;
        }
 
        function GetPhotoTitle ()
        {
            var value = "";
            if (titleSettings.doPhotos)
            {
                var element = document.getElementById("caption_bottom");
                if (!element)
                {
                    element = document.getElementById("caption_top");
                }
                if (element)
                {
                    value = GetTextContent(element);
                }
            }
            return value;
        }
 
    }
 
} // end of ContextualTitle class
 
/*
--------------------------------------------------
    Utility Methods
--------------------------------------------------
*/
 
function GetPhotoCaption()
{
    var caption = "";
    var photoTitle = document.getElementById("caption_bottom");
    if(!photoTitle)
    {
        photoTitle = document.getElementById("caption_top");
    }
    if(photoTitle)
    {
        caption = GetTextContent(photoTitle);
    }
    return caption;
}
 
function GetTextContent(node)
{
    var text = "";
    if(node)
    {
        if(node.children)
        {
            text = GetTextContent(node.firstChild);
        }
        else
        {
            if(node.nodeValue)
            {
                text = node.nodeValue; // IE
            }
            else
            {
                text = node.textContent; // mozilla
            }
        }
    }
    text = Trim(text);
    return text;
}
 
function Trim(text)
{
    var regexp = /^\s+|\s+$/g;
    text = text.replace(regexp, "");
    return text;
}
 
function IsHomePage()
{
    var isHomePage = false;
    // test for the "homepage" class name in the <BODY> tag
    var classStr = document.body.className;
    if (classStr && (classStr.indexOf("homepage") != -1))
    {
        isHomePage = true;
    }
    return isHomePage;
}