function hasPath(sPath)
{
re = new RegExp("\/" + sPath + "(\/|$)");
return re.test(window.location)
} 

if (hasPath("galleries"))
YD.addClass(document.body, "galleries");

// guest book hack

if (YD.hasClass(document.body,'gallery_9491700'))
{
   var objElement = YD.get("comment_header")
   if (objElement != null) {
     var str = new String(objElement.innerHTML);
     str = str.replace('Gallery', 'TPP');
     str = str.replace('Comments', 'Guestbook');
     objElement.innerHTML = str;
   }
}


// Disable Mouse Over Popup

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)});



// change text in guest book

function ModifyText ()
{
  if (YD.hasClass(document.body, "gallery/Guestbook")) 
  {
    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);



// no click in journal style

// for single gallery


function doOnLoad()

{

if (window.AlbumID &&

(window.AlbumID == "9528983")) //

removeLinkFromImg();

}

function removeLinkFromImg()

{

    var links = document.getElementsByTagName("A");

    for (var i = 0; i < links.length; i++)

    {

        var link = links[i];

        var divElm = link.parentNode;

        if (!divElm)

            continue;

        divElm = divElm.parentNode;

        if (!divElm)

            continue;

        if (divElm.className.indexOf("photo")<0)

            continue;

        link.href = "javascript:void(0);";

    }

}

YE.onAvailable('bodyWrapper', doOnLoad);


// ---------------------------------------------
// Slideshow parameter modification
// ---------------------------------------------
function MyEmbedSWF(swfURL, containerID, swfID, version, backgroundColor, expressInstall)
{
	// catch all exceptions here so, if there's an error, we just continue on as if we weren't here
	try {
		var overrides = null;
		if (this._type == "gallery")
		{
			overrides = this.gallerySlideshowOverrides;
		}
		else if (this._type == "fullScreen")
		{
			overrides = this.fullScreenSlideshowOverrides;
		}
		if (overrides)
		{
			// copy all overrides over into the objects flashVars
			for (var i in overrides)
			{
				this._flashVars[i] = overrides[i];
			}
		}
	} catch (e) {}
	oldEmbedSWF.apply(this, arguments);		// call the regular handler for this method
}


function SetSlideshowOverrides()
{
	var globalGallerySlideshowConfigOverride = {
		showButtons: "false",
		showSpeed: "false",
		showThumbs: "false",
		captions: "false",
		transparent: "true"		// no comma after the last entry in this table or IE7 will barf
	};

	var globalFullScreenSlideshowConfigOverride = {
		showButtons: "false",
		showSpeed: "false"		// no comma after the last entry in this table or IE7 will barf
	};
	
	SM.flash.Slideshow.prototype.gallerySlideshowOverrides = globalGallerySlideshowConfigOverride;
	SM.flash.Slideshow.prototype.fullScreenSlideshowOverrides = globalFullScreenSlideshowConfigOverride;
	
	// now check to see if anything was defined just for this gallery and use it instead
	if (typeof(localGallerySlideshowConfigOverride) == "object")
	{
		SM.flash.Slideshow.prototype.gallerySlideshowOverrides = localGallerySlideshowConfigOverride;
	}
	if (typeof(localFullScreenSlideshowConfigOverride) == "object")
	{
		SM.flash.Slideshow.prototype.fullScreenSlideshowOverrides = localFullScreenSlideshowConfigOverride;
	}
}

// SM.flash.Slideshow is only defined in a galleries page
if (typeof(SM.flash.Slideshow) == "function")
{
	var oldEmbedSWF = SM.flash.Slideshow.superclass._embedSWF;
	SM.flash.Slideshow.superclass._embedSWF = MyEmbedSWF;
	SetSlideshowOverrides();
}

// ---------------------------------------------
// end of slideshow customization
// ---------------------------------------------



// no click in journal style

// for single gallery


function doOnLoad()

{

if (window.AlbumID &&

(window.AlbumID == "9491700")) //

removeLinkFromImg();

}

function removeLinkFromImg()

{

    var links = document.getElementsByTagName("A");

    for (var i = 0; i < links.length; i++)

    {

        var link = links[i];

        var divElm = link.parentNode;

        if (!divElm)

            continue;

        divElm = divElm.parentNode;

        if (!divElm)

            continue;

        if (divElm.className.indexOf("photo")<0)

            continue;

        link.href = "javascript:void(0);";

    }

}

YE.onAvailable('bodyWrapper', doOnLoad);


// no click in journal style

// for single gallery


function doOnLoad()

{

if (window.AlbumID &&

(window.AlbumID == "9528983")) //

removeLinkFromImg();

}

function removeLinkFromImg()

{

    var links = document.getElementsByTagName("A");

    for (var i = 0; i < links.length; i++)

    {

        var link = links[i];

        var divElm = link.parentNode;

        if (!divElm)

            continue;

        divElm = divElm.parentNode;

        if (!divElm)

            continue;

        if (divElm.className.indexOf("photo")<0)

            continue;

        link.href = "javascript:void(0);";

    }

}

YE.onAvailable('bodyWrapper', doOnLoad);


//------------------------------------------------------------------------------------
// Move share button to the cart line
//-------------------------------------------------------------------------------------

YE.onContentReady("shareButton", 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
    }    
}


//--------------------------------------------------------------------------------------------------------------------
// MarkHiddenThumbs puts a red X on thumbnails in the Smugmug view that are hidden
//
// Installation and support is here: http://www.dgrin.com/showthread.php?t=143433.
//--------------------------------------------------------------------------------------------------------------------
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);

// --------------------------------------
// End of MarkHiddenThumbs code
// --------------------------------------
