// script to automatically redirect to the iphone interface from any 
// small screen webkit browser (e.g. iPhone, iPod Touch, Palm Pre, Android, etc...)

// Check if we are on a small screen
function CheckForSmallScreen(minWidth, minHeight)
{
    return(window.screen.height < minHeight || window.screen.width < minWidth);
}

// Check if the browser userAgent string is AppleWebKit
function CheckForWebKitUA()
{
    return(navigator.userAgent.search(/AppleWebKit/i) != -1);
}

// Check if the URL already has /iphone in it
function CheckForIPhoneURL()
{
    return(window.location.pathname.toString().search(/^\/iphone/i) != -1);
}

// Switch to the iphone UI if we're a webkit browser, are not already the /iPhone URL and are on a small screen
function RedirectIfSmallWebKitBrowser()
{
    var parms = window.location.search;
    if (parms.search(/autoPhoneRedirect=no|stripiPhoneCookie=yes/i) != -1)
    {
        SM.util.setCookie("autoPhoneRedirect", "no", 1);
    }
    else if (parms.search(/autoPhoneRedirect=yes/i) != -1)
    {
        SM.util.setCookie("autoPhoneRedirect", "yes", 1);
    }
    // check to see if redirection has been turned off via cookie
    var value = "";
    value = SM.util.getCookie("autoPhoneRedirect");
    if (value != "no")
    {
        if (CheckForWebKitUA() && !CheckForIPhoneURL() && CheckForSmallScreen(600,600))
        {
            window.location.replace("/iphone");
        }
    }
}

RedirectIfSmallWebKitBrowser();

function ModifyText ()
{
if (YD.hasClass(document.body, "gallery_5943244"))
{
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 delHover() {
imgTags = document.getElementsByTagName("img");
for (i=0; i<imgTags.length; i++) {
imgTags[i].title = "";
imgTags[i].alt = "";
}
}
YE.onAvailable('keywordsTitle', function() {this.innerHTML = ''});
var vanityTable = 
 {
blog : "http://www.blog.chrismooreimages.com",
recent : "/gallery/5896987_RD3Yk",
wedding : "/share/UKkFvpquvIP62",
engagement : "/share/s3LRLpQF6zkL6",
calendar : "/gallery/5979416_fkC5T",
purchase : "/gallery/6072966_GCXcT",
photooftheweek : "/gallery/6013437_6wSzt",
imagegalleries : "/gallery/6090180_Bomhf",
contact : "/gallery/5878492_whMR9",
about : "/gallery/5808346_Ds8tH",
guestbook : "/gallery/5943244_hqhbR",
africa : "/gallery/6550639_PwKaV",
utah : "/gallery/6599626_DCWJc",
katelynbook : "/gallery/6554025_Sb3JA",
gear : "/gallery/7102205_F67BK",
vendors : "/gallery/6889455_StmkA",
download1 : "/gallery/7026910_W9unU",
download2 : "/gallery/7037103_5oeA3",
download3 : "/gallery/7036969_YVVxh",
katelyn : "/gallery/6968651_rLBZX"
 };

 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
         }
     }
 }
function AddReferralCode()  {
  var links = this.getElementsByTagName("A");
  if (links && (links.length != 0)) {
    var smugLink = links.item(0);
    smugLink.href = "http://www.smugmug.com/?referrer=XYNEbQ9sjCIws";
  }
}
YE.onAvailable('footer', AddReferralCode);
var rightClickWarning = "All images are © Chris Moore Photography. All Rights Reserved. Unauthorized use prohibited.";

        function rightProtect(e) {
            if (window.event) {
                var srcEl = event.srcElement ? event.srcElement : event.target;
            } else {
                var srcEl = e.srcElement ? e.srcElement : e.target;
            }

            var className = srcEl.className;

            if (className.indexOf('protected') != -1) {
                window.alert(rightClickWarning);
                return false;
            } else {
                return true;
            }
        }

function hasPath(sPath)
{
re = new RegExp("\/" + sPath + "(\/|$)");
return re.test(window.location)
}
YE.onAvailable('mapTitle', function() {this.innerHTML = 'Let Me Show You the World'});

YE.onAvailable('categoryTitle', function() {this.innerHTML = 'Galleries'});

YE.onAvailable('datesTitle', function() {this.innerHTML = 'Browse by Date Uploaded'});

document.title = "Chris Moore Photography";
function RelevantTitle()
{
   var baseTitle = "Chris Moore Photography";
   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;
   }
}


function norobotmail(aUser, aDomain) { document.location = "mailto:" + aUser + "@" + aDomain; }
filmstripMove = 0;

YE.onContentReady("altViews", MovePaypalContent);
 
function MovePaypalContent()
{
    var paypalObj = document.getElementById("paypalButtonSet");
    var altViews = document.getElementById("altViews");
    if (altViews && paypalObj)
    {
        var paypalSetObj = paypalObj.parentNode.removeChild(paypalObj);
        altViews.appendChild(paypalSetObj);
        paypalSetObj.style.display = "inline";
    }    
}
YE.onAvailable('galleryTitle', function() {this.innerHTML = this.innerHTML.replace(/(sub\-)?categories/, '')});

function insertSlideshowNoClick(width, height, parms, transparency)
{
	var isClickURL = false;
	var gifHeight = height;
	var gifWidth = width;
	
	// it appears that the default for showThumbs is true
	if ((!parms.showThumbs) || ((parms.showThumbs == "true") && (height > 100)))
	{
		gifHeight -= 87;
	}
	// can't support the startButton because it will never get clicked
	if (parms.showStartButton)
	{
		delete parms.showStartButton;
	}
	// can't support the buttons because they will never get clicked
	if (parms.showButtons)
	{
		parms.showButtons = "false";		
	}
	document.write('<div id="slideshowContainerWrapper" style="position:relative;">\n');
	if (parms.clickUrl && (parms.clickUrl != "blank") && (parms.clickUrl != "false"))
	{
		isClickURL = true;
		var newWindowText = "";
		if (parms.newWindow && (parms.newWindow == "true"))
		{
			newWindowText = ' target="_blank" ';
		}
		document.write('<a href="' + parms.clickUrl + '"' + newWindowText + '>');
	}
	document.write('<img src="/img/spacer.gif" border="0" style="position:absolute;" height="' + gifHeight + '" width="' + gifWidth + '" oncontextmenu="return false;">\n');
	if (isClickURL)
	{
		document.write('</a>');
	}
	SM.flash.insertSlideshow(width, height, parms, transparency);
	document.write("</div>");
}




function GetDateTime(){
   var oDate = new Date();
   var sDate = oDate.getMonth() + 1 + "/" + 
      oDate.getDate() + "/" + oDate.getYear();
   var iHour = oDate.getHours();
   var sAmPm;
 
   if (iHour < 13)
   {
      sAmPm = "AM";
   }
   else
   {
      iHour = iHour - 12;
      sAmPm = "PM";
   }
   var sTime = iHour + ":" + oDate.getMinutes() + " " + sAmPm;
   
   return sDate + ", " + sTime;
}



