rightClickWarning = "All photos Copyright Apex One Photo"; // ------------------------------------------------------------------------
// Code to insert a download button 
// 
// Works for any gallery that has originals enabled
// And right-click protection off
// And gallery is in smugmug or smugmug small view
// ------------------------------------------------------------------------

function IsAnySmugmugView()
{
    return(YD.hasClass(document.body, "smugmug") || YD.hasClass(document.body, "smugmug_small"));
}

function IsGalleryPage()
{
	return(YD.hasClass(document.body, "galleryPage"));
}

onPhotoShow.subscribe(ProcessDownloadButton);

function ProcessDownloadButton()
{
	// set onlyInGalleries to true if you only want a download button in gallery views
	// set onlyInGalleries to false if you want a download button in other views too like (search, keywords, date, etc...)
	var onlyInGalleries = false;
	if (IsAnySmugmugView() && (IsGalleryPage() || !onlyInGalleries))
	{
		if (photoInfo[ImageID].albumOriginals && !photoInfo[ImageID]['protected'] && (photoInfo[ImageID].Format !== "MP4"))
		{
			var downloadParent = "cartButtonsWrapper";
			if (!document.getElementById("cartButtonsWrapper"))
			{
				downloadParent = "altViews";
			}
			InsertDownloadButton(downloadParent);
		}
		else
		{
			// disable the button
			var downloadButton = YAHOO.widget.Button.getButton("downloadButtonId");
			if (downloadButton)
			{
				downloadButton.set("disabled", true);
			}
		}
	}
}

function InsertDownloadButton(parentId)
{
	// now add the download button
	var parentDiv = document.getElementById(parentId);
	var downloadButton = document.getElementById("downloadButtonId");
	if (downloadButton)
	{
		// make sure it is enabled
		YAHOO.widget.Button.getButton("downloadButtonId").set("disabled", false);
	}
	else if (parentDiv)
	{
		var downloadButtonInfo =
		{
			id: "downloadButtonId",
			label: "Download Image...",
			container: parentDiv,
			type: "button",
			className: "sm-button sm-button-small themesButton glyphButton",
			onclick: { fn: InitiateDownloadImage }
		};
		
		var dButtonObj = new YAHOO.widget.Button(downloadButtonInfo);
	}
}

function InitiateDownloadImage()
{
	// construct the download URL
	window.location = "/photos/" + ImageID + "_" + ImageKey + "-D.jpg";
}












function RemoveGalleryWord()
{
   this.innerHTML = this.innerHTML.replace(/ Galleries$| Sub-Categories$/, "");
}

YE.onAvailable("subCatGalleryTitle", RemoveGalleryWord);
YE.onAvailable("galleryTitle", RemoveGalleryWord);

function hasPath(sPath)
{
re = new RegExp("\/" + sPath + "(\/|$)");
return re.test(window.location)
}

if (hasPath("galleries"))
YD.addClass(document.body, "galleries");

// This is a script to combine the categories with the gallery listing to have just one continuous listing of thumbs
YE.onContentReady("subcategoriesBox", CombineCategoriesWithGalleries);

function IsArrayEmpty(testVal)
{
   return(!testVal || (testVal.length == 0));
}

function CombineCategoriesWithGalleries()
{
   // get miniBoxes in the subcategoriesBox object
   var miniBoxes = YD.getElementsByClassName("miniBox", "div", this);
   // get target galleriesBox object
   var galleriesObj = document.getElementById("galleriesBox");
   var galleryMiniBoxes = new Array;

   // now find the right miniBox in the galleriesBox in order to insert the sub-categories
   if (galleriesObj)
   {
       galleryMiniBoxes = YD.getElementsByClassName("miniBox", "div", galleriesObj);
   }

   // if we don't have everything we need, then return without doing anything
   if (!galleriesObj || IsArrayEmpty(miniBoxes) || IsArrayEmpty(galleryMiniBoxes) || (window.location.hash == "#stop"))
   {
       this.style.display = "block";
       return;
   }

   // move all the sub-categories over to the gallery listing
   for (var i in miniBoxes)
   {
       miniBoxes[i].parentNode.removeChild(miniBoxes[i]);
       galleryMiniBoxes[0].parentNode.insertBefore(miniBoxes[i], galleryMiniBoxes[0]);
   }
}



function addCategoryTitleToBreadcrumb(description)
{
  var breadCrumb = YD.get("breadcrumb");
  if (breadCrumb)
  {
      var divTag = document.createElement("div");
      divTag.className = "categoryDescription";
      divTag.innerHTML = description;
      breadCrumb.parentNode.insertBefore(divTag, breadCrumb.nextSibling);
  }
}

function addCategoryTitleToThumbs(descriptionObject, boxObjectName)
{
  var re = /\>([^\<]+)<\/a>/i;    // pattern to find the category name between the <a> and </a> tags
  var divTag = YD.get(boxObjectName);
  if (divTag)
  {
      var divTags = YD.getElementsByClassName("albumTitle", "p", divTag);
      for (var i = 0; i < divTags.length; i++)
      {
          var matches = re.exec(divTags[i].innerHTML);    // get just the category name
          // if we found a category name and the category name exists in our categoryDescription object, then add the description
          if (matches && (matches.length > 1) && descriptionObject[matches[1]] != undefined)
          {
              var pTag = document.createElement("p");
              pTag.className = "categoryDescription";
              pTag.innerHTML = descriptionObject[matches[1]];
              divTags[i].parentNode.insertBefore(pTag, divTags[i].nextSibling);
          }
      }
  }
}

function AddReferralCode() {
var links = this.getElementsByTagName("A");
if (links && (links.length != 0)) {
var smugLink = links.item(0);
smugLink.href = "http://www.smugmug.com/?referrer=aJIkhmVbGBy5A";
}
}
YE.onAvailable('footer', AddReferralCode);

// Script to change the breadcrumb link to your homepage to point to your galleries page instead of your slideshow
// It also changes that link to say "Galleries" instead of your user name

function AdjustBreadcrumb()
{
    // there are something like six different forms of the breadcrumb including search and keyword and date and communities, categories and galleries that we have to make this work for
    var tags = YD.getElementsByClassName("nav", "a", this);        // get all the <a> tags with class "nav"
    var filteredTags = new Array;
    // filter out any that aren't at the top level in the breadCrumbTrail (this gets rid of the relatedDate tags)
    for (var i in tags)
    {
        if (tags[i].parentNode == this)
        {
            filteredTags.push(tags[i]);
        }
    }
    if (filteredTags.length == 0)
    {
        return;
    }
    // default to targeting the first filtered tag
    var targetTag = filteredTags[0];
    
    // see if we have a community here
    if (filteredTags.length > 1)
    {
        // if we have a community here, then the user top level is in the 2nd position
        if (filteredTags[0].href.search(/\/community\//) != -1)
        {
            targetTag = filteredTags[1];
        }
    }
    // make sure URL ends with a slash
    var str = targetTag.href;
    if (str.search(/\/$/) == -1)
    {
        str += "/";
    }
    str +="galleries";
    targetTag.href = str;
    targetTag.innerHTML = "Galleries";
}

YE.onContentReady("breadCrumbTrail", AdjustBreadcrumb);

YE.onDOMReady(ContextualizeTitle);
