rightClickWarning = "All photos are property of Agape Photo Studio.  All rights reserved. Unauthorized use is prohibited.";

function hasPath(sPath)
{
re = new RegExp("\/" + sPath + "(\/|$)");
return re.test(window.location)
}

if (hasPath("galleries"))
YD.addClass(document.body, "galleries");

YE.onContentReady("breadCrumbTrail", RemoveTopOfBreadCrumb);
function RemoveTopOfBreadCrumb() 
{
    var str = this.innerHTML;
    str = str.replace(/\n/g, " ");    // get rid of linebreaks which cause problems for regular expressions in javascript
    this.innerHTML = str.replace(/^\s*<a .*?a>.*?</i, "<");
}


/*========================================*/
/*==   Disable PhotoRank on Mouseover    ==*/
/*========================================*/

displaySmugPopular = false;

/*========================================*/
/*==   Paypal shopping functionality    ==*/
/*========================================*/
function setPaypalForm(form) {
/*
 urlToImage = webServer + "/gallery/" + AlbumID + "_" + AlbumKey + "/1/" + ImageID + "_" + ImageKey + "/Large" + "   " + photoInfo[ImageID]['fileName']; 
*/
urlToImage = webServer + "/gallery/" + AlbumID + "_" + AlbumKey + "/1/" + ImageID + "_" + ImageKey + " - " + photoInfo[ImageID]['fileName']; 

 i = form.photoselection.selectedIndex

 /*document.PhotoOrderFormspt.paypalfilename.value=mainPhotoFileName;*/

 sPhotoPrice = form.photoselection.options[i].value;
 form.item_name.value = form.photoselection.options[i].text.substr(0, form.photoselection.options[i].text.indexOf(" ["));
 form.amount.value = sPhotoPrice;
 form.os0.value = "/gallery/" + AlbumID + "_" + AlbumKey + "/1/" + ImageID + "_" + ImageKey;
 form.os1.value = photoInfo[ImageID]['fileName'];
}



/*===================================================================================*/
/*==   code to insert a download button for any gallery that has originals enabled ==*/
/*===================================================================================*/

function IsSmugmugView()
{
    return(YD.hasClass(document.body, "smugmug"));
}

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 (IsSmugmugView() && (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 Original 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";
}


/*===========================================*/
/*==   code to add items to the Buy button ==*/
/*===========================================*/


YE.onDOMReady(AddItemsToBuyButton);

function AddItemsToBuyButton()
{
    var buyButton = YAHOO.widget.Button.getButton("buyButton");
    if (buyButton)
    {
        var newBuyItem = { text: "View Catalog", url: "http://www.smugmug.com/prints/catalog/", target: "_blank"};
        buyButton.getMenu().addItem(newBuyItem);
    }
}



/*===========================================================================*/
/*==   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]);
    }
}
*/

// -----------------------------------------------------------
// Code to add descriptions to categories and/or sub-categories
// -----------------------------------------------------------

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);
            }
        }
    }
}

/* Category descriptions */
function addCategoryDescription() 
{
    var categoryDescription = {
        // list "categoryname" : "category title",
        // or "categoryname.subcategoryname" : "subcategory title",
        // Examples:
        // "Kenya"  : "Our vacation to Kenya",
        // "Kenya.Highlights" : "The highlights galleries from our vacation to Kenya",
        "Kennedale Speedway Park" : "Pictures from Kennedale Speedway Park, Kennedale, Texas.<br><br><center><b><u>Pictures from previous race dates will be posted shortly!</u></b></center>",
        "Kennedale Speedway Park.09-19-2009" : "Full Race Program + Mini Sprints + Trailer Race",
        "Kennedale Speedway Park.09-05-2009" : "Full Race Program + Kid's Rides + Mechanic's Races + Powder Puff",
        "Kennedale Speedway Park.08-29-2009" : "Full Race Program + Demolition Derby",
        "Kennedale Speedway Park.08-28-2009" : "Special Race Program + Sprints + Young Guns",
        "Kennedale Speedway Park.08-22-2009" : "Full Race Program + Powder Puff",
        "Kennedale Speedway Park.08-15-2009" : "Full Race Program + Sprints",
        "Kennedale Speedway Park.08-08-2009" : "Full Race Program + Wing Modifieds",
        "Kennedale Speedway Park.07-25-2009" : "Full Race Program + Trailer Race",
        "Kennedale Speedway Park.07-18-2009" : "Full Race Program + Demolition Derby",
        "category2"  : "This is another test.",
        "category3"  : "Final test"
    };
    
    var re, matches, i;        // various local variables

    // now fix it so that it works automatically even if the category or sub-category name has spaces in it
    // we replace those spaces with underscores (which is what the classname does) and add those to our object so we can match those too
    for (i in categoryDescription) 
    {
        var newName = i.replace(/ /g, "_");
        categoryDescription[newName] = categoryDescription[i];    // add a property to the object that has only underscores in the name
    }
    // on the homepage, we want to check for category names and add a description if a match found
    // on a category page, we want to check to see if the category that the page is needs a description under the breadcrumb
    //      and, we need to see if any of the sub-category items on the page need us to add a description under the name
    // on a sub-category page, we want to check to see if the sub-category that the page is needs a description under the breadcrumb
    if (YD.hasClass(document.body, "category")) 
    {
        // fetch the category name
        re = /category_(\S+)/i;
        matches = re.exec(document.body.className);
        if (matches && (matches.length > 1)) 
        {
            var categoryName = matches[1];
            // now see if we have a subcategory too
            if (YD.hasClass(document.body, "subcategory")) 
            {
                re = /subcategory_(\S+)/i;
                matches = re.exec(document.body.className);
                if (matches && (matches.length > 1)) 
                {
                    var subcatName = matches[1];
                    // category and subcategory so we are on a subcategory page showing a list of galleries in this subcategory
                    // we need to just add a subcategory title to this page if the category-subcategory matches
                    var fullName = categoryName + "." + subcatName;
                    if (categoryDescription[fullName])
                    {
                        addCategoryTitleToBreadcrumb(categoryDescription[fullName]);
                    }
                }
            }
            // here we're on a category page
            // we need to add a category description for the category page
            // and potentially add subcategory descriptions to the subcategory names displayed on this page
            else 
            {
                if (categoryDescription[categoryName])
                {
                    addCategoryTitleToBreadcrumb(categoryDescription[categoryName]);
                }
                // now we need to build a temporary subcategoryDescription object that has only the subcategory names in it that are in this category
                var subcatDescriptions = {};
                re = new RegExp("^" + categoryName + "\\.(.+)$", "i");
                for (i in categoryDescription)
                {
                    matches = re.exec(i);
                    if (matches && (matches.length > 1))
                    {
                        subcatDescriptions[matches[1]] = categoryDescription[i];
                    }
                }
                addCategoryTitleToThumbs(subcatDescriptions, "subcategoriesBox");
            }
        }
    }

    // then see if we're on the homepage
    if (YD.hasClass(document.body, "homepage")) 
    {
        addCategoryTitleToThumbs(categoryDescription, "categoriesBox");
    }
}

YE.onDOMReady(addCategoryDescription);

// ------------------------------------------------------------------
// End of code to add descriptions to categories and/or sub-categories
// -----------------------------------------------------------------


// ------------------------------------------------------------------
// Replace Gallery or Sub-Categories with different words
// -----------------------------------------------------------------

/*
function RemoveGalleryWord()
{
    this.innerHTML = this.innerHTML.replace(/ Galleries$/, "");
    this.innerHTML = this.innerHTML.replace(/ Sub-Categories$/, "");
}

YE.onAvailable("subCatGalleryTitle", RemoveGalleryWord);
YE.onAvailable("galleryTitle", RemoveGalleryWord);
*/



// ------------------------------------------------------------------
// Turn off pop-ups on mouse hover
// -----------------------------------------------------------------
function delHover() {
    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)});






// ------------------------------------------------------------------
//====Hide Categories====
// -----------------------------------------------------------------

function delCategory() {
  re = /\/(abc)$/;

  var oList = YD.getElementsByClassName('miniBox', 'div', this);

  for (i = 0; i < oList.length; i++) {
    if (re.test(oList[i].getElementsByTagName('a')[0].href))
      oList[i].parentNode.removeChild(oList[i]);
  }
}
YE.onContentReady('categoriesBox', delCategory);



// ------------------------------------------------------------------
// Use Same Description for Multiple Galleries
// -----------------------------------------------------------------


var dA = new Array(1);
dA[0] = "hi, i'm a javascript description!";





