/*displaySmugPopular = false;*/

document.title="DZ's Photography"

rightClickWarning = "These photos are copyright protected. All rights reserved.  No material may be reproduced electronically or in print without written permission.  Unauthorized use is strictly prohibited.  If you would like to use this image, please email your request via the contact tab on the menu bar."




/*===========================*/
/*== SLIDE SHOW            ==*/
/*== version .091          ==*/
/*== Updated 09 March 2006 ==*/
/*===========================*/
var SLIDE_SHOW = 0;
var RANDOM_PHOTO = 1;
var slideshowContainer;
var slide;
var ssLoaded;
var ssImage;
var ssFile;
var ssSlideTotal;
var ssSlideTimer;
var ssOldSlide;
var ssFadeTimer;
var ssFade;
var ssTimerId;
var blank;


function PrepSlideEnvironment()
{
  blank = new Image();
  blank.src = "/img/spacer.gif";

  if (typeof(slideshowType) == "undefined" || (slideshowType != SLIDE_SHOW && slideshowType != RANDOM_PHOTO))
    slideshowType = SLIDE_SHOW;

  if (slideshowType == RANDOM_PHOTO)
    randomSlides = true;

  if (typeof(slideshowContainerId) == "undefined")
    return false
  else if (typeof(slideshowContainerId) == "string")
    slideshowContainer = document.getElementById(slideshowContainerId);

  if (!slideshowContainer)
    return false;

  if (typeof(slideshowAlbumId) == "undefined" || typeof(slideshowAlbumId) != "string")
    return false;

  if (typeof(slideHeight) == "undefined" || isNaN(slideHeight))
    slideHeight = "400";

  if (typeof(slideWidth) == "undefined" || isNaN(slideWidth))
    slideWidth = "400";

  if (typeof(photoHeight) == "undefined" || isNaN(photoHeight))
    photoHeight = slideHeight;

  if (typeof(photoWidth) == "undefined" || isNaN(photoWidth))
    photoWidth = slideWidth;

  if (typeof(slideDuration) == "undefined" || isNaN(slideDuration))
    slideDuration = 3;

  if (typeof(firstSlideUrl) == "undefined" || typeof(firstSlideUrl) != "string")
    firstSlideUrl = blank.src;

  if (typeof(showSlideTransition) == "undefined" || typeof(showSlideTransition) != "boolean")
    showSlideTransition = true
  
  if (typeof(resizeToPhoto) == "undefined" || typeof(resizeToPhoto) != "boolean")
    resizeToPhoto = true;

  if (typeof(quickStart) == "undefined" || typeof(quickStart) != "boolean")
    quickStart = true;

  if (typeof(randomSlides) == "undefined" || typeof(randomSlides) != "boolean")
    randomSlides = true;

  if (typeof(slideControls) == "undefined" || typeof(slideControls) != "boolean")
    slideControls = false;

  return true;
}


function loadSlideshow()
{
  if (!PrepSlideEnvironment())
    return false;

  var re = /(http:\/\/[\w]+\.[\w]+\.[\w]+)\//; 
  re.exec(window.location);
  var webServer = RegExp.$1;

  slideshowContainer.innerHTML = '<img src="http://www.smugmug.com/img/spacer.gif" alt="" id="ssSlide" height="' + slideHeight + '" width="' + slideWidth + '" style="opacity: .99; background-image: url(' + firstSlideUrl + '); background-repeat: no-repeat; background-position: center;" />';

  if (slideControls)
    slideshowContainer.innerHTML += '<div id="ssControl"><a title="Previous Slide" id="ssPrev" class="ssBtn" href="javascript: void(0);" onclick="prevSlide();"><img src="/img/spacer.gif" border="0" /></a><a title="Next Slide" id="ssNext" class="ssBtn" href="javascript: void(0);" onclick="nextSlide();"><img src="/img/spacer.gif" border="0" /></a><a title="Pause Slideshow" id="ssPause" class="ssBtn" href="javascript: void(0);" onclick="pauseSlideshow();"><img src="/img/spacer.gif" border="0" /></a><a title="Resume Slideshow" id="ssPlay" class="ssBtn" href="javascript: void(0);" onclick="resumeSlideshow();"><img src="/img/spacer.gif" border="0" /></a></div>';

  slide = document.getElementById('ssSlide');

  ssIndex = new Array();
  ssHeight = new Array();
  ssWidth = new Array();
  ssLoaded = new Array();
  ssImage = new Array();
  ssFile = new Array();
  ssSlideTotal = 0;
  ssSlideTimer = 0;
  ssOldSlide = 0;
  ssFadeTimer = 50;
  ssFade = "out";  
 
  ajax_query(slideshowHandler,webServer+'/photos/sspopup.mg?AlbumID=' + slideshowAlbumId, null, true);
}


function slideshowHandler(response)
{
  var re = /file\[\d+\] = "[\S ]+\(\);/g;
  var re2 = /width\[\d+\] = "\d+";/g;
  var re3 = /height\[\d+\] = "\d+";/g;
 
  s = response.match(re); 
  w = response.match(re2);
  h = response.match(re3);

  for (i = 0; i < s.length; i++)
  {
   ssIndex[i+1] = i+1;
   temp = s[i].split(/"/);
   ssFile[i+1] = temp[1] + photoHeight + temp[3] + photoWidth;
   temp = h[i].split(/"/);
   ssHeight[i+1] = temp[1];
   temp = w[i].split(/"/);
   ssWidth[i+1] = temp[1];
   ssLoaded[i+1] = false;
 
   if ((ssWidth[i + 1] > photoWidth) || (ssHeight[i + 1] > photoHeight))
   {
     if (ssWidth[i + 1] >= ssHeight[i + 1])
     {
        ssHeight[i + 1] = Math.round((ssHeight[i + 1] / ssWidth[i + 1]) * photoWidth);
        ssWidth[i + 1] = photoWidth;
     }
     else
     {
       ssWidth[i + 1] = Math.round((ssWidth[i + 1] / ssHeight[i + 1]) * photoHeight);
       ssHeight[i + 1] = photoHeight;
     }
   }
  }
  ssSlideTotal = s.length;

  if (randomSlides)
  {
    ssIndex.shift();
    ssIndex.shuffle();
    ssIndex.unshift(0);
  }

  if (quickStart)
    ssSlideTimer = (slideDuration * 1000);

  ssPrepSlide(ssIndex[1]);
  window.setTimeout("ssPrepSlide(ssIndex[2]);", 0);
  window.setTimeout("ssPrepSlide(ssIndex[ssSlideTotal]);", 0);

  if (slideshowType == SLIDE_SHOW)
    ssPlaySlideshow();
  else
    ssSlideSwap(1);
}


function ssPauseSlideshow()
{
  window.clearTimeout(ssTimerId);
  ssTimerId = null;
}


function ssResumeSlideshow()
{
  if (!ssTimerId)
    ssTimerId = window.setTimeout("ssPlaySlideshow()", 10);
}


function ssPrepSlide(prep)
{
  if (ssLoaded[prep] == false)
  {
    ssImage[prep] = new Image();
    ssImage[prep].src = ssFile[prep];
    ssLoaded[prep] = true;
  }   
}


function ssMoveSlide(i) {
  ssSlideTimer = 0;
  ssFadeTimer = 100;
  ssTransition(ssFadeTimer);
  ssFade = "out";
  ssSlideSwap(i);                       
}


function ssPlaySlideshow()
{
  if (ssSlideTimer >= (slideDuration * 1000))
  {                
    if (ssFade == 'out')
      ssTransition(ssFadeTimer -= 10);                   
 
    if (ssFadeTimer == 0)
    {
      ssSlideSwap(1);
      ssFade = 'in';
    }
 
    if (ssFade == 'in')
      ssTransition(ssFadeTimer += 10);
 
    if (ssFadeTimer == 100)
    {
      ssSlideTimer = 0;
      ssFade = 'out';
    }
  }
  else
    ssSlideTimer += 10;
 
  ssTimerId = window.setTimeout("ssPlaySlideshow()", 10);
}


function ssTransition(opacity)
{
  if (showSlideTransition)
  {
    if (opacity != 100)
      slide.style.opacity = (opacity / 100);   
 
    // one case where mozilla sucks: the image will flash if you turn opacuity up to 1 suddenly
    else
      slide.style.opacity = (.99);
 
    // only affects Win IE
    slide.style.filter = 'alpha(opacity=' + opacity + ')';
  }
}


function ssSlideSwap(i)
{
  var newSlide = ssOldSlide + i;
 
  if (newSlide > ssSlideTotal)
    newSlide = 1;
 
  if (newSlide < 1)
    newSlide = ssSlideTotal;
 
  if (ssLoaded[ssIndex[newSlide]] != false)
  {
    document.images['ssSlide'].src = blank.src;
    slide.style.backgroundImage = 'url(' + ssFile[ssIndex[newSlide]] + ')';
    if (resizeToPhoto)
    {
      document.images['ssSlide'].height = ssHeight[ssIndex[newSlide]];
      document.images['ssSlide'].width = ssWidth[ssIndex[newSlide]];
    }
    
    ssPrepSlide(ssIndex[newSlide + i]);
    ssOldSlide = newSlide;
  }
  else
  {
    ssPrepSlide(ssIndex[newSlide]);
    ssSlideSwap(i);
  }
}



Array.prototype.shuffle = function()
{
  var len = this.length;
  var rand, temp, i;

  for (i = 0; i < len; i++)
  {
    rand = Math.floor(Math.random()*len);
    temp = this[i];
    this[i] = this[rand];
    this[rand] = temp;
  }
}


function pauseSlideshow()
{
  document.getElementById('ssPause').style.display = "none";
  document.getElementById('ssPlay').style.display = "inline";
  ssPauseSlideshow();
}


function resumeSlideshow()
{
  document.getElementById('ssPause').style.display = "inline";
  document.getElementById('ssPlay').style.display = "none";
  ssResumeSlideshow();
}


function prevSlide()
{
  pauseSlideshow();
  ssMoveSlide(-1);
}


function nextSlide()
{
  pauseSlideshow();
  ssMoveSlide(1);
}


function isClass(sClass) {
  sClassName = document.body.className;
  re = new RegExp(sClass + "( |$)") 

  if (!sClassName)
    return false;

  return re.test(sClassName);
}


