rightMoves = -5;
leftMoves = 5;


/* Not that I have right-click protection enabled anywhere, but in case I ever turn it on...*/
rightClickWarning = "These photos are copyright Andrew Davidson. All rights reserved. Unauthorized use is prohibited.";


/* Link rewriting script courtesy of jfriend, here: http://dgrin.com/showpost.php?p=194946&postcount=30 */
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=4Gj82gBlW4N8c";
  		}
  	}
  }
  
/* Functions that update the page's title to be a little more informative, from this dgrin thread (thanks to MikeFried and Gary Glass): http://dgrin.com/showthread.php?t=25861 */
function ContextualizeTitle() {
	var separator = " : ";
	var smugmugSuffix = " - powered by smugmug";
	var insertAt = document.title.indexOf(smugmugSuffix);
	var newTitle = document.title;
	var newText = null;
	if(!IsHomePage()) {
		// add photo title
		var photoTitleText = GetPhotoCaption();
		if(photoTitleText.length > 0) {
			newText = separator + photoTitleText;
			newTitle = InsertString(newTitle, newText, insertAt);
		}
		// add album title
		var albumTitle = document.getElementById("albumTitle");
		if(albumTitle) {
			var albumTitleText = GetTextContent(albumTitle);
			if(albumTitleText.length > 0) {
				newText = separator + albumTitleText;
				newTitle = InsertString(newTitle, newText, insertAt);
			}
		} else {
			// add gallery title
			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 = separator + galleryTitleText;
					newTitle = InsertString(newTitle, newText, insertAt);
				}
			}
		}
		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 = text.substring(0, index) + insertText + text.substring(index);
	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  tag
	var classStr = document.body.className;
	if (classStr && (classStr.indexOf("homepage") != -1)) {
		isHomePage = true;
	}
	return isHomePage;
}



function OnLoadHandler() {
	AddReferralCode();
	ContextualizeTitle();
}