rightClickWarning = "All photos are property of Ashish Pandey. All rights reserved. Unauthorized use is prohibited.";

/*** Begin AllGalleries Link Style ***/
if (hasPath("AllGalleries"))
  YD.addClass(document.body, "allgalleries");
/*** End AllGalleries Link Style ***/

/*** Change Breadcrumb ***/
YE.onContentReady("breadCrumbTrail", function () {
  this.innerHTML = this.innerHTML.replace(/href="\/"|href="http:\/\/photography.ashish-pragya.com"|href="http:\/\/ashishpandey.smugmug.com"/, 'href="/Galleries"');
  this.innerHTML = this.innerHTML.replace(/Ashish Pandey/, "Galleries");
});

var categoryDescription = {
    "Travel"  : "I love to go places, and when I go places, I have a gallery to show :)",
    "Travel.China 2007" : "A glimpse of seven days we spent travelling China. We started off with Beijing, visiting the Great Wall, Tiananmen Square, Forbidden City, Summer Palace, Temple of Heven, Beihai & Jingshan Park and Lama Temple.<br/>Then we moved our focus to the traditional city of Xian. The high point was the visit to the museum of Terracotta Warriors, but we were pleasently surprized by the beauty of the city itself<br/>Our final stop was Shanghai. It wasnt too impressive after being in Hong Kong for quite some time, but the tall towers still were good enough to visit their top floors. The view at the bund was good and YuYuan Garden presented a slightly different glimpse of chinese architecture",
    "Travel.India 2008" : " A few weeks spent in India during early 2008",
    "Photography": "Miscellenious Photography Galleries"
}; 

// fix the pesky pipes
YE.onAvailable("cobrand_footer", function() {this.innerHTML = this.innerHTML.replace(/\||what are feeds\?/gi, '');});

function AddReferralCode() {
  var links = this.getElementsByTagName("A");
  if (links && (links.length != 0)) {
    var smugLink = links.item(0);
    smugLink.href = "http://www.smugmug.com/?referrer=rygL1hiuicNfs";
  }
}
YE.onAvailable('footer', AddReferralCode);

function ModifyText ()
{
  if (YD.hasClass(document.body, "gallery_6477629"))
  {
    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 ModifyGalleriesText ()
{
  if (YD.hasClass(document.body, "category_Galleries"))
  {
    var objElement = YD.get("galleryTitle")
    if (objElement != null)
    {
      var str = new String(objElement.innerHTML);
      objElement.innerHTML = "Ashish Pandey's Gallery Categories";
    }
  }
}

YE.onAvailable("galleryTitle", ModifyGalleriesText);


/***** Bulk Zoom Thumbnail Hack ****/
/*==============================*/
/*== Bulk Zoom thumbnail v3.3 ==*/
/*==============================*/
var thumbnailArray = new Array();
var thumbnailCount;
var thumbnailItem;
var thumbnailEXIFArray = new Array();
var reqIncrement = 0;

YE.on(window, "load", addBulkThumbnail);

function addBulkThumbnail() {
  if (YD.hasClass(document.body,"galleryPage") && YD.hasClass(document.body,"loggedIn")) {
    if (YD.hasClass(document.body,"traditional") || YD.hasClass(document.body,"allthumbs") ||  YD.hasClass(document.body,"smugmug")) {
      onStartBulk();

      var divTag = YD.get("photoTools");

      YD.get("bulkSave").disabled = true;

      var objSpan = document.createElement("span");
      objSpan.className = "foreground";
      divTag.appendChild(objSpan);

      var objButton = document.createElement("input");
      objButton.type = "checkbox";
      objButton.id = "bulkzoom";
      objSpan.appendChild(objButton);
      YE.on(objButton, "click", toggleBulkZoom);

      var objText = document.createTextNode(' bzt');
      objSpan.appendChild(objText);
    }
  }
}

function toggleBulkZoom() {
  if (YD.get('bulkzoom').checked)
    processThumbnails();
  else
    window.location.reload();
}

function processThumbnails() {
  var re = /\/photos\/(\d+)_(\w+)\-(Ti|Th)/;

  pageWorking('Loading...');

  YD.get("bulkzoom_toolbox").style.display = "";

  var divTag = YD.inDocument("thumbnails") ? YD.get("thumbnails") : YD.get("photos");

  if (divTag) {
    var divTags = YD.getElementsByClassName("photo", "div", divTag);
    for (var i = 0, len = divTags.length; i < len; i++) {
      if (re.test(divTags[i].innerHTML)) {
        re.exec(divTags[i].innerHTML);
        thumbnailEXIFArray.push({"id": RegExp.$1, "key": RegExp.$2});
      }
    }
  }
  getThumbnailEXIF();
}

function maskThumbnails(objThumbnail, j) {
  var re1 = /\/gallery\/\d+_\w+\/\d+\/(\d+)_(\w+)/;
  var re2 = /javascript\:openLB\(([0-9]+),/;
  var re3 = /#(\d+)(_(\w+))?/;

  var divTag = YD.inDocument("thumbnails") ? YD.get("thumbnails") : YD.get("photos");

  if (divTag) {
    divTags = YD.getElementsByClassName("photo", "div", divTag);

    for (var i = 0, len = divTags.length; i < len; i++) {
      if (re1.test(divTags[i].innerHTML))
        re1.exec(divTags[i].innerHTML);
      else
      {
        if (re2.test(divTags[i].innerHTML))
          re2.exec(divTags[i].innerHTML);
        else {
          if (re3.test(divTags[i].innerHTML))
            re3.exec(divTags[i].innerHTML);
          else
            continue;
        }
          
      }

      var thumbnailId = RegExp.$1;
      var thumbnailKey = RegExp.$2;

      var aTags = divTags[i].getElementsByTagName("a");
      var imgTags = aTags[0].getElementsByTagName("img");

      if (objThumbnail.id == thumbnailId) {
        var maskedDiv = document.createElement("div");
        maskedDiv.id = thumbnailId + "_masked";
        maskedDiv.className = j;
        maskedDiv.style.cssText = "position: relative; background: transparent url('" + webServer+"/photos/toolthumbs.mg?tool=cropmask&Size=Small&ImageID="+ objThumbnail.id + "&ImageKey="+ objThumbnail.key + "') no-repeat; width: " + objThumbnail.imgWidth + "px; height: " + objThumbnail.imgHeight + "px; z-index: 1; margin:0px auto; text-align:left;";

        var clearedDiv = document.createElement("div");
        clearedDiv.id = thumbnailId + "_cleared";
        clearedDiv.className = j;
        clearedDiv.style.cssText = "position: absolute; background: url('" + objThumbnail.url + "') no-repeat; width: " + objThumbnail.imgWidth + "px; height: " + objThumbnail.imgHeight + "px; z-index: 2; clip:rect(0px," + objThumbnail.imgWidth + "px," + objThumbnail.imgHeight + "px,0px);";

        maskedDiv.appendChild(clearedDiv);

        var cropboxDiv = document.createElement("div");
        cropboxDiv.id = thumbnailId + "_cropbox";
        cropboxDiv.className = j;
        cropboxDiv.style.cssText = "position: absolute; left: 0px; top: 0px; width: " + (objThumbnail.imgWidth-4) + "px; height: " + (objThumbnail.imgHeight-4) + "px; border: solid 2px blue; z-index: 3; cursor: move";
        YE.on(cropboxDiv, "mousedown", testMouseBulk);
        clearedDiv.appendChild(cropboxDiv);

        var ratioboxDiv = document.createElement("div");
        ratioboxDiv.id = thumbnailId + "_ratiobox";
        ratioboxDiv.className = j;
        ratioboxDiv.style.cssText = "position: absolute; bottom: 0px; right: 0px; width: 25px; height: 25px; border-top: solid 2px blue; border-left: solid 2px blue;  cursor: pointer; cursor: hand; z-index: 4;";
        YE.on(ratioboxDiv, "mousedown", testZoomBulk); 
        cropboxDiv.appendChild(ratioboxDiv);
          
        var replaceNode = aTags[0];
        replaceNode.parentNode.replaceChild(maskedDiv, replaceNode);
        divTags[i].style.width = objThumbnail.imgWidth + "px";
        divTags[i].style.height = objThumbnail.imgHeight + "px";
      }
    }
  } 
}

function getThumbnailEXIF()
{
  var thumbnail = thumbnailEXIFArray.shift();

  if (thumbnail) {
    var postArray = new Array();
    postArray['method'] = "getImageInfo";
    postArray['imageId'] = thumbnail.id;
    postArray['imageKey'] = thumbnail.key;
    ajax_query(processThumbnailEXIF, webServer+'/rpc/image.mg', postArray, true);
    window.setTimeout(getThumbnailEXIF, 100);
  }
  else
  {
    removePageWorking();

    if (YD.hasClass(document.body,"loggedIn"))
      YD.get("bulkSave").disabled = false;
  }
}

function processThumbnailEXIF(response) {

  var json = eval('(' + response + ')');

  var imgWidth = parseInt(json.result.OriginalWidth);
  var imgHeight = parseInt(json.result.OriginalHeight);

  var obj = {"id": json.result.ImageID, "key": json.result.imageKey, "url": json.result.SmallURL};

  obj.imgHeight = (imgWidth < imgHeight) ? 300 : Math.round((imgHeight / imgWidth) * 400);
  obj.imgWidth = (imgWidth < imgHeight) ? Math.round((imgWidth / imgHeight) * 300) : 400;
  obj.ratio = 0;
  obj.invRatio = 0;
  obj.marginTop = 0;
  obj.marginLeft = 0;
  obj.cropHeight = obj.imgHeight;
  obj.cropWidth = obj.imgWidth;
  obj.oRatio = (imgWidth / obj.imgWidth);
  obj.cropDiff = 0;

  thumbnailArray.push(obj);

  maskThumbnails(thumbnailArray[thumbnailArray.length-1], "bzt_"+ (thumbnailArray.length-1));
}

function zoomThumbnails() {
  if (!thumbnailItem) {
    thumbnailItem = 0;
    thumbnailCount = thumbnailArray.length;
  }

  var thumbnail = thumbnailArray.shift();
  YD.get("bulkzoom_toolbox").style.display = "none";
  
  if (thumbnail) {
    thumbnailItem++; 

    postArray = new Array();
    postArray['tool'] = 'newthumb';
    postArray['ImageID'] = thumbnail.id;
    postArray['ImageKey'] = thumbnail.key;
    postArray['action'] = "doit";
    postArray['crop_h'] = Math.round(parseInt(thumbnail.cropHeight) * parseFloat(thumbnail.oRatio));
    postArray['crop_w'] = Math.round(parseInt(thumbnail.cropWidth) * parseFloat(thumbnail.oRatio));
    postArray['crop_x'] = Math.round(parseInt(thumbnail.marginLeft) * parseFloat(thumbnail.oRatio));
    postArray['crop_y'] = Math.round(parseInt(thumbnail.marginTop) * parseFloat(thumbnail.oRatio));

    reqIncrement ++;
    pageWorking('Processing thumbnails');
    window.setTimeout('ajax_query(thumbReqHandler, webServer+\'\/photos\/tools.mg\', postArray, true, true);', 10);
    window.setTimeout(zoomThumbnails, 50);
  } 
}


function thumbReqHandler() {
  reqIncrement--;

  if (thumbnailArray.length == 0 && reqIncrement == 0) {
      window.location.reload();
  }
}

var smallestBulk = 75;   
var mouseXBulk = 0;
var mouseYBulk = 0;
var mouseToolBulk = "move";
var hideRatioBulk = false;    
var scaleBulk = 1;
var pageLoadedBulk = false;

function onStartBulk() {
  pageLoadedBulk = true;
}        

function moveBulk(X,Y,e) {
  if (pageLoadedBulk == true)
  {
    try {
      var objClass = (e.srcElement) ? e.srcElement.className : e.target.className;
      var obj = thumbnailArray[objClass.replace("bzt_", "")];

      X = X*scaleBulk;
      Y = Y*scaleBulk;
      var newLeft = obj.marginLeft+X;
      var newTop = obj.marginTop+Y;                                
      var stopX = obj.imgWidth - obj.cropWidth;
      var stopY = obj.imgHeight - obj.cropHeight;

      if (newLeft < 0)
        newLeft = 0;

      if (newLeft > stopX)
        newLeft = stopX;

      if (newTop < 0)
        newTop = 0;

      if (newTop > stopY)
        newTop = stopY;

      obj.marginLeft = newLeft;
      obj.marginTop = newTop;

      var objNode = (e.srcElement) ? e.srcElement : e.target;

      while (objNode.id != obj.id + "_cropbox")
        objNode = objNode.parentNode;

      updateCropBulk(objNode);
    }
    catch(e) {}
  }
  else {
    window.alert("Page loading, please wait.");
  }
}        

function zoomBulk(X,Y,e)
{
  if (pageLoadedBulk == true) {
    try {
      var objClass = (e.srcElement) ? e.srcElement.className : e.target.className;
      var obj = thumbnailArray[objClass.replace("bzt_", "")];              

      var Xadj = (obj.ratio == 0) ? obj.cropWidth+(X*scaleBulk) : 0;
      var Yadj = (obj.ratio == 0) ? obj.cropHeight+(Y*scaleBulk) : 0;

      var newWidth = obj.cropWidth+(X*scaleBulk);
      var newHeight = Math.round(newWidth*obj.ratio)+Yadj;

      if (newWidth < smallestBulk) {
        newWidth = smallestBulk;
        newHeight = Math.round(newWidth*obj.ratio)+Yadj;
      }

      if (newHeight < smallestBulk) {
        newHeight = smallestBulk;
        newWidth = Math.round(newHeight*obj.invRatio)+Xadj;
      } 

      if (newWidth+obj.marginLeft > obj.imgWidth) {
        newWidth = obj.imgWidth-obj.marginLeft;
        newHeight = Math.round(newWidth*obj.ratio)+Yadj;
      } 

      if (newHeight+obj.marginTop > obj.imgHeight) {
        newHeight = obj.imgHeight-obj.marginTop;
        newWidth = Math.round(newHeight*obj.invRatio)+Xadj;
      }                

      obj.cropWidth = newWidth;
      obj.cropHeight = newHeight;

      var objNode = (e.srcElement) ? e.srcElement : e.target;

      while (objNode.id != obj.id + "_cropbox")
        objNode = objNode.parentNode;

      updateCropBulk(objNode);
    }
    catch(e) {}
    
  }
  else {
    window.alert("Page loading, please wait.");
  }
}        

function changeRatioBulk(newRatios) {
  if (pageLoadedBulk == true) {
    var newRatio = newRatios.split(",");

    for (i=0; i<thumbnailArray.length; i++) {
      var obj = thumbnailArray[i];

      if (obj.imgHeight > obj.imgWidth) {
        obj.ratio = newRatio[1];
        obj.invRatio = newRatio[0];
      }
      else {
        obj.ratio = newRatio[0];
        obj.invRatio = newRatio[1];
      }

      if (obj.ratio == 0) {
        YD.get('customRatio').style.display = "none";
        obj.marginTop = 0;
        obj.marginLeft = 0;
        obj.cropHeight = obj.imgHeight;
        obj.cropWidth = obj.imgWidth;
      }
      else {
        if (newRatios == "custom") {
          obj.ratio = document.cropTool.ratioH.value/document.cropTool.ratioW.value;
          obj.invRatio = document.cropTool.ratioW.value/document.cropTool.ratioH.value;
          YD.get('customRatio').style.display = "block";
        }
        else
          YD.get('customRatio').style.display = "none";

        obj.cropWidth = Math.round(1 * obj.imgWidth);

        obj.cropHeight = Math.round(obj.cropWidth * obj.ratio);        

        if ((obj.cropHeight > obj.imgHeight)||(obj.cropWidth > obj.imgWidth)) {
          obj.cropHeight = obj.imgHeight;  
          obj.cropWidth = Math.round(obj.cropHeight * obj.invRatio);
        }   

        obj.marginTop = ((obj.imgHeight - obj.cropHeight)/2);
        obj.marginLeft = ((obj.imgWidth - obj.cropWidth)/2);
      }

      updateCropBulk(YD.get(thumbnailArray[i].id + "_cropbox"));
    }
  }
  else {
     window.alert("Page loading, please wait.");
  }
}        

function rotateBulk() {
  if (pageLoadedBulk == true) {
    for (i=0; i<thumbnailArray.length; i++) {
      var obj = thumbnailArray[i];

      var Xadj = (obj.ratio == 0) ? obj.cropHeight : 0;
      var Yadj = (obj.ratio == 0) ? obj.cropWidth : 0;

      var temp = obj.invRatio;
      obj.invRatio = obj.ratio;
      obj.ratio = temp;
      temp = obj.cropWidth;
      obj.cropWidth = obj.cropHeight;
      obj.cropHeight = temp;  

      if (obj.cropWidth + obj.marginLeft > obj.imgWidth) {
        obj.marginLeft = obj.imgWidth - obj.cropWidth;

        if (obj.marginLeft < 0) {
          obj.marginLeft = 0;
          obj.cropWidth = obj.imgWidth - obj.marginLeft;
          obj.cropHeight = Math.round(obj.cropWidth * obj.ratio)+Yadj;                        
        }
      } 

      if (obj.cropHeight + obj.marginTop > obj.imgHeight) {
        obj.marginTop = obj.imgHeight - obj.cropHeight;

        if (obj.marginTop < 0) {
          obj.marginTop = 0;
          obj.cropHeight = obj.imgHeight - obj.marginTop;
          obj.cropWidth = Math.round(obj.cropHeight * obj.invRatio)+Xadj;
        }
      }

      updateCropBulk(YD.get(obj.id + "_cropbox"));
    }
  }
  else
    window.alert("Page loading, please wait.");
}        

function updateCropBulk(e) {
  var objClass = e.className;
  var obj = thumbnailArray[objClass.replace("bzt_", "")];

  e.parentNode.style.clip = "rect("+obj.marginTop+"px "+(obj.marginLeft+obj.cropWidth)+"px "+(obj.marginTop+obj.cropHeight)+"px "+obj.marginLeft+"px)";
  e.style.top = obj.marginTop+"px";
  e.style.left = obj.marginLeft+"px";
  e.style.width = obj.cropWidth-obj.cropDiff+"px";
  e.style.height = obj.cropHeight-obj.cropDiff+"px";
}        

function mouseMoveBulk(e) {
  if (!e) var e = window.event;

   var objClass = (e.srcElement) ? e.srcElement.className : e.target.className;

  if (lookMouse) {
    var tempX = mouseXBulk;
    var tempY = mouseYBulk;
    mouseXBulk = e.clientX;
    mouseYBulk = e.clientY;
    var x = mouseXBulk-tempX;
    var y = mouseYBulk-tempY;

    if (mouseToolBulk == "zoom") {
      if (thumbnailArray[objClass.replace("bzt_","")].ratio == 0)
        zoomBulk(x,y,e);
      else
        zoomBulk(x,0,e);
    }
    else
      moveBulk(x,y,e)
  }
}

function testMouseBulk(e) {
  state = true;
  if (!e) var e = window.event;

  if (mouseToolBulk != "zoom") {
    lookMouse = state;

    if (state == true) {
      mouseToolBulk = "move";
      mouseXBulk = e.clientX;
      mouseYBulk = e.clientY;
      document.onmousemove = mouseMoveBulk;
    }
  }
}

function testZoomBulk(e) {
  state=true;
  if (!e) var e = window.event;

  lookMouse = state;
  if (state == true) {	            
    mouseToolBulk = "zoom"
    mouseXBulk = e.clientX;
    mouseYBulk = e.clientY;
    document.onmousemove = mouseMoveBulk;
  }
}

function cancelMouse() {
  mouseToolBulk = "move";
  lookMouse = false;
}

document.onmouseup = cancelMouse;
/***** End Zoom Thumbnail Hack ****/

/******** Show Full Gallery Description Hack ***********/

var replaceLargerThumbs = function(wrapperElemName) {
	var galleryBox = document.getElementById(wrapperElemName);
	if( galleryBox != null) {
            if( galleryBox.parentNode.className == "caption") {
                return;
            }
		var galleryBoxes = getElementsByClassName("miniBox", "div", galleryBox);
		if( galleryBoxes != null) {
			for( i = 0; i < galleryBoxes.length; i++) {
				var gBox = galleryBoxes[i];
				var gThumb = getGalleryThumbElem(gBox);
				if( gThumb != null) {
					replaceGalleryThumb(gThumb);
				}
			}
		}
	}
}

var showFullGalleryDescriptions = function (wrapperElemName) {
	var galleryBox = document.getElementById(wrapperElemName);
	if( galleryBox != null) {
            if( galleryBox.parentNode.className == "caption") {
                return;
            }
		var galleryBoxes = getElementsByClassName("miniBox", "div", galleryBox);
		if( galleryBoxes != null) {
			for( i = 0; i < galleryBoxes.length; i++) {
				var gBox = galleryBoxes[i];
				var gThumb = getGalleryThumbElem(gBox);
				if( gThumb != null) {
					var gDesc = extractGalleryDescFromTitle(gThumb);
					replaceGalleryThumb(gThumb);
					var gDescPs = getElementsByClassName("description", "p", gBox);
					if( gDescPs != null) {
						if( gDescPs.length > 0) {
							var gDescP = gDescPs[0];
							gDescP.innerHTML = gDesc;
						}
					}
				}
			}
		}
	}
};

var extractGalleryDescFromTitle = function ( gThumb) {
	var gDesc = gThumb.title;
	var ix = gDesc.indexOf(" : ");
	if(ix >= 0) {
		gDesc = gDesc.substring(ix+3);
	}
	return gDesc;
};

var replaceGalleryThumb = function ( imgTag) {
	var tiUrl = imgTag.src;
        imgTag.src = tiUrl.replace(/Ti([-0-9]*).jpg/,"Th$1.jpg");
	imgTag.height = 150;
	imgTag.width = 150;
};

var getGalleryThumbElem = function ( gBox) {
	var thumbImg = null;	
	var divs = gBox.getElementsByTagName("DIV");
	if( divs != null && divs.length > 0) {
		var photoDiv = divs[0];
		if( photoDiv.className == "photo" || photoDiv.className == "photoLarge") {
			var imgElems = gBox.getElementsByTagName("img");
			if( imgElems != null && imgElems.length > 0) {
				thumbImg = imgElems[0];
			}
		}
	}
	return thumbImg;
}

/*
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/
var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),

				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};

YE.onAvailable('galleriesBox', showFullGalleryDescriptions, 'galleriesBox');
YE.onAvailable('subcategoriesBox', showFullGalleryDescriptions, 'subcategoriesBox');
YE.onAvailable('sharedGalleries', showFullGalleryDescriptions, 'sharedGalleries');
YE.onAvailable('featuredBox', replaceLargerThumbs, 'featuredBox', false);
/******** End Show Full Gallery Description Hack ***********/

/******** Begin Category / Subcategory descriptions and breadcrumb */
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 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 Category / Subcategory descriptions and breadcrumb */