var isLoggedIn = false;
addEvent( window, "load", getLoggedInStatus );

/*
resizeLarge();
*/

function resizeLarge() {
var url = window.location.href;

if (url.indexOf("/Small") + url.indexOf("/Medium") + url.indexOf("/Original") > -3) {
window.location.replace(url.substr(0, url.lastIndexOf("/")) + "/Large")
}
}

function norobotmail(aUser, aDomain) { 
       document.location = "mailto:" + aUser + "@" + aDomain;
    }


function getLoggedInStatus() {
if (document.body.className && document.body.className.indexOf("loggedIn") > -1)
{isLoggedIn=true;}
}

/*=================================*/
/*== BROWSER TITLE CUSTOMIZATION ==*/
/*=================================*/
// On IE/FF set the title before the Document OnLoad takes place

document.title = "ForeFront Photography - Greg Brownstein";
//addEvent( window, "load", CustomizeTitle );

function CustomizeTitle()
{
    var baseTitle = "ForeFront Photography";
    var separator = " - ";
	var loggedInTitle = "Logged In";
    var albumTitle = GetText( document.getElementById("albumTitle") );
    var galleryTitle = GetText( document.getElementById("galleryTitle") );
    var subCatTitle = GetText ( document.getElementById("subCatGalleryTitle") );
    var singleImage = document.body.className && document.body.className.indexOf("singleImage") > -1 ? true : false;
    var isPopularGallery = document.body.className && document.body.className.indexOf("popularGallery") > -1 ? true : false;
    isLoggedIn = document.body.className && document.body.className.indexOf("loggedIn") > -1 ? true : false;
    var pageTypeDefined = typeof( pageType ) != "undefined";
    var pageTypeDetailsDefined = typeof( pageTypeDetails ) != "undefined";
// Don't change the title from the above document.title on the homepage
    if( document.body.className && document.body.className.indexOf("homepage") > -1 )
    {
        document.title = baseTitle + separator + "Home";
		if (isLoggedIn) {document.title = document.title + separator + loggedInTitle;}
        return;
    }
 
// An album page (holds a bunch of photos, could be "zoomed in" on a specific photo)
    if( albumTitle )
    {
        var photoTitle = GetPhotoTitle();
        if( photoTitle )
            document.title = baseTitle + separator + albumTitle + separator + photoTitle;
        else
            document.title = baseTitle + separator + albumTitle;
		if (isLoggedIn) {document.title = document.title + separator + loggedInTitle;}
        return;
    }
// A gallery page (holds a bunch of albums and/or a bunch of sub categories)
    if( galleryTitle )
    {
// Strip " sub-categories" off the end of the category text
        var finalPositionCategory = galleryTitle.indexOf(" sub-categories");
        if( finalPositionCategory > -1 )
            galleryTitle = galleryTitle.substr( 0, finalPositionCategory );
        else
            {
// Strip " galleries" off the end of the category/sub-category text
              var finalPositionSubCategory = galleryTitle.indexOf(" galleries");
              if( finalPositionSubCategory > -1 )
          galleryTitle = galleryTitle.substr( 0, finalPositionSubCategory );
             }
 
            document.title = baseTitle + separator + galleryTitle;
	if (isLoggedIn) {document.title = document.title + separator + loggedInTitle;}
    return;
    }
// Pick up sub-category
    if( subCatTitle )
    {
// Strip " sub-categories" off the end of the category text
        var finalPositionCategory = subCatTitle.indexOf(" sub-categories");
        if( finalPositionCategory > -1 )
            galleryTitle = subCatTitle.substr( 0, finalPositionCategory );
        else
            {
// Strip " galleries" off the end of the category/sub-category text
              var finalPositionSubCategory = subCatTitle.indexOf(" galleries");
              if( finalPositionSubCategory > -1 )
          galleryTitle = subCatTitle.substr( 0, finalPositionSubCategory );
             }
 
            document.title = baseTitle + separator + galleryTitle;
	if (isLoggedIn) {document.title = document.title + separator + loggedInTitle;}
    return;
    }
 
// A single image (like the kind you get when you click an image in a keyword page)
    if( singleImage )
        {
 var photoTitle = GetPhotoTitle();
 if( photoTitle )
            document.title = baseTitle + separator + photoTitle;
 else
     document.title = baseTitle + separator + "untitled photo";
if (isLoggedIn) {document.title = document.title + separator + loggedInTitle;}
 return;
 }
// A single keyword page
    if( pageTypeDefined && pageType == 'Keyword' && pageTypeDetailsDefined )
 {
// Keyword page
             document.title = baseTitle + separator + "Keyword: " + pageTypeDetails;
	if (isLoggedIn) {document.title = document.title + separator + loggedInTitle;}
     return;
 }
// A multiple keyword page
    if( pageTypeDefined && pageType == 'Keywords' && pageTypeDetailsDefined )
 {
// Multiple keywords page
// Put " + " between each keyword instead of -
             var keywordList = pageTypeDetails;
     keywordList = keywordList.replace(/\-/g, " + ");
     document.title = baseTitle + separator + "Keywords: " + keywordList;
	if (isLoggedIn) {document.title = document.title + separator + loggedInTitle;}
     return;
 }
// The main keywords page. Note: single image takes precedence over this type
    if( document.body.className && document.body.className.indexOf("keywordPage") > -1 )
        {
// Main Keywords Page
            document.title = baseTitle + separator + "Keywords";
			if (isLoggedIn) {document.title = document.title + separator + loggedInTitle;}
            return;
 }
	if (isPopularGallery)
	{
		document.title = baseTitle + separator + "Popular photos";
		if (isLoggedIn) {document.title = document.title + separator + loggedInTitle;}
		return;
	}
// None of the rules above set the title! Oh well, fall back on the base title.
    document.title = baseTitle;
	if (isLoggedIn) {document.title = document.title + separator + loggedInTitle;}
} // CustomizeTitle
function Trim( text )
{
    text = text.replace(/(^\s+)|(\s+$)/g, ""); // trim leading and trailing white space
    return text;
} // Trim
function GetText( node )
{
    if( !node )
        return "";
    if( node.innerText )
        return RemoveEditTag(Trim( node.innerText )); // For IE
    if( node.textContent )
        return RemoveEditTag(Trim( node.textContent )); // For others
    return "";
} // GetText
function RemoveEditTag(text)
{
	var edit = " edit";
	if (text.lastIndexOf(edit) == text.length-edit.length)
	{
		text = text.substring(0, text.length-edit.length);
	}
	return text;
} // RemoveEditTag
function GetPhotoTitle()
{
// If the photo title is set, it starts with the breadcrumb.
    var breadCrumbStart = "ForeFront Photography > ";
    var mainPhoto = document.getElementById("mainPhoto");
    if( !mainPhoto || !mainPhoto.title || mainPhoto.title.indexOf( breadCrumbStart ) != 0 )
 return "";
    return Trim( mainPhoto.title.substr( breadCrumbStart.length ) );
} // GetPhotoTitle
/*=====================================*/
/*== END BROWSER TITLE CUSTOMIZATION ==*/
/*=====================================*/
