function hasPath(sPath)
{
re = new RegExp("\/" + sPath + "(\/|$)");
return re.test(window.location)
}

if (hasPath("galleries"))
YD.addClass(document.body, "galleries");

function ModifyText () 
{
  if (YD.hasClass(document.body, "gallery_7482942")) 
  {
    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);

YE.onDOMReady(InsertStylePicker);

function SetNewGalleryStyle(type, args, menuItem)
{
    // this click handler is called as a method of the menuItem that was clicked on
    var styleValue = this.value;        // get the value of the menu item
    
    // because we are calling styleBarChange which is expecting to be passed a comboBox object,
    // we have to create a fake comboBox object that has the new value in it so that function
    // can fetch the value from our object
    var fakeComboItem = {value: styleValue};
    var fakeComboBox = {selectedIndex: 0, options: [fakeComboItem]};
    
    // call the function that changes the style just like the Smugmug comboBox would have
    styleBarChange("Template", fakeComboBox);
}

function InsertStylePicker()
{
    if (!YD.get("stylebar"))
    {
        return;        // if there wasn't supposed to be a stylebar in this page, the don't insert our version
    }
    // declare the data for our style picker
    // you can remove any of these lines that you don't want to offer your viewers
    // just make sure the last line does not have a comma after it and all others do have a comma (IE will choke if you don't do it right)
    var stylePickerData = [
        {text: "SmugMug", value: "3", onclick: { fn: SetNewGalleryStyle }},
        {text: "Traditional", value: "4", onclick: { fn: SetNewGalleryStyle }},
        {text: "All Thumbs", value: "7", onclick: { fn: SetNewGalleryStyle }},
        {text: "Slideshow", value: "8", onclick: { fn: SetNewGalleryStyle }},
        {text: "Journal", value: "9", onclick: { fn: SetNewGalleryStyle }},
        {text: "Filmstrip", value: "11", onclick: { fn: SetNewGalleryStyle }},
        {text: "Critique", value: "12", onclick: { fn: SetNewGalleryStyle }}
    ];
    
    // now put a checkmark by the currently selected style which we get from the galleryStyle variable
    if (galleryStyle)
    {
        var tempStyle = galleryStyle.toLowerCase();
        tempStyle = tempStyle.replace("_", " ");
        for (var i in stylePickerData)
        {
            if (stylePickerData[i].text.toLowerCase() == tempStyle)
            {
                stylePickerData[i].checked = true;
                break;
            }
        }
    }
    
    // declare the style menu button
    // You can change the button text, by changing the quoted string for the label line below
    // You can put it a different place in your page by changing the container object to a different DIV object in the page
    var styleMenu = new YAHOO.widget.Button({
        id: "customStylebarMenu",
        name: "customStylebarMenu",
        type: "menu",
        menu: stylePickerData,
        label: "Style",
        className: "sm-button sm-button-small themesButton glyphButton menuButton",
        container: "altViews"
    });
    
    
}

//
// most recent
//
function showRecent(days)
{
  endDate = new Date();
  oneDay = 1000*60*60*24;
  startDate = new Date(endDate.getTime() - (parseInt(days) * oneDay));
  sUrl = "/date/";
  sUrl += startDate.getFullYear() + "-" + padDate(startDate.getMonth() + 1) + "-" + padDate(startDate.getDate());
  sUrl += "/";
  sUrl += endDate.getFullYear() + "-" + padDate(endDate.getMonth() + 1) + "-" + padDate(endDate.getDate());
   window.location = sUrl;
}

function padDate(datePart)
{
  if (datePart.toString().length != 1)
    return datePart
  return "0" + datePart;
}

// end Most Recent

// script to replace a user's name in the breadcrumb with "Home"
YE.onContentReady("breadCrumbTrail", ReplaceTopOfBreadcrumbWithHome);

function ReplaceTopOfBreadcrumbWithHome()
{
    var str = this.innerHTML.replace(/\n/g, " ");
    this.innerHTML = str.replace(/\>[^\<]+<\/a>/i, ">Home</a>");
}

// function to make breadcrumb navigate to galleries instead of home page

function AdjustBreadcrumb()
{
    var str = this.innerHTML;
    str = str.replace(/\n/g, " ");
    str = str.replace(/^\s*<a .*?<\/a>/i, '<a href="/galleries" class="nav">Gallery Categories</a>');
    this.innerHTML = str;
}

YE.onContentReady("breadCrumbTrail", AdjustBreadcrumb);