var
  g_bGalleryRotate = true;

function LC2_GalleryRotate_Init(sId)
{
  window.setTimeout('LC2_GalleryRotate_Next("' + sId + '")', 10000);
}

function LC2_GalleryRotate_Next(sId)
{
  var
    oGallery, nSelected, aoImg, nNext;
    
  oGallery = GetElem(sId);
  if (oGallery != null && g_bGalleryRotate)
  {
    nSelected = Number(oGallery.getAttribute('selected'));
    if (!isNaN(nSelected))
    {
      aoImg = oGallery.getElementsByTagName('img');
      if (aoImg.length >= 2)
      {
        nSelected = nSelected % aoImg.length;
        nNext = (nSelected + 1) % aoImg.length;
        if (oGallery.filters) oGallery.filters.item(0).Apply();
        aoImg[nSelected].style.display = 'none';
        aoImg[nNext].style.display = 'block';
        if (oGallery.filters) oGallery.filters.item(0).Play();
        oGallery.setAttribute('selected', nNext);
        window.setTimeout('LC2_GalleryRotate_Next("' + sId + '")', 10000);
      }
    }
  }
}

function LC_GalleryRotate_Select(sId, nSelected)
{
  var
    oGallery, bHasJQ, aoImg, nIndex;
    
  oGallery = GetElem(sId);
  if (oGallery != null)
  {
    bHasJQ = typeof($) != 'undefined';
    if (bHasJQ) $('#videocontainer').empty();
    aoImg = oGallery.getElementsByTagName('img');
    if (aoImg.length > 0)
    {
      oGallery.setAttribute('selected', 'set');
      nSelected = nSelected % aoImg.length;
      for (nIndex = 0; nIndex < aoImg.length; nIndex++)
      {
        aoImg[nIndex].style.display = (nSelected == nIndex ? 'block' : 'none');
      }
      if (bHasJQ && $(aoImg[nSelected]).hasClass('galleryImageHasVideo'))
      {
        LC2_Gallery_PlayVideo(aoImg[nSelected]);
      }
    }
  }
  return false;
}

function LC2_Gallery_PlayFirstVideo()
{
  var
    aoImg;
    
  aoImg = $('#galleryrotate img.galleryImageHasVideo');
  if (aoImg.length > 0)
  {
    LC2_Gallery_PlayVideo(aoImg.get(0));
  }
}

function LC2_Gallery_PlayVideo(oImg)
{
  var
    sVideoUrl, oOptions;
    
  g_bGalleryRotate = false;
  sVideoUrl = oImg.src.replace(/\.[a-z]+$/g, '.mp4');
  oOptions = { src: sVideoUrl,
               width: oImg.width,
               height: oImg.height,
               autoPlay: true,
               bufferingOverlay: false };
  $('#videocontainer').empty();
  $('<div id="videoplayer"></div>').css({width:oOptions.width+'px',height:oOptions.height+'px'}).appendTo($('#videocontainer'));
  $('#galleryrotate img').css('display', 'none');
  $('#videoplayer').strobemediaplayback(oOptions);
}

function LC2_Tenders_OnSelectAll(bSelect)
{
  var
    aoCb, nIndex, oCb;
    
  aoCb = document.getElementsByTagName('input');
  for (nIndex = 0; nIndex < aoCb.length; nIndex++)
  {
    oCb = aoCb[nIndex];
    if (oCb.type == 'checkbox')
    {
      oCb.checked = bSelect;
    }
  }
  return false;
}

function LC2_Tenders_OnSelectSection(oA, bSelect)
{
  var
    oTr, oTable, nIndex, aoCb;
    
  oTr = oA.parentNode.parentNode.parentNode;
  oTable = oTr.parentNode;
  for (nIndex = oTr.rowIndex + 1; nIndex < oTable.rows.length; nIndex++)
  {
    aoCb = oTable.rows[nIndex].cells[0].getElementsByTagName('input');
    if (aoCb.length > 0)
    {
      aoCb[0].checked = bSelect;
    }
    else
    {
      break;
    }
  }
  return false;
}

