////////////////////////////////////////////////////////////
// remove img caption when cursor is mouseover
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)});


//////////////////////////////////////////////////////////////////////
// MarkHiddenThumbs puts a red X on thumbnails in the Smugmug view that are hidden

if (typeof(JLF) == "undefined") var JLF = new Object;

// Declare a global object with our various methods on it.  This puts all of our methods in their own namespace like YUI does.
JLF.HiddenMarkers = 
{
	// global data variables on the object
	oldHidePhoto: "",
	
	// externally accessible methods
	
	// Replacement for the built-in hidePhoto function.  
	// It calls the original function, then updates the hidden marker for the affected thumb
	NewHidePhoto: function(status, ImageID, ImageKey)
	{
		var retVal = JLF.HiddenMarkers.oldHidePhoto.apply(this, arguments);
		var thumb = YD.get("photoBox_" + ImageID);
		if (thumb)
		{
			JLF.HiddenMarkers.MarkSingleHiddenThumb(thumb);
		}
		return(retVal);
	},
	
	// Set the style from a whole style string rather than one attribute at a time
	SetStyleString: function(element, str)
	{
		var styles = str.split(/\s*;\s*/);
		for (var i in styles)
		{
			var pieces = styles[i].split(/\s*:\s*/);
			if (pieces.length > 1)
			{
				YD.setStyle(element, pieces[0], pieces[1]);
			}
		}
	},
	
	// Update the hidden status of a single thumb
	MarkSingleHiddenThumb: function(element)
	{
		try
		{
			// get existing marker if here
			var markers = YD.getElementsByClassName("hiddenMarker", "div", element);
			var imageID = element.id.substr(9);		// strip off "photoBox_" off the id to get just the id
			if (photoInfo[imageID].Status == "Hidden")
			{
				// if there is no marker yet, add one
				if (!markers || (markers.length == 0))
				{
					var links = element.getElementsByTagName("a");
					var imgs = links[0].getElementsByTagName("img");
					var newDiv = document.createElement("div");
					newDiv.className = "hiddenMarker";
					JLF.HiddenMarkers.SetStyleString(newDiv, "position: absolute; top:1px; left:5px; z-index:10; color: #F00; font-size: 14pt; font-weight: bold; font-family: Arial;");
					newDiv.innerHTML = "X";
					imgs[0].parentNode.insertBefore(newDiv, imgs[0]);
				}
			}
			else	// not hidden now
			{
				// if there's a hidden marker, then remove it
				if (markers && (markers.length != 0))
				{
					markers[0].parentNode.removeChild(markers[0]);		// remove it
				}
			}
		} catch (e) {}
	},
	
	// Update the hidden status of all thumbs
	// Only written to work in the Smugmug view when logged in
	// Other views don't appear to have the photoInfo array which gives us the hidden status
	MarkAllHiddenThumbs: function()
	{
		
		if (YD.hasClass(document.body, "loggedIn") && YD.hasClass(document.body, "smugmug"))
		{
			YD.getElementsByClassName("photo", "div", YD.get("thumbnails"), JLF.HiddenMarkers.MarkSingleHiddenThumb);
		}
	}
};

// Install our replacement function for hidePhoto
if (typeof(hidePhoto) == "function")
{
	JLF.HiddenMarkers.oldHidePhoto = hidePhoto;
	hidePhoto = JLF.HiddenMarkers.NewHidePhoto;
}

// Register for notifications when the Smugmug view has been rendered
onPhotoShow.subscribe(JLF.HiddenMarkers.MarkAllHiddenThumbs);



//////////////////////////////////////////////////////////////////////
// Change smugmug link to add my referral !
function AddReferralCode()  {
  var links = this.getElementsByTagName("A");
  if (links && (links.length != 0)) {
    var smugLink = links.item(0);
    smugLink.href = "http://www.smugmug.com/?referrer=5N5oLiQDRqZdI";
  }
}
YE.onAvailable('footer', AddReferralCode);


/////////////////////////////////////////////////////////////////////
// "duplicate" the gallery/homepage to access it through 2 different links. Required for slideshow on the first page.
function hasPath(sPath)
{
re = new RegExp("\/" + sPath + "(\/|$)");
return re.test(window.location)
}

if (hasPath("Galleries") || hasPath("galleries") )
YD.addClass(document.body, "galleries");


///////////////////////////////////////////////////////////////////////// Change Breadcrumb 

var objElement = document.getElementById("breadCrumbTrail")
if (objElement != null) {
var str = new String(objElement.innerHTML);
str = str.replace('>Johan Georget<', '>Galleries</a><');
objElement.innerHTML = str;

}


/////////////////////////////////////////////////////////////////////
// Code to move the slideshow button to the same row as the buy button

YE.onContentReady("shareButton", MoveToCartDiv);
YE.onContentReady("viewingStylesButton", MoveToCartDiv);


function MoveToCartDiv()
{
    MoveObjToDiv(this, "cartButtonsWrapper");
}

function MoveObjToDiv(sourceObj, destDiv)
{
    var destDivObj = document.getElementById(destDiv);    // get the object for the dest div
    if (sourceObj && destDivObj)
    {
        sourceObj.parentNode.removeChild(sourceObj);    // remove object from it's current parent
        destDivObj.appendChild(sourceObj);                // add it to the new parent
    }    
}
