function ModifyText ()
{
  if (YD.hasClass(document.body, "gallery_3954346"))
  {
    var objElement = YD.get("comment")
    if (objElement != null)
    {
      var str = new String(objElement.innerHTML);
      str = str.replace(/\gallery/gi, 'guestbook');
      objElement.innerHTML = str;
    }
  }
}

YE.onAvailable("comment", ModifyText);

function AddReferralCode() {
var links = this.getElementsByTagName("A");
if (links && (links.length != 0)) {
var smugLink = links.item(0);
smugLink.href = "http://www.smugmug.com/?referrer=dslVL0NeZhe9w";
}
}

YE.onAvailable('footer', AddReferralCode);


function hasPath(sPath)
{
re = new RegExp("\/" + sPath + "(\/|$)");
return re.test(window.location)
}
/*=========================*/

/*== SLIDE SHOW          ==*/

/*== version 0.58        ==*/

/*== Updated 15 Mar 2007 ==*/

/*=========================*/

var SLIDE_SHOW = 0;

var RANDOM_PHOTO = 1;

var slideshowContainer;

var sSlide;

var sCaption;

var ssSlides;

var ssSlideTotal;

var ssSlideTimer;

var ssOldSlide;

var ssFadeTimer;

var ssFade;

var ssTimerId;

var blank;





function PrepSlideEnvironment() {

  tmpCookie = getCookie("Template");



  blank = new Image();

  blank.src = "/img/spacer.gif";



  if (typeof(slideshowType) == "undefined" || (slideshowType != SLIDE_SHOW && slideshowType != RANDOM_PHOTO)) {

    slideshowType = SLIDE_SHOW;

  }



  if (slideshowType == RANDOM_PHOTO) {

    randomSlides = true;

  }



  if (typeof(slideshowContainerId) == "undefined") {

    return false;

  } else if (typeof(slideshowContainerId) == "string") {

    slideshowContainer = YD.get(slideshowContainerId);

  }



  if (!slideshowContainer) {

    return false;

  }



  if (typeof(slideshowUrl) == "undefined" || typeof(slideshowUrl) != "string") {

    return false;

  } else {

    slideshowUrl =  /(?:http:\/\/[^\/]+)?(\/\S+)/.exec(slideshowUrl)[1];

  }



  if (/\/gallery\/[0-9]+/.test(slideshowUrl)) {

    slideSourceIsGallery = true;

  } else {

    slideSourceIsGallery = false;

  }



  if (typeof(slideHeight) == "undefined" || isNaN(slideHeight)) {

    slideHeight = "600";

  }



  if (typeof(slideWidth) == "undefined" || isNaN(slideWidth)) {

    slideWidth = "800";

  }



  if (typeof(photoHeight) == "undefined" || isNaN(photoHeight)) {

    photoHeight = slideHeight;

  }



  if (typeof(photoWidth) == "undefined" || isNaN(photoWidth)) {

    photoWidth = slideWidth;

  }



  if (typeof(slideDuration) == "undefined" || isNaN(slideDuration)) {

    slideDuration = 3;

  }



  if (typeof(firstSlideUrl) == "undefined" || typeof(firstSlideUrl) != "string") {

    firstSlideUrl = blank.src;

  }



  if (typeof(showSlideTransition) == "undefined" || typeof(showSlideTransition) != "boolean") {

    showSlideTransition = true;

  }

   

  if (typeof(resizeToPhoto) == "undefined" || typeof(resizeToPhoto) != "boolean") {

    resizeToPhoto = true;

  }



  if (typeof(quickStart) == "undefined" || typeof(quickStart) != "boolean") {

    quickStart = true;

  }



  if (typeof(randomSlides) == "undefined" || typeof(randomSlides) != "boolean") {

    randomSlides = false;

  }



  if (typeof(slideControls) == "undefined" || typeof(slideControls) != "boolean") {

    slideControls = false;

  }



  if (typeof(slideCaptions) == "undefined" || typeof(slideCaptions) != "boolean") {

    slideCaptions = false;

  }



  if (typeof(slidesClickable) == "undefined" || typeof(slidesClickable) != "boolean") {

    slidesClickable = false;

  }



  return true;

}





function loadSlideshow() {

  if (!PrepSlideEnvironment()) {

    return false;

  }



  slideshowContainer.innerHTML = '<img src="http://www.smugmug.com/img/spacer.gif" alt="" id="ssSlide" height="' + slideHeight + '" width="' + slideWidth + '" style="opacity: .99; background-image: url(' + firstSlideUrl + '); background-repeat: no-repeat; background-position: center;" />';



  if (slideCaptions) {

    slideshowContainer.innerHTML += '<div id="ssCaption"></div>';

  }



  if (slideControls) {

    slideshowContainer.innerHTML += '<div id="ssControl"><a title="Previous Slide" id="ssPrev" class="ssBtn" href="javascript: void(0);" onclick="prevSlide();"><img src="/img/spacer.gif" border="0" /></a><a title="Next Slide" id="ssNext" class="ssBtn" href="javascript: void(0);" onclick="nextSlide();"><img src="/img/spacer.gif" border="0" /></a><a title="Pause Slideshow" id="ssPause" class="ssBtn" href="javascript: void(0);" onclick="pauseSlideshow();"><img src="/img/spacer.gif" border="0" /></a><a title="Resume Slideshow" id="ssPlay" class="ssBtn" href="javascript: void(0);" onclick="resumeSlideshow();"><img src="/img/spacer.gif" border="0" /></a></div>';

  }



  sSlide = YD.get('ssSlide');

  sCaption = YD.get('ssCaption');



  if (slidesClickable) {

    sSlide.style.cursor = 'pointer';

  

    if (firstSlideUrl != blank.src) {

      ssAddSlideClick(slideshowUrl);

    }

  }



  ssSlides = [];

  ssSlideTotal = 0;

  ssSlideTimer = 0;

  ssOldSlide = 0;

  ssFadeTimer = 100;

  ssFade = "out";  



  if (slideSourceIsGallery) {

    ajax_query(slideshowHandler, '/photos/sspopup.mg?AlbumID=' + /\/gallery\/([0-9]+)/.exec(slideshowUrl)[1], null, true);

  } else {

    var postArray = [];

    postArray['TemplateID'] = '8';

    postArray['origin'] = slideshowUrl;

    ajax_query(slideshowHandler, '/homepage/templatechange.mg', postArray, true);

  }

}





function slideshowHandler(response)

{

  if (!slideSourceIsGallery) {

    if (tmpCookie && tmpCookie != "") {

      setCookie('Template', tmpCookie, 30, '/', /(?:http[s]?:\/\/)?(?:\w+\.)?(\S+[^\/])/.exec(location.href)[1]);

    } else {

      deleteCookie("Template", "/", /(?:http[s]?:\/\/)?(?:\w+\.)?(\S+[^\/])/.exec(location.href)[1]);

    }

  }



  var re = /imageID\[\d+\] = "\d+";/g;

  var re2 = /width\[\d+\] = "\d+";/g;

  var re3 = /height\[\d+\] = "\d+";/g;

  var re4 = /caption\[\d+\] = ".*";/g;



  s = response.match(re); 

  w = response.match(re2);

  h = response.match(re3);

  c = response.match(re4);



  var oSlide;



  for (i = 0; i < s.length; i++) {

    oSlide = {};



    temp = s[i].split(/"/);

    oSlide.ImageId = temp[1];

    oSlide.File = 'http://upload.smugmug.com/photos/toolthumbs.mg?ImageID=' + temp[1] + '&tool=slideshowXL&winHeight=' + photoHeight + '&winWidth=' + photoWidth;

    oSlide.Gallery = slideshowUrl + '/1/' + oSlide.ImageId;



    temp = h[i].split(/"/);

    oSlide.Height = temp[1];



    temp = w[i].split(/"/);

    oSlide.Width = temp[1];



    temp = c[i].split(/"/);

    oSlide.Caption = temp[1];



    oSlide.Loaded = false;

 

    if ((oSlide.Width > photoWidth) || (oSlide.Height > photoHeight)) {

      if (oSlide.Width >= oSlide.Height) {

         oSlide.Height = Math.round((oSlide.Height / oSlide.Width) * photoWidth);

         oSlide.Width = photoWidth;

      } else {

        oSlide.Width = Math.round((oSlide.Width / oSlide.Height) * photoHeight);

        oSlide.Height = photoHeight;

      }

    }



    ssSlideTotal = ssSlides.push(oSlide);

  }



  ssSlideTotal -= 1;



  if (randomSlides) {

    ssSlides.shift();

    ssSlides.shuffle();

    ssSlides.unshift(0);

  }



  if (quickStart) {

    ssSlideTimer = (slideDuration * 1000);

  }



  ssPrepSlide(1);

  window.setTimeout("ssPrepSlide(2);", 0);

  window.setTimeout("ssPrepSlide(ssSlideTotal);", 0);



  if (slideshowType == SLIDE_SHOW) {

    ssPlaySlideshow();

  } else {

    ssSlideSwap(1);

  }

}





function ssPauseSlideshow()

{

  window.clearTimeout(ssTimerId);

  ssTimerId = null;

}





function ssResumeSlideshow()

{

  if (!ssTimerId) {

    ssTimerId = window.setTimeout("ssPlaySlideshow()", 10);

  }

}





function ssPrepSlide(prep)

{

  if (ssSlides[prep].Loaded == false) {

    ssSlides[prep].Image = new Image();

    ssSlides[prep].Image.src = ssSlides[prep].File;

    ssSlides[prep].Loaded = true;

  }   

}





function ssMoveSlide(i) {

  ssSlideTimer = 0;

  ssFadeTimer = 100;

  ssTransition(ssFadeTimer);

  ssFade = "out";

  ssSlideSwap(i);                       

}





function ssPlaySlideshow()

{

  if (ssSlideTimer >= (slideDuration * 1000))

  {                

    if (ssFade == 'out') {

      ssTransition(ssFadeTimer -= 10);

    }

 

    if (ssFadeTimer == 0) {

      ssSlideSwap(1);

      ssFade = 'in';

    }

 

    if (ssFade == 'in') {

      ssTransition(ssFadeTimer += 10);

    }

 

    if (ssFadeTimer == 100) {

      ssSlideTimer = 0;

      ssFade = 'out';

    }

  } else {

    ssSlideTimer += 10;

  }

 

  ssTimerId = window.setTimeout("ssPlaySlideshow()", 10);

}





function ssTransition(opacity)

{

  if (showSlideTransition)

  {

    if (opacity != 100) {

      YD.setStyle(sSlide, 'opacity', (opacity / 100));

    } else {

      YD.setStyle(sSlide, 'opacity', '.99'); // to prevent flashing in mozilla browsers

    }

 

    // only affects Win IE

    YD.setStyle(sSlide, 'filter', 'alpha(opacity=' + opacity + ')');



    if (sCaption) {

      YD.setStyle(sCaption, 'opacity', sSlide.style.opacity);

      YD.setStyle(sCaption, 'filter', sSlide.style.filter);

    }

  }

}





function ssSlideSwap(i)

{

  var newSlide = ssOldSlide + i;

 

  if (newSlide > ssSlideTotal)

    newSlide = 1;

 

  if (newSlide < 1)

    newSlide = ssSlideTotal;

 

  if (ssSlides[newSlide].Loaded != false)

  {

    document.images['ssSlide'].src = blank.src;

    YD.setStyle(sSlide, 'backgroundImage', 'url(' + ssSlides[newSlide].File + ')');



    if (resizeToPhoto)

    {

      document.images['ssSlide'].height = ssSlides[newSlide].Height;

      document.images['ssSlide'].width = ssSlides[newSlide].Width;

    }



    if (slidesClickable) {

      ssAddSlideClick(ssSlides[newSlide].Gallery);

    }

    

    if (slideCaptions) {

      YD.get('ssCaption').innerHTML = ssSlides[newSlide].Caption;

    }



    ssPrepSlide(newSlide < ssSlideTotal ? newSlide + i : 1);

    ssOldSlide = newSlide;

  } else {

    ssPrepSlide(newSlide);

    ssSlideSwap(i);

  }

}





function ssAddSlideClick(sUrl) {

  YE.purgeElement(sSlide, false, 'click');

  YE.addListener(sSlide, 'click', function() {

	location.href = sUrl;

  })

}





Array.prototype.shuffle = function()

{

  var len = this.length;

  var rand, temp, i;



  for (i = 0; i < len; i++)

  {

    rand = Math.floor(Math.random()*len);

    temp = this[i];

    this[i] = this[rand];

    this[rand] = temp;

  }

}





function pauseSlideshow()

{

  YD.setStyle('ssPause', 'display', 'none');

  YD.setStyle('ssPlay', 'display', 'inline');

  ssPauseSlideshow();

}





function resumeSlideshow()

{

  YD.setStyle('ssPause', 'display', 'inline');

  YD.setStyle('ssPlay', 'display', 'none');

  ssResumeSlideshow();

}





function prevSlide()

{

  pauseSlideshow();

  ssMoveSlide(-1);

}





function nextSlide()

{

  pauseSlideshow();

  ssMoveSlide(1);

}





function getCookie(name) {

  var start = document.cookie.indexOf(name + "=");

  var len = start + name.length + 1;

  

  if ((!start) && (name != document.cookie.substring(0, name.length))) {

    return null;

  }



  if (start == -1) {

    return null;

  }



  var end = document.cookie.indexOf(";", len);



  if (end == -1) {

    end = document.cookie.length;

  }



  return unescape(document.cookie.substring(len, end));

}





function setCookie(name, value, expires, path, domain, secure) {

  var today = new Date();

  today.setTime( today.getTime() );



  if (expires) {

    expires = expires * 1000 * 60 * 60 * 24;

  }



  var expires_date = new Date(today.getTime() + (expires));



  document.cookie = name + '='+escape(value) +

    ((expires) ? ';expires=' + expires_date.toGMTString() : '') +

    ((path) ? ';path=' + path : '') +

    ((domain) ? ';domain=' + domain : '') +

    ((secure) ? ';secure' : '');

}





function deleteCookie(name, path, domain) {

  if (getCookie(name)) {

    document.cookie = name + "=" + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";

  }

}
var vanityTable = 
 {
     about : "http://bernskioldphotography.com/gallery/3944161",
     guestbook: "http://bernskioldphotography.com/gallery/3954346",
     seagulls: "http://jfriend.smugmug.com/gallery/386570"
 };
 function IsHomePage()
 {
    return(YD.hasClass(document.body, 'homepage'));
 }
 
 function CheckRedirects()
 {
     if (IsHomePage())    // 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
         }
     }
 }

/*
--------------------------------------------------
	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;
}