/*=========================*/
/*== Shizam Slideshow    ==*/
/*=========================*/

function createSWF( w, h, params) {
 var args = "";
 for (var i in params) {
     args += i + "=" + params[i] + "&amp;";
 }
 document.writeln('<object width="100%" height="100%" align="middle">'+
'<param name="movie" value="http://www.smugmug.com/ria/ShizamSlides-2007091201.swf?'+args+'"/>'+
'<param name="wmode" value="transparent" />'+
'<embed src="http://www.smugmug.com/ria/ShizamSlides-2007091201.swf?'+args+'" wmode="transparent" width="' + w + '" height="' + h + '" type="application/x-shockwave-flash" allowScriptAccess="always" allowNetworking="all"/></object>');
return 1;
} 

/*=========================*/
/*== Duplicate Homepage  ==*/
/*=========================*/

function hasPath(sPath)
{
re = new RegExp("\/" + sPath + "(\/|$)");
return re.test(window.location)
}


/*=========================*/
/*== Vanity URLS         ==*/
/*=========================*/

var vanityTable = 
 {
     scottandjodi : "http://www.davidtomic.com/gallery/4146927",
     re4x4 : "http://www.davidtomic.com/gallery/3516956#198792109",
     showtimefmx : "http://www.davidtomic.com/gallery/3509414", 
     show06 : "http://www.davidtomic.com/gallery/3509422",     
     show07 : "http://www.davidtomic.com/Events/383231",
     reese : "http://www.davidtomic.com/Family/311430",
     beingearnest : "http://www.davidtomic.com/gallery/3387836",
     avalon2007 : "http://www.davidtomic.com/gallery/2618867",
     football : "http://www.davidtomic.com/Sports/367060",
     crcnktest : "http://www.davidtomic.com/gallery/6389380_m2D47"
 };

function IsHomePage()
 {
    return(YD.hasClass(document.body, 'homepage'));
 }
 
 function CheckRedirects()
 {
     if (YD.hasClass(document.body, 'homepage'))    // only run this code on the home page
     {
         // get the path from the current URL, 
         // convert it to lowercase and remove the leading slash
         var path = window.location.pathname.toLowerCase().substr(1);
         
         var newURL = vanityTable[path];        // look it up in our table
         
         // if we found it in the table && newURL is different than where we are
         if (newURL && (newURL != window.location))
         {
             window.location.replace(newURL);        // go to the new URL
         }
     }
 }
 
/*=========================================*/
/*== Change Gallery to Guestbook comments==*/
/*=========================================*/

function ModifyText () 
{
  if (YD.hasClass(document.body, "gallery_2665920")) 
  {
    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);

/*===================================================*/
/*== Get rid of the same boring title on every page==*/
/*===================================================*/

document.title = "DavidTomic.com";
function RelevantTitle()
{
   var baseTitle = "DavidTomic.com";
   var separator = " - ";
   var albumTitle = document.getElementById("albumTitle");
   var galleryTitle = document.getElementById("galleryTitle");
   if( albumTitle && albumTitle.textContent )
      document.title = baseTitle + separator + albumTitle.textContent;
   else if( galleryTitle && galleryTitle.textContent )
   {
      var galleryTitleText = galleryTitle.textContent;
      // Strip " sub-categories" off the end of the category text
      var finalPositionCategory = galleryTitleText.search(" sub-categories");
      if( finalPositionCategory >= 0 )
         galleryTitleText = galleryTitleText.substr( 0, finalPositionCategory );
      else
      {
         // Strip " galleries" off the end of the category/sub-category text
         var finalPositionSubCategory = galleryTitleText.search(" galleries");
         if( finalPositionSubCategory >= 0 )
            galleryTitleText = galleryTitleText.substr( 0, finalPositionSubCategory );
      }
      document.title = baseTitle + separator + galleryTitleText;
   }
   else // Not Gallery, Category, or Subcategory
   {
      // Set title on homepage
      document.title = baseTitle;
   }
}


/*===================================================*/
/*==    Add SmugMug refferal code to page footer   ==*/
/*===================================================*/

function AddReferralCode()  {
  var links = this.getElementsByTagName("A");
  if (links && (links.length != 0)) {
    var smugLink = links.item(0);
    smugLink.href = "http://www.smugmug.com/?referrer=spEouKpaPdz5M";
  }
}
YE.onAvailable('footer', AddReferralCode);