// Change Home Link (from Devbobo)
YE.onContentReady('toolbar', function () { this.innerHTML = this.innerHTML.replace(/href="http:\/\/www.smugmug.com\/([?\w&;=]+)?"/, 'href="' + webServer + '"')});

function norobotmail(aUser, aDomain) { document.location = "mailto:" + aUser + "@" + aDomain; }



// change gallery removing photo numbers in description

function changeCategoryInfo()
{
  re = /^([0-9]+ )(galler(y|ies))/;
  divTag1 = document.getElementById("categoriesBox");
  divTag2 = document.getElementById("subcategoriesBox");
  if ((divTag1)|| (divTag2))
  {
    if (divTag1)
      divTags = divTag1.getElementsByTagName("div");
    else
      divTags = divTag2.getElementsByTagName("div");
    for (i=0; i<divTags.length; i++)
    {
      if (divTags[i].className == "miniBox")
      {
        pTags = divTags[i].getElementsByTagName("p");
        if (pTags.length > 1)
        {
         re.exec(pTags[1].innerHTML);
          pTags[1].innerHTML = RegExp.$1 + RegExp.$2;
        }
      }
    }
  }
}


YE.onAvailable("homelink", function(){this.href="http://www.pmbimages.com";});


// make SmugMug link in footer automatically be referral link

function AddReferralCode()  {
  var links = this.getElementsByTagName("A");
  if (links && (links.length != 0)) {
    var smugLink = links.item(0);
    smugLink.href = "http://www.smugmug.com/?referrer=Cn5sosTV50sWg";
  }
}
YE.onAvailable('footer', AddReferralCode);


// On IE/FF set the title before the Document OnLoad takes place
document.title = "::: PMB Images -- Photography by Paula M Brathwaite :::";
addEvent( window, "load", CustomizeTitle );
function CustomizeTitle()
{
    var baseTitle = "::: PMB Images -- Photography by Paula M Brathwaite :::";
    var separator = " - ";
    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 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";
        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;
        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;
    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;
    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";
 return;
 }
// A single keyword page
    if( pageTypeDefined && pageType == 'Keyword' && pageTypeDetailsDefined )
 {
// Keyword page
             document.title = baseTitle + separator + "Keyword: " + pageTypeDetails;
     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;
     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";
            return;
 }
// None of the rules above set the title! Oh well, fall back on the base title.
    document.title = baseTitle;
} // 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 Trim( node.innerText ); // For IE
    if( node.textContent )
        return Trim( node.textContent ); // For others
    return "";
} // GetText
function GetPhotoTitle()
{
// If the photo title is set, it starts with the breadcrumb.
    var breadCrumbStart = "pmbpro > ";
    var mainPhoto = document.getElementById("mainPhoto");
    if( !mainPhoto || !mainPhoto.title || mainPhoto.title.indexOf( breadCrumbStart ) != 0 )
 return "";
    return Trim( mainPhoto.title.substr( breadCrumbStart.length ) );
} // GetPhotoTitle





// unification of google stats, having nickname site URL redirected to the main domain - Now supports both nickname.smugmug.com and www.nickname.smugmug.com


function redirectPath() { 
  re = /((www.)?introversion.smugmug.com)/; 
  tmp = window.location.href; 
  if (re.test(tmp)) { 
    tmp = tmp.replace(re, 'www.pmbimages.com'); 
    window.location.href = tmp; 
  } 
}
redirectPath();  



// right click protection of homepage slideshow

function insertSlideshowNoClick(width, height, parms, transparency)
{
	var isClickURL = false;
	var gifHeight = height;
	var gifWidth = width;
	
	// it appears that the default for showThumbs is true
	if ((!parms.showThumbs) || ((parms.showThumbs == "true") && (height > 100)))
	{
		gifHeight -= 87;
	}
	// can't support the startButton because it will never get clicked
	if (parms.showStartButton)
	{
		delete parms.showStartButton;
	}
	// can't support the buttons because they will never get clicked
	if (parms.showButtons)
	{
		parms.showButtons = "false";		
	}
	document.write('<div id="slideshowContainerWrapper" style="position:relative;">\n');
	if (parms.clickUrl && (parms.clickUrl != "blank") && (parms.clickUrl != "false"))
	{
		isClickURL = true;
		var newWindowText = "";
		if (parms.newWindow && (parms.newWindow == "true"))
		{
			newWindowText = ' target="_blank" ';
		}
		document.write('<a href="' + parms.clickUrl + '"' + newWindowText + '>');
	}
	document.write('<img src="/img/spacer.gif" border="0" style="position:absolute;" height="' + gifHeight + '" width="' + gifWidth + '" oncontextmenu="return false;">\n');
	if (isClickURL)
	{
		document.write('</a>');
	}
	SM.flash.insertSlideshow(width, height, parms, transparency);
	document.write("</div>");
}

