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

function AutoSelectChanged (obj, idx)
{
  var iSelectedIndex = obj.selectedIndex ;
  if (iSelectedIndex != iaASSelectedIndexes [idx])
  {
    iaASSelectedIndexes [idx] = iSelectedIndex ;
    obj.form.submit () ;
  }
}

function PageLoad ()
{
  var idx, obj ;

  idx = 0 ; while (obj = document.getElementById ('AutoSelect' + (idx ++) + '_Form')) obj.reset () ;

  iaASSelectedIndexes = [] ;
  idx = 0 ; while (obj = document.getElementById ('AutoSelect' + idx))
   iaASSelectedIndexes [idx ++] = obj.selectedIndex ;

  if (bEnableThumbPreviews)
  {
    iCurrentThumb         = 0 ;
    iNumThumbsPreloaded   = 1 ;
    iThumbPreviewActive   = - 1 ;
    oThumbChangerTimeout  = false ;
    oThumbLauncherTimeout = false ;
    oPreloadedThumb       = new Image () ;
    saThumbURLs           = [] ;
  }

  if (typeof (iaNewThumbs) != 'undefined')
  {
    var num, container ;
    if ((num = iaNewThumbs.length) && (container = document.getElementById ('Thumbs')))
    {
      var newobj ;
      for (var i = 0 ; i < num ; i ++) if (!document.getElementById ('NewThumbImg' + i) &&
       (obj = document.getElementById ('Thumb' + iaNewThumbs [i])) && (newobj = document.createElement ('img')))
      {
        newobj.setAttribute ('id',     'NewThumbImg' + i) ;
        newobj.setAttribute ('src',    sImagesRoot + 'new.gif') ;
        newobj.setAttribute ('width',  '30') ;
        newobj.setAttribute ('height', '15') ;

        newobj.style.position = 'absolute' ;
        newobj.style.left     = (GetAbsoluteXPosition (obj, container) + 1 + 150) + 'px' ;
        newobj.style.top      = (GetAbsoluteYPosition (obj, container) + 1) + 'px' ;

        container.appendChild (newobj) ;

        obj.className = 'new' ;
      }
    }
  }

  DisableTextSelection (document.body) ;
}

function PageUnload ()
{
  var idx, obj ;

  idx = 0 ; while (obj = document.getElementById ('AutoSelect' + (idx ++) + '_Form')) obj.reset () ;
}

function ThumbChangerTimeout ()
{
  if ((iThumbPreviewActive != - 1) && oThumbChangerTimeout)
  {
    var i = iCurrentThumb + 1 ; if (i >= iNumThumbsPreloaded) i = 0 ;
    if (i != iCurrentThumb)
    {
      iCurrentThumb = i ;
      document.getElementById ('Thumb' + iThumbPreviewActive).src = saThumbURLs [iCurrentThumb] ;
    }

    oThumbChangerTimeout = setTimeout ('ThumbChangerTimeout () ;', 600) ;
  }
}

function ThumbGotMouse (obj, idx)
{
  if (idx == - 1) obj.className = obj.attributes ['className_bak'].nodeValue ;
  else
  {
    if (!obj.attributes ['className_bak']) obj.setAttribute ('className_bak', obj.className) ;
    obj.className = 'hover' ;
  }

  if (bEnableThumbPreviews && (typeof (iThumbPreviewActive) != 'undefined'))
  {
    if ((iThumbPreviewActive != - 1) && ((idx == - 1) || (idx != iThumbPreviewActive)))
    {
      document.getElementById ('Thumb' + iThumbPreviewActive).src = saThumbURLs [0] ;

      iThumbPreviewActive = - 1 ;

      oPreloadedThumb.onload = function () {}
      oPreloadedThumb.src = saThumbURLs [0] ;

      if (oThumbChangerTimeout)
      {
        clearTimeout (oThumbChangerTimeout) ;
        oThumbChangerTimeout = false ;
      }

      if (oThumbLauncherTimeout)
      {
        clearTimeout (oThumbLauncherTimeout) ;
        oThumbLauncherTimeout = false ;
      }

      saThumbURLs = [] ;
      iNumThumbsPreloaded = 1 ;
      iCurrentThumb = 0 ;
    }

    if ((iThumbPreviewActive == - 1) && (idx != - 1) && (typeof (saThumbIds [idx]) == 'string'))
    {
      var num = saThumbIds [idx].length ;
      if (!(num % 8))
      {
        num /= 8 ; if (num >= 2)
        {
          for (var i = 0 ; i < num ; i ++)
          {
            var hid = saThumbIds [idx].substr (i * 8, 8) ;
            saThumbURLs [i] = sThumbsRoot.substring (0, 15) == 'http://thumbs%d' ?
             sThumbsRoot.substring (0, 13) + (parseInt (hid.charAt (7), 16) % 4) + sThumbsRoot.substring (15) +
             hid.charAt (0) + '/' + hid.charAt (1) + '/' + hid.charAt (2) + '/' +
             hid.charAt (3) + '/' + hid.charAt (4) + '/' + hid.charAt (5) + '/' + hid + '.jpg' :
             sThumbsRoot +
             hid.charAt (0) + '/' + hid.charAt (1) + '/' + hid.charAt (2) + '/' +
             hid.charAt (3) + '/' + hid.charAt (4) + '/' + hid.charAt (5) + '/' +
             saThumbWebsites [idx] + '_' + hid + '.jpg' ;
          }

          iThumbPreviewActive = idx ;
          oThumbLauncherTimeout = setTimeout ('ThumbLauncherTimeout () ;', 500) ;
        }
      }
    }
  }
}

function ThumbLauncherTimeout ()
{
  if ((iThumbPreviewActive != - 1) && oThumbLauncherTimeout)
  {
    oPreloadedThumb.onload = ThumbPreloaded ;
    oPreloadedThumb.src = saThumbURLs [1] ;
  }

  oThumbLauncherTimeout = false ;
}

function ThumbPreloaded ()
{
  if (iThumbPreviewActive != - 1)
  {
    iNumThumbsPreloaded ++ ;

    if ((iNumThumbsPreloaded == 2) && !oThumbChangerTimeout)
     oThumbChangerTimeout = setTimeout ('ThumbChangerTimeout () ;', 10) ;

    if (iNumThumbsPreloaded < saThumbURLs.length) oPreloadedThumb.src = saThumbURLs [iNumThumbsPreloaded] ;
  }
}

/*
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') ;
*/
