// Copyright (c) 2,011 AZGalleries.com. All Rights Reserved
// Unauthorized use of this code is strictly forbidden

function ChangeImage (iJump, bClicked)
{
  var iLastImage = iCurrentImage ;

  iCurrentImage += iJump ;
  if (iCurrentImage >= iaImageWidths.length) iCurrentImage = iaImageWidths.length - 1 ;
  if (iCurrentImage < 0) iCurrentImage = 0 ;

  if (iCurrentImage != iLastImage)
  {
    oSlideshowImage.src = saImageUrls [iCurrentImage] ;
    ResizeImage (false) ;

    oSlideshowControls_ImageProgress.innerHTML =
     PadNumber (iCurrentImage + 1, 2) + ' of ' + PadNumber (saImageUrls.length, 2) ;

    DisableAnchor (oSlideshowControls_ImagePrev, iCurrentImage <= 0 ? true : false) ;
    DisableAnchor (oSlideshowControls_ImageNext, iCurrentImage >= (iaImageWidths.length - 1) ? true : false) ;

    if (iaImageWidths.length <= (iCurrentImage + 2)) PreloadImage () ;

    if (bClicked) RunSlideshow (false, false) ;
  }
  else if (iCurrentImage >= (saImageUrls.length - 1))
  {
    RunSlideshow (false, false) ;
    if (!bLocationChanged) { bLocationChanged = true ; location.href = sWebsiteUrl ; }
  }
}

function DelaySecsChanged (event)
{
  DisableAnchor (oSlideshowControls_DelaySet, false) ;

  if (event && (event.keyCode == 13))
  {
    oSlideshowControls_DelaySet.focus () ;
    SetDelay () ;
  }
}

function FocusMoved (obj, bLostOrGained)
{
  if (bLostOrGained) oFocusedElement = obj ;
  else if (obj == oFocusedElement) oFocusedElement = false ;
}

function GetHTMLLayerTimeout (bShow, iClientX, iClientY)
{
  if (bShow && (oGetHTMLMain.style.visibility != 'visible'))
  {
    oGetHTMLMain.style.left = (iClientX - Math.round (oGetHTMLMain.offsetWidth / 2)) + 'px' ;
    oGetHTMLMain.style.top  = (GetAbsoluteYPosition (oSlideshowGetHTMLButton, null) +
     oSlideshowGetHTMLButton.offsetHeight + 1) + 'px' ;

    if (GetAbsoluteXPosition (oGetHTMLMain, null) < 8) oGetHTMLmain.style.left = 8 + 'px' ;
    if ((iWindowWidth - GetAbsoluteXPosition (oGetHTMLMain, null) - oGetHTMLMain.offsetWidth) < 8)
     oGetHTMLMain.style.left = (iWindowWidth - oGetHTMLMain.offsetWidth - 8) + 'px' ;

    oGetHTMLMain.style.visibility = 'visible' ;
  }

  if (!bShow && (oGetHTMLMain.style.visibility != 'hidden'))
  {
    oGetHTMLMain.style.visibility = 'hidden' ;

    oGetHTMLMain.style.left = '0px' ;
    oGetHTMLMain.style.top  = '0px' ;
  }

  oGetHTMLLayerTimeout = false ;
}

function HelpLayerTimeout (bShow, iClientX, iClientY)
{
  if (bShow && (oHelpMain.style.visibility != 'visible'))
  {
    oHelpMain.style.left = (iClientX - Math.round (oHelpMain.offsetWidth / 2)) + 'px' ;
    oHelpMain.style.top  = (GetAbsoluteYPosition (oSlideshowHelpButton, null) +
     oSlideshowHelpButton.offsetHeight + 1) + 'px' ;

    if (GetAbsoluteXPosition (oHelpMain, null) < 8) oHelpmain.style.left = 8 + 'px' ;
    if ((iWindowWidth - GetAbsoluteXPosition (oHelpMain, null) - oHelpMain.offsetWidth) < 8)
     oHelpMain.style.left = (iWindowWidth - oHelpMain.offsetWidth - 8) + 'px' ;

    oHelpMain.style.visibility = 'visible' ;
  }

  if (!bShow && (oHelpMain.style.visibility != 'hidden'))
  {
    oHelpMain.style.visibility = 'hidden' ;

    oHelpMain.style.left = '0px' ;
    oHelpMain.style.top  = '0px' ;
  }

  oHelpLayerTimeout = false ;
}

function KeyCaptured (event)
{
  if ((typeof bSettingsLoaded != 'undefined') && bSettingsLoaded && bSlideshowMode && !oFocusedElement)
   if (event) switch (event.keyCode)
  {
  case 32 : // Space

    RunSlideshow (!oSlideshowTimeout ? true : false, true) ;
    break ;

  case 33 : // Page up

    if (iCurrentImage > 0) ChangeImage (- 5, true) ;
    break ;

  case 34 : // Page down

    if (iCurrentImage < (iaImageWidths.length - 1)) ChangeImage (5, true) ;
    break ;

  case 35 : // End

    if (iCurrentImage < (iaImageWidths.length - 1)) ChangeImage (100, true) ;
    break ;

  case 36 : // Home

    if (iCurrentImage > 0) ChangeImage (- 100, true) ;
    break ;

  case 37 : case 38 : // Left and Up

    if (iCurrentImage > 0) ChangeImage (- 1, true) ;
    break ;

  case 39 : case 40 : // Right and Down

    if (iCurrentImage < (iaImageWidths.length - 1)) ChangeImage (1, true) ;
    break ;

  case 67 : // 'C'

    bControlsLocked = !bControlsLocked ;
    MarginTimeout (bControlsLocked) ;

    AjaxRequest ('POST', 'http://www.azgalleries.com/settings.php?controlslocked=' + bControlsLocked, true, false) ;
    break ;
  }
}

function LoadSettings (sSettings)
{
  if (sSettings.length)
  {
    var saSettings = sSettings.split (' ') ;
    if (saSettings.length == 4)
    {
      bSlideshowMode    = saSettings [0] == 'no' ? false : true ;
      bAutoRunSlideshow = saSettings [1] == 'no' ? false : true ;
      bControlsLocked   = saSettings [2] == 'no' ? false : true ;

      iSlideshowDelaySecs = parseInt (saSettings [3]) ;
    }
  }

  oSlideshowControls_DelaySecs.value = iSlideshowDelaySecs ;

  bSettingsLoaded = true ;
  if (bSlideshowMode) ViewAsSlideshow (false) ;
}

function MarginTimeout (bShow)
{
  if (bSettingsLoaded && bSlideshowMode)
  {
    if (bShow && !bControlsVisible)
    {
      oSlideshowTop.style.display    = 'block' ;
      oSlideshowBottom.style.display = 'block' ;
      ResizeLayout () ;

      oSlideshowTopMargin_Left.style.display     = 'none' ;
      oSlideshowTopMargin_Right.style.display    = 'none' ;
      oSlideshowBottomMargin_Left.style.display  = 'none' ;
      oSlideshowBottomMargin_Right.style.display = 'none' ;

      bControlsVisible = true ;
    }

    if (!bShow && bControlsVisible)
    {
      oSlideshowTop.style.display    = 'none' ;
      oSlideshowBottom.style.display = 'none' ;
      ResizeLayout () ;

      oSlideshowTopMargin_Left.style.display     = 'inline' ;
      oSlideshowTopMargin_Right.style.display    = 'inline' ;
      oSlideshowBottomMargin_Left.style.display  = 'inline' ;
      oSlideshowBottomMargin_Right.style.display = 'inline' ;

      bControlsVisible = false ;
    }
  }

  oMarginTimeout = false ;
}

function MouseOverMargin (sMargin, bShow)
{
  if ((sMargin == '') || (sMargin == sActiveMargin))
  {
    if (oMarginTimeout)
    {
      clearTimeout (oMarginTimeout) ;
      oMarginTimeout = false ;
    }

    if (!bControlsLocked) oMarginTimeout = setTimeout ('MarginTimeout (' + bShow + ') ;', !bShow ? 500 : 200) ;
  }
}

function PageLoad ()
{
  var idx, obj ;

  oGalleryBottom                   = document.getElementById ('galleryBottom') ;
  oGalleryControls                 = document.getElementById ('galleryControls') ;
  oGalleryMiddle                   = document.getElementById ('galleryMiddle') ;
  oGalleryTop                      = document.getElementById ('galleryTop') ;
  oGetHTMLCode                     = document.getElementById ('getHTMLCode') ;
  oGetHTMLMain                     = document.getElementById ('getHTMLMain') ;
  oHelpMain                        = document.getElementById ('helpMain') ;
  oMainLeft                        = document.getElementById ('mainLeft') ;
  oMainRight                       = document.getElementById ('mainRight') ;
  oSlideshowAD0                    = document.getElementById ('slideshowAD0') ;
  oSlideshowAD1                    = document.getElementById ('slideshowAD1') ;
  oSlideshowBottom                 = document.getElementById ('slideshowBottom') ;
  oSlideshowControls_DelaySecs     = document.getElementById ('slideshowControls_DelaySecs') ;
  oSlideshowControls_DelaySet      = document.getElementById ('slideshowControls_DelaySet') ;
  oSlideshowControls_ImageNext     = document.getElementById ('slideshowControls_ImageNext') ;
  oSlideshowControls_ImagePrev     = document.getElementById ('slideshowControls_ImagePrev') ;
  oSlideshowControls_ImageProgress = document.getElementById ('slideshowControls_ImageProgress') ;
  oSlideshowControls_Start         = document.getElementById ('slideshowControls_Start') ;
  oSlideshowControls_Stop          = document.getElementById ('slideshowControls_Stop') ;
  oSlideshowGetHTMLButton          = document.getElementById ('slideshowGetHTMLButton') ;
  oSlideshowHelpButton             = document.getElementById ('slideshowHelpButton') ;
  oSlideshowImage                  = document.getElementById ('slideshowImage') ;
  oSlideshowImage_BottomMargin     = document.getElementById ('slideshowImage_BottomMargin') ;
  oSlideshowImage_LowerLinks       = document.getElementById ('slideshowImage_LowerLinks') ;
  oSlideshowImage_LowerPadding     = document.getElementById ('slideshowImage_LowerPadding') ;
  oSlideshowImage_TopMargin        = document.getElementById ('slideshowImage_TopMargin') ;
  oSlideshowMiddle                 = document.getElementById ('slideshowMiddle') ;
  oSlideshowTop                    = document.getElementById ('slideshowTop') ;

  sActiveMargin = (document.getElementById ('slideshowTopMarginB') &&
   document.getElementById ('slideshowBottomMarginB')) ? 'B' : 'A' ;

  oSlideshowBottomMargin        = document.getElementById ('slideshowBottomMargin' + sActiveMargin) ;
  oSlideshowBottomMargin_Left   = document.getElementById ('slideshowBottomMargin' + sActiveMargin + '_Left') ;
  oSlideshowBottomMargin_Right  = document.getElementById ('slideshowBottomMargin' + sActiveMargin + '_Right') ;
  oSlideshowBottomMargin_Spacer = document.getElementById ('slideshowBottomMargin' + sActiveMargin + '_Spacer') ;
  oSlideshowTopMargin           = document.getElementById ('slideshowTopMargin' + sActiveMargin) ;
  oSlideshowTopMargin_Left      = document.getElementById ('slideshowTopMargin' + sActiveMargin + '_Left') ;
  oSlideshowTopMargin_Right     = document.getElementById ('slideshowTopMargin' + sActiveMargin + '_Right') ;
  oSlideshowTopMargin_Spacer    = document.getElementById ('slideshowTopMargin' + sActiveMargin + '_Spacer') ;

  oaSlideshowLayoutRows = [] ;
  idx = 0 ; while (obj = document.getElementById ('slideshowLR' + idx)) oaSlideshowLayoutRows [idx ++] = obj ;

  oGalleryControls.innerHTML =
   'Gallery mode: &nbsp; <a class="underlined" href="javascript: ViewAsSlideshow (true) ;">View as Slideshow</a>' ;

  DisableAnchor (oSlideshowControls_Start,     true) ;
  DisableAnchor (oSlideshowControls_Stop,      true) ;
  DisableAnchor (oSlideshowControls_DelaySet,  true) ;
  DisableAnchor (oSlideshowControls_ImagePrev, true) ;
  DisableAnchor (oSlideshowControls_ImageNext, true) ;

  bAdFramesAvailable    = (oSlideshowAD0 && oSlideshowAD1) ? true : false ;
  bAdFramesHidden       = (oSlideshowAD0 && oSlideshowAD1) ? false : true ;
  bAutoRunSlideshow     = true ;
  bControlsLocked       = false ;
  bControlsVisible      = true ;
  bImageMinDimsLoaded   = false ;
  bLocationChanged      = false ;
  bPreloadActive        = false ;
  bSettingsLoaded       = false ;
  bSlideshowMode        = true ;
  iAD0Height            = oSlideshowAD0 ? oSlideshowAD0.offsetHeight : 0 ;
  iAD0Width             = oSlideshowAD0 ? oSlideshowAD0.offsetWidth : 0 ;
  iAD1Height            = oSlideshowAD1 ? oSlideshowAD1.offsetHeight : 0 ;
  iAD1Width             = oSlideshowAD1 ? oSlideshowAD1.offsetWidth : 0 ;
  iCurrentImage         = - 1 ;
  iImageMaxHeight       = 0 ;
  iImageMaxWidth        = 0 ;
  iImageMinHeight       = 240 ;
  iImageMinWidth        = 240 ;
  iSlideshowLinksHeight = 0 ;
  iSlideshowDelaySecs   = 7 ;
  iWindowHeight         = 0 ;
  iWindowWidth          = 0 ;
  iaImageHeights        = [] ;
  iaImageWidths         = [] ;
  oFocusedElement       = false ;
  oGetHTMLLayerTimeout  = false ;
  oHelpLayerTimeout     = false ;
  oMarginTimeout        = false ;
  oPreloadedImage       = new Image () ;
  oSlideshowTimeout     = false ;

  oPreloadedImage.onload  = PreloadImage_Ok ;
  oPreloadedImage.onerror = PreloadImage_Error ;
  oPreloadedImage.onabort = PreloadImage_Error ;

  AjaxRequest ('POST', 'http://www.azgalleries.com/settings.php', true, LoadSettings) ;

  DisableTextSelection (oGalleryTop) ;
  DisableTextSelection (oGalleryMiddle) ;
  DisableTextSelection (oGalleryBottom) ;
  DisableTextSelection (oSlideshowTop) ;
  DisableTextSelection (oSlideshowMiddle) ;
  DisableTextSelection (oSlideshowBottom) ;
}

function PageUnload () {}

function PreloadImage ()
{
  if (!bPreloadActive && (saImageUrls.length > iaImageWidths.length))
  {
    bPreloadActive = true ;
    oPreloadedImage.src  = saImageUrls [iaImageWidths.length] ;
  }
}

function PreloadImage_Error ()
{
  bPreloadActive = false ;
  PreloadImage () ;
}

function PreloadImage_Ok ()
{
  bPreloadActive = false ;

  iaImageWidths  [iaImageWidths.length]  = oPreloadedImage.width ;
  iaImageHeights [iaImageHeights.length] = oPreloadedImage.height ;

  if (iCurrentImage == - 1)
  {
    if (bAutoRunSlideshow) RunSlideshow (true, false) ;
    else ChangeImage (1, false) ;

    if (!bControlsLocked && !oMarginTimeout) oMarginTimeout = setTimeout ('MarginTimeout (false) ;', 1000) ;

    oSlideshowImage_LowerLinks.style.visibility = 'visible' ;
  }

  if (iaImageWidths.length <= (iCurrentImage + 2)) PreloadImage () ;

  DisableAnchor (oSlideshowControls_Start,
   (oSlideshowTimeout || ((iCurrentImage > 0) && (iCurrentImage >= (iaImageWidths.length - 1)))) ? true : false) ;

  DisableAnchor (oSlideshowControls_ImageNext, iCurrentImage >= (iaImageWidths.length - 1) ? true : false) ;
}

function ResizeImage (bSecondPass)
{
  if (iCurrentImage == - 1)
  {
    //var iImageMaxHeight = iImageMaxHeight + iSlideshowLinksHeight ;

    var i = oSlideshowImage.height ;

    var iTopMargin    = Math.round ((iImageMaxHeight - i) / 2) ;
    var iBottomMargin = iImageMaxHeight - i - iTopMargin ;

    i = Math.round (iSlideshowLinksHeight / 2) ;

    iTopMargin += i ;
    iBottomMargin -= iSlideshowLinksHeight - i ;

    oSlideshowImage_TopMargin.height    = 1 + iTopMargin ;
    oSlideshowImage_BottomMargin.height = 1 + iBottomMargin ;
  }
  else
  {
    var iImageMaxWidth_Resize = iImageMaxWidth - 16 ;
    if (!bAdFramesHidden) iImageMaxWidth_Resize -= (iAD0Width + iAD1Width) ;
    if (iImageMaxWidth_Resize < iImageMinWidth) iImageMaxWidth_Resize = iImageMinWidth ;

    var iNewWidth, iNewHeight, iTopMargin, iBottomMargin ;

    var fAspectRatio_Max   = iImageMaxWidth_Resize / iImageMaxHeight ;
    var fAspectRatio_Image = iaImageWidths [iCurrentImage] / iaImageHeights [iCurrentImage] ;

    if (fAspectRatio_Image < fAspectRatio_Max)
    {
      var i = Math.round (iaImageWidths [iCurrentImage] * iImageMaxHeight / iaImageHeights [iCurrentImage]) ;

      iNewWidth     = i ;
      iNewHeight    = iImageMaxHeight ;
      iTopMargin    = 0 ;
      iBottomMargin = 0 ;
    }
    else if (fAspectRatio_Image > fAspectRatio_Max)
    {
      var i = Math.round (iaImageHeights [iCurrentImage] * iImageMaxWidth_Resize / iaImageWidths [iCurrentImage]) ;

      iNewWidth     = iImageMaxWidth_Resize ;
      iNewHeight    = i ;
      iTopMargin    = Math.round ((iImageMaxHeight - i) / 2) ;
      iBottomMargin = iImageMaxHeight - i - iTopMargin ;
    }
    else
    {
      iNewWidth     = iImageMaxWidth_Resize ;
      iNewHeight    = iImageMaxHeight ;
      iTopMargin    = 0 ;
      iBottomMargin = 0 ;
    }

    if (!bShowAdsWideImages && !bSecondPass && bAdFramesAvailable && !bAdFramesHidden && (iTopMargin || iBottomMargin))
    {
      oSlideshowAD0.style.display = 'none' ;
      oSlideshowAD1.style.display = 'none' ;
      bAdFramesHidden = true ;
      ResizeImage (true) ;
    }
    else if (!bShowAdsWideImages && !bSecondPass && bAdFramesAvailable &&
     bAdFramesHidden && ((iWindowWidth - iNewWidth) >= (16 + iAD0Width + iAD1Width)))
    {
      oSlideshowAD0.style.display = 'table-cell' ;
      oSlideshowAD1.style.display = 'table-cell' ;
      bAdFramesHidden = false ;
      ResizeImage (true) ;
    }
    else
    {
      oSlideshowImage.width  = iNewWidth
      oSlideshowImage.height = iNewHeight ;

      oSlideshowImage_TopMargin.height    = 1 + iTopMargin ;
      oSlideshowImage_BottomMargin.height = 1 + iBottomMargin ;
    }
  }
}

function ResizeLayout ()
{
  iImageMaxWidth  = iWindowWidth ;
  iImageMaxHeight = iWindowHeight - 2 ;

  var idx = 0 ; while (typeof oaSlideshowLayoutRows [idx] != 'undefined')
   iImageMaxHeight -= oaSlideshowLayoutRows [idx ++].offsetHeight ;

  if (iImageMaxWidth  < iImageMinWidth)  iImageMaxWidth  = iImageMinWidth ;
  if (iImageMaxHeight < iImageMinHeight) iImageMaxHeight = iImageMinHeight ;

  oSlideshowTopMargin_Spacer.width    = (iWindowWidth - 200) >= 32 ? iWindowWidth - 200 : 32 ;
  oSlideshowBottomMargin_Spacer.width = (iWindowWidth - 200) >= 32 ? iWindowWidth - 200 : 32 ;

  ResizeImage (false) ;
}

function ResizeSlideshow ()
{
  if (bSettingsLoaded && bSlideshowMode)
  {
    if (typeof (window.innerWidth) == 'number')
    {
      // Non-IE
      iWindowWidth  = window.innerWidth ;
      iWindowHeight = window.innerHeight ;
    }
    else if (document.documentElement &&
     (document.documentElement.clientWidth || document.documentElement.clientHeight))
    {
      // IE 6+ in 'standards compliant mode'
      iWindowWidth  = document.documentElement.clientWidth ;
      iWindowHeight = document.documentElement.clientHeight ;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight))
    {
      // IE 4 compatible
      iWindowWidth  = document.body.clientWidth ;
      iWindowHeight = document.body.clientHeight ;
    }
    else { iWindowWidth = 950 ; iWindowHeight = 600 ; }

    ResizeLayout () ;
  }
}

function RunSlideshow (bRun, bClicked)
{
  if (bRun && !oSlideshowTimeout && (iCurrentImage < (iaImageWidths.length - 1))) SlideshowTimeout () ;

  if (!bRun && oSlideshowTimeout)
  {
    clearTimeout (oSlideshowTimeout) ;
    oSlideshowTimeout = false ;
  }

  DisableAnchor (oSlideshowControls_Start,
   (oSlideshowTimeout || ((iCurrentImage > 0) && (iCurrentImage >= (iaImageWidths.length - 1)))) ? true : false) ;
  DisableAnchor (oSlideshowControls_Stop, !oSlideshowTimeout ? true : false) ;

  if (bClicked) AjaxRequest ('POST', 'http://www.azgalleries.com/settings.php?runslideshow=' + bRun, true, false) ;
}

function SetDelay ()
{
  var i = parseInt (oSlideshowControls_DelaySecs.value) ;
  if ((typeof i == 'number') && !isNaN	(i))
  {
    if (i < 5)  i = 5 ;
    if (i > 30) i = 30 ;

    if (i != iSlideshowDelaySecs)
    {
      iSlideshowDelaySecs = i ;

      if (oSlideshowTimeout)
      {
        clearTimeout (oSlideshowTimeout) ;
        oSlideshowTimeout = setTimeout ('SlideshowTimeout () ;', iSlideshowDelaySecs * 1000) ;
      }

      AjaxRequest ('POST',
       'http://www.azgalleries.com/settings.php?slideshowdelaysecs=' + iSlideshowDelaySecs, true, false) ;
    }
  }

  oSlideshowControls_DelaySecs.value = iSlideshowDelaySecs ;

  DisableAnchor (oSlideshowControls_DelaySet, true) ;
}

function ShowGetHTMLLayer (event, bShow)
{
  if (oGetHTMLLayerTimeout)
  {
    clearTimeout (oGetHTMLLayerTimeout) ;
    oGetHTMLLayerTimeout = false ;
  }

  oGetHTMLLayerTimeout = setTimeout
   ('GetHTMLLayerTimeout (' + bShow + ', ' + event.clientX + ', ' + event.clientY + ') ;', !bShow ? 500 : 200) ;
}

function ShowHelpLayer (event, bShow)
{
  if (oHelpLayerTimeout)
  {
    clearTimeout (oHelpLayerTimeout) ;
    oHelpLayerTimeout = false ;
  }

  oHelpLayerTimeout = setTimeout
   ('HelpLayerTimeout (' + bShow + ', ' + event.clientX + ', ' + event.clientY + ') ;', !bShow ? 500 : 200) ;
}

function SlideshowTimeout ()
{
  if (iCurrentImage < (iaImageWidths.length - 1))
  {
    ChangeImage (1, false) ;
    oSlideshowTimeout = setTimeout ('SlideshowTimeout () ;', iSlideshowDelaySecs * 1000) ;
  }
  else
  {
    RunSlideshow (false, false) ;
    if (!bLocationChanged) { bLocationChanged = true ; location.href = sWebsiteUrl ; }
  }
}

function ViewAsGallery (bClicked)
{
  if (bSettingsLoaded && (bSlideshowMode || !bClicked))
  {
    RunSlideshow (false, false) ;
    bSlideshowMode = false ;

    oSlideshowImage_TopMargin.height    = 1 ;
    oSlideshowImage_BottomMargin.height = 1 ;

    oSlideshowTopMargin_Spacer.width    = 8 ;
    oSlideshowBottomMargin_Spacer.width = 8 ;

    oSlideshowBottom.style.display = 'none' ;
    oSlideshowMiddle.style.display = 'none' ;
    oSlideshowTop.style.display    = 'none' ;

    oMainLeft.className  = 'vat' ;
    oMainRight.className = 'vat' ;

    oGalleryTop.style.display    = 'block' ;
    oGalleryMiddle.style.display = 'block' ;
    oGalleryBottom.style.display = 'block' ;

    if (bAdFramesAvailable && bAdFramesHidden)
    {
      oSlideshowAD0.style.display = 'table-cell' ;
      oSlideshowAD1.style.display = 'table-cell' ;
    }
  }

  if (bClicked) AjaxRequest ('POST', 'http://www.azgalleries.com/settings.php?slideshowmode=false', true, false) ;
}

function ViewAsSlideshow (bClicked)
{
  if (bSettingsLoaded && (!bSlideshowMode || !bClicked))
  {
    if (bAdFramesAvailable && bAdFramesHidden)
    {
      oSlideshowAD0.style.display = 'none' ;
      oSlideshowAD1.style.display = 'none' ;
    }

    oGalleryBottom.style.display = 'none' ;
    oGalleryMiddle.style.display = 'none' ;
    oGalleryTop.style.display    = 'none' ;

    oMainLeft.className  = 'vam' ;
    oMainRight.className = 'vam' ;

    oSlideshowTop.style.display    = 'block' ;
    oSlideshowMiddle.style.display = 'block' ;
    oSlideshowBottom.style.display = 'block' ;

    if (!bImageMinDimsLoaded)
    {
      var i ;

      iSlideshowLinksHeight = oSlideshowImage_LowerPadding.offsetHeight + oSlideshowImage_LowerLinks.offsetHeight ;

      i = oSlideshowImage_LowerLinks.offsetWidth ;
      if (i > iImageMinWidth) iImageMinWidth = i ;

      if (oSlideshowAD0)
      {
        i = iAD0Height - iSlideshowLinksHeight ;
        if (i > iImageMinHeight) iImageMinHeight = i ;
      }

      if (oSlideshowAD1)
      {
        i = iAD1Height - iSlideshowLinksHeight ;
        if (i > iImageMinHeight) iImageMinHeight = i ;
      }

      bImageMinDimsLoaded = true ;
    }

    bSlideshowMode = true ;
    ResizeSlideshow () ;
    if (iCurrentImage == - 1) PreloadImage () ;
  }

  if (bClicked) AjaxRequest ('POST', 'http://www.azgalleries.com/settings.php?slideshowmode=true', true, false) ;
}

/*
var sLocation = location.toString () ;
if (sLocation.length && !sLocation.match (/http\:\/\/([-_0-9a-z]+\.)?azgalleries\.com(\/.*)?/))
 alert ('ATTENTION: This website is using copyrighted code stolen from http://www.azgalleries.com') ;
*/
