// Called on page loads (from code placed in the footer)
function OnLoadHandler()
{
    //Add featured galleries in the reverse order they should appear
    addFeatured('Big Doggies', '', 'keyword/big doggie', 'photos/140638863-Ti.jpg'); 
    addFeatured('Faerieworlds 2009', '', '/Festivals/840073', '/photos/619425498_vPgiv-Ti.jpg'); 
    //addFeatured('Pacific Performing Arts Center 2007 Chinese New Year in Redmond: Spirit of Peacock by Yin Li of Huayin Performing Arts Group', '', 'gallery/2430641', 'photos/127699030-Ti.jpg'); 
    addFeatured('Favorite Photos', '', 'keyword/favorite', 'photos/283142254_AGSuA-Ti.jpg'); 
}

//Make the smugmug link in my footer add my referral code
function AddReferralCode() {
    var links = this.getElementsByTagName("A");
    if (links && (links.length != 0)) {
        var smugLink = links.item(0);
        smugLink.href = "http://www.smugmug.com/?referrer=T6qGq24hYPlLP";
    }
}
YE.onAvailable('footer', AddReferralCode);

//Customize the right click protect warning
rightClickWarning = "All photos are property of Creative Flashes Photography. All rights reserved. Unauthorized use is prohibited. I won't steal your car, please do not steal my photograph! Contact me instead, I am very reasonable.";

//Make the popout window drop out below the image, not in the right corner
//SM.PhotoBar.config.position = 'bottom';
//Delay the popout window slightly on mouseovers
photoBarDelay = 1;

//Tweak the stretchy image size algorithm to account for my header somewhat
SM.SmugMug.config.alterScreenHeight = -50;

//Disable the image tooltips (unless logged in)
function delHover()
{
    if (!YD.hasClass(document.body, 'loggedIn'))
    {
        oLst = YD.getElementsBy(function(el) {return (YD.hasClass(el,'imgBorder') || YD.hasClass(el,'imgBorderOn'))},'img');
        for (i=0; i < oLst.length ; i++) {
            if (oLst[i].title && oLst[i].title != '') oLst[i].title = '';
            if (oLst[i].alt && oLst[i].alt != '') oLst[i].alt = '';
        }
    }
}
YE.onContentReady('bodyWrapper', function() {if (!YD.hasClass(document.body, 'smugmug_ajax')) delHover()});
onPhotoShow.subscribe(function(){YE.onAvailable('mainImage', delHover)});

//Make the Guestbook page say "guestbook comments" instead of "gallery comments"
function ModifyText ()
{
  if (YD.hasClass(document.body, "gallery_2507057"))    //Guestbook gallery 
  {
    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 to add a featured gallery
function addFeatured(text, description, href, thumbUrl)
{
  if (YD.hasClass(document.body, "homepage")) 
  {
    divTag = document.getElementById("featuredBox");
    if (divTag)
    {
      divTags = divTag.getElementsByTagName("div");

      for (i=0; i<divTags.length; i++)
      {
        if (divTags[i].className == "boxBottom")
        {
          miniBox = document.createElement("div");
          miniBox.className = "miniBox";

          photoBox = document.createElement("div");
          photoBox.className = "photo";
          miniBox.appendChild(photoBox);

          photoLink = document.createElement("a");
          photoLink.setAttribute("href", href);
          photoBox.appendChild(photoLink);

          photoImg = document.createElement("img");
          photoImg.setAttribute("border", "0");
          photoImg.setAttribute("alt", text);
          photoImg.setAttribute("title", text);
          photoImg.src = thumbUrl;
          photoImg.className = "imgBorder";
          photoLink.appendChild(photoImg);

          albumTitle = document.createElement("p");
          albumTitle.className = "albumTitle";
          miniBox.appendChild(albumTitle);

          albumLink = document.createElement("a");
          albumLink.className = "nav";
          albumLink.setAttribute("href", href);
          albumTitle.appendChild(albumLink);

          albumLinkText = document.createTextNode(text);
          albumLink.appendChild(albumLinkText);
          
          albumDescription = document.createElement("p");
          albumDescription.className = "description";
          miniBox.appendChild(albumDescription);

          albumDescriptionText = document.createTextNode(description);
          albumDescription .appendChild(albumDescriptionText);

          spacerDiv = document.createElement("div");
          spacerDiv.className = "spacer";
          miniBox.appendChild(spacerDiv);

          divTags[i].insertBefore(miniBox, divTags[i].childNodes[1]);

          break;
        }
      }
    }
  }
}
