/* function to hide email address */

function norobotmail(aUser, aDomain) { document.location = "mailto:" + aUser + "@" + aDomain; }

/* function to change some text in the guestbook that nobody uses */
function ModifyText ()
{
  if (YD.hasClass(document.body, "gallery_4733609")) 
  {
    var objElement = YD.get("comment")
    if (objElement != null) 
    {
      var str = new String(objElement.innerHTML);
      str = str.replace(/\gallery/gi, 'guestbook');
      objElement.innerHTML = str;
    }
  }
}

/* changing some titles on the main page */

YE.onAvailable("comment", ModifyText);
YE.onAvailable('featuredTitle', function() {this.innerHTML = 'Newest Collections'});
YE.onAvailable('categoryTitle', function() {this.innerHTML = 'Photo Categories'});
YE.onContentReady('popularTitle', function() {this.innerHTML = this.innerHTML.replace('Most Popular Photos', 'Most Popular Photos - Vote for your favorites!')});

/* Following code puts subcategories below galleries */

function swapBoxes() {
     bodyClass = document.getElementsByTagName("body")[0].className;
     if (bodyClass.indexOf("category") != -1)
     {
        box1 = document.getElementById("subcategoriesBox");
        box2 = document.getElementById("galleriesBox");

        if (box1 && box2)
        {
           swap = box1.innerHTML;
           box1.innerHTML = box2.innerHTML;
           box2.innerHTML = swap;
           box1.innerHTML = box1.innerHTML.replace(/galleries/, '')
           box2.innerHTML = box2.innerHTML.replace(/galleries/, '')

        }
     }
}

/* Following code adds a description to categories */

function addCategoryDescription(){
    var categoryDescription = {
        "The Laboratory": "...Our Experiments in Photography",
        "Video": "...Taken with our old PnS Camera",
        "MyPhotos": "This does not."
    };
    
    if ((YAHOO.util.Dom.hasClass(document.body, "category")) && (!YAHOO.util.Dom.hasClass(document.body, "subcategory"))) {
    
        re = /category_(\S+)/i;
        if (re.exec(document.body.className)) {
            foundCat = RegExp.$1.replace('_', ' ');
            
            breadCrumb = document.getElementById("breadcrumb");
            if (breadCrumb) {
                divTag = document.createElement("div");
                divTag.className = "categoryDescription";
                if (categoryDescription[foundCat] != undefined) {
                    divTag.appendChild(document.createTextNode(categoryDescription[foundCat]));
                    breadCrumb.parentNode.insertBefore(divTag, breadCrumb.nextSibling);
                }
            }
        }
    }
    if (YAHOO.util.Dom.hasClass(document.body, "homepage")) {
        re = /\>([\w\- ]+)<\/a>/i;
        
        divTag = document.getElementById("categoriesBox");
        if (divTag) {
            divTags = YAHOO.util.Dom.getElementsByClassName("albumTitle", "p", divTag);
            
            for (i = 0; i < divTags.length; i++) {
                re.exec(divTags[i].innerHTML);
                if (categoryDescription[RegExp.$1] != undefined) {
                    pTag = document.createElement("p");
                    pTag.className = "categoryDescription";
                    pTag.appendChild(document.createTextNode(categoryDescription[RegExp.$1]));
                    divTags[i].parentNode.insertBefore(pTag, divTags[i].nextSibling);
                }
            }
        }
    }
}
addEvent(window, "load", addCategoryDescription);