function centerPhoto(elImg)
{
  if ( elImg.parentNode )
  {
    elImg.style.left = parseInt( ( elImg.parentNode.offsetWidth -  2 - elImg.offsetWidth  ) / 2 ) + 'px';
    elImg.style.top  = parseInt( ( elImg.parentNode.offsetHeight - 2 - elImg.offsetHeight ) / 2 ) + 'px';
    elImg.style.visibility  = 'visible';
  }
}

function removeAllChildren(node)
{
  while ( node.hasChildNodes() )
  {
    node.removeChild(node.firstChild);
  }
}

function scrollPhoto(direction)
{
  var last;
  var linkTemp;

  last = photosCount - 1;

  repeat = direction > 0 ? direction : direction * ( -1 );

  for ( r = 0; r < repeat; r++ )
  {

    if ( direction > 0 )
    {
      linkTemp = images[0].href;
      elTemp = images[0].firstChild;

      images[0].removeChild(images[0].firstChild );

      for ( i = 0; i < last; i++ )
      {
        images[i].href = images[i+1].href;
        images[i].appendChild(images[i+1].firstChild );

        centerPhoto(images[i].firstChild);
      }
      
      images[last].href = linkTemp;
      images[last].appendChild(elTemp );

      centerPhoto(images[last].firstChild);

      actualPhoto++;
    }
    else
    {
      linkTemp = images[last].href;
      elTemp = images[last].firstChild;

      images[last].removeChild(images[last].firstChild );

      for ( i = last; i > 0; i-- )
      {
        images[i].href = images[i-1].href;
        images[i].appendChild(images[i-1].firstChild );

        centerPhoto(images[i].firstChild);
      }

      images[0].href = linkTemp;
      images[0].appendChild(elTemp );

      centerPhoto(images[0].firstChild);

      actualPhoto--;
    }

    actualPhoto = actualPhoto > photosCount ? 1 : actualPhoto;
    actualPhoto = actualPhoto < 1 ? photosCount : actualPhoto;

  }

  elPhotoCounter.removeChild(elPhotoCounter.firstChild );
  elPhotoCounter.appendChild(document.createTextNode(' ' + actualPhoto + ' / ' + photosCount + ' ' ) );
}

