displaySmugPopular = false

function AddReferralCode()
  {
  	var footerDiv = document.getElementById("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=TiAmCc4R4j9is";
  		}
  	}
  }
  
  function OnLoadHandler()
  {
  	AddReferralCode();
  }
 


function doOnLoad()
{
if (window.AlbumID && window.AlbumID == "1834608") //
if (window.AlbumID && window.AlbumID == "1833351") //
{
removeLinkFromImg();
}
}

function removeLinkFromImg()
{
var links = document.getElementsByTagName("A");
for (var i = 0; i < links.length; i++)
{
var link = links[i];
var divElm = link.parentNode;
if (!divElm) continue;
if (divElm.className.indexOf("photo")<0) continue;
link.href = "javascript:void(0);";
}
}


function norobotmail(aUser, aDomain) { 
       document.location = "mailto:" + aUser + "@" + aDomain;
    }


/*
----------------------------
Titlebar Customizer
----------------------------
*/

var titleSettings = new Array();

titleSettings.separator = ": "; // text to insert between parts of title
titleSettings.maxLength = -1; // limits length of title (-1 == no limit)
titleSettings.doPhotos = true; // true == append photo captions
titleSettings.doAlbums = true; // true == append album names
titleSettings.doGalleries = true; // true == append gallery names
titleSettings.stripSmugmug = true; // true == remove " - powered by SmugMug" from title bar text

function ContextualizeTitle()
{
var smugmugSuffix = " - powered by SmugMug";
var insertAt = document.title.indexOf(smugmugSuffix);
var newTitle = document.title;
var newText = null;

if(IsHomePage() == false)
{
// Add gallery title
if(titleSettings.doGalleries)
{
var galleryTitle = document.getElementById("galleryTitle");
if(galleryTitle)
{
var galleryTitleText = GetTextContent(galleryTitle);
if(galleryTitleText.length > 0)
{
var index = galleryTitleText.indexOf(" galleries");
if(index > -1)
{
galleryTitleText = galleryTitleText.substr(0, index);
}
newText = titleSettings.separator + galleryTitleText;
newTitle = InsertString(newTitle, newText, insertAt);
}
}
}

// Add album title
if(titleSettings.doAlbums)
{
var albumTitle = document.getElementById("albumTitle");
if(albumTitle)
{
var albumTitleText = GetTextContent(albumTitle);
if(albumTitleText.length > 0)
{
newText = titleSettings.separator + albumTitleText;
newTitle = InsertString(newTitle, newText, insertAt);
}
}
}

// Add photo title
if(titleSettings.doPhotos)
{
var photoTitleText = GetPhotoCaption();
if(photoTitleText.length > 0)
{
newText = titleSettings.separator + photoTitleText;
newTitle = InsertString(newTitle, newText, insertAt);
}
}

// Set the new title
if(titleSettings.maxLength > -1)
{
newTitle = newTitle.substr(0, titleSettings.maxLength);
}
}

// Remove the "- powered by SmugMug" segment
if(titleSettings.stripSmugmug)
{
var regexp = /- powered by SmugMug/g;
newTitle = newTitle.replace(regexp, "");
}

// Set the title in the document
document.title = newTitle;
}

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 InsertString(text, insertText, index)
{
var newText = "";

if(index > -1 && index < text.length)
{
newText = text.substring(0, index) + insertText + text.substring(index);
}
else
{
newText = text + insertText;
}

return newText;
}

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;
}

/* Add a handler for the window load event. Calls ContextualizeTitle on window load */
addEvent(window, "load", ContextualizeTitle); 

var vanityTable = 
 {
     workshop : "http://pidge.smugmug.com/gallery/7620618_YfDXB",
     rwenzori : "http://pidge.smugmug.com/gallery/9022082_nd6DV#600168720_bkuKw",
     syria : "http://www.pidgephotography.com/gallery/8385424_QAYvX#550253119_2Hcrg",
     prague : "http://www.pidgephotography.com/gallery/8397351_mR26f#551205642_Z9hbe",
 };
function CheckRedirects()
 {
     if (YD.hasClass(document.body, 'homepage'))    // only run this code on the home page
     {
         // get the path from the current URL, 
         // convert it to lowercase and remove the leading slash
         var path = window.location.pathname.toLowerCase().substr(1);
         
         var newURL = vanityTable[path];        // look it up in our table
         
         // if we found it in the table && newURL is different than where we are
         if (newURL && (newURL != window.location))
         {
             window.location.replace(newURL);        // go to the new URL
         }
     }
 }