/* <![CDATA[ */
var thumbLink;
var thumbClassName = 'imageVisited';



function showBigImage (link)
{
  //if (link && link.firstChild && (link.firstChild.nodeType==1)) thumbLink = link;
  thumbLink = link;           // ulozeni na odkaz nahledu
  setAsVisited();
  hidePage();
  showCount();
  setDetailProperties(link);
  setNavigation();
}



function showCount ()
{
  var i      = 1;
  var number = document.getElementById('imageNumber');
  var count  = document.getElementById('imageCount');
  if (isObject(number) && isObject(count))
  {
    number.firstChild.data = parseIndexFromID(thumbLink.id);
    while (isObject(document.getElementById(createID(i))))
    {
      count.firstChild.data = i;
      i++;
    }
  }
}



function hideBigImage ()
{
  unsetDetailProperties();
  showPage();
  if (thumbLink) thumbLink.focus();     // posun stranky zpet na nahled
  thumbLink=null;
  setNavigation();
}



function existsPrevious ()
{
  return isObject(getOtherLink(thumbLink, -1));
}

function existsNext ()
{
  return isObject(getOtherLink(thumbLink, 1));
}

function getOtherLink (link, step)
{
  var newLink;
  if (isObject(link)) newLink = document.getElementById(createID(parseIndexFromID(link.id)+step));
  return newLink;
}



function showPrevious ()
{
  showOther(thumbLink, -1);
}

function showNext ()
{
  showOther(thumbLink, 1);
}

function showOther (link, step)
{
  unsetDescription();
  showBigImage(getOtherLink(link, step));
}



function setAsVisited ()
{
  if (thumbLink)
  {
    thumbLink.setAttribute('class', thumbClassName);            // nastavi CSS tridu navstivene fotky
    thumbLink.className = thumbClassName;                       // nastavi CSS tridu navstivene fotky
  }
}



function setNavigation ()
{
  var prev = document.getElementById('bigImage-prev');
  var next = document.getElementById('bigImage-next');
  if (isObject(prev) && (isObject(next)))
  {
    prev.style.visibility = ((existsPrevious())? 'visible' : 'hidden');
    next.style.visibility = ((existsNext())? 'visible' : 'hidden');
  }
}



function setDetailProperties (link)
{
  var image = getImageInFrame();
  var text  = getLinkText(link);          // vyzvednuti textu - popisu z odkazu
  //image.src = link.href;                // nacteni velke fotky
  //image.alt = text;                     // nastaveni ALT velke fotky podle ALT nahledu
  image.setAttribute('src', link.href);   // nacteni velke fotky
  image.setAttribute('alt', text);        // nastaveni ALT velke fotky podle ALT nahledu
  setDescription(link, text);             // nastaveni popisu
}

function unsetDetailProperties ()
{
  var image = getImageInFrame();
  //image.src = '/images/web/bigImageBackgroundColor.png';
  //image.alt = '';                          // vymazani ALT velke fotky
  image.setAttribute('src', '/images/web/bigImageBackgroundColor.png');
  image.setAttribute('alt', '');             // vymazani ALT velke fotky
  unsetDescription();
}



function setDescription (link, text)
{
  var image       = getImageInFrame();
  var description = getDescription();
  if (text!='' && text!=basename(link.href))
  {
    description.appendChild(document.createTextNode(text)); // nastaveni popisu pod velkou fotkou podle ALT nahledu
    image.style.paddingBottom = '40px';                     // roztazeni spodniho okraje velke fotky pro popis
  }
}

function unsetDescription ()
{
  var image       = getImageInFrame();
  var description = getDescription();
  var textNode    = description.firstChild;
  if (textNode) description.removeChild(textNode);     // vymazani popisu pod velkou fotkou
  if (image.style.paddingBottom=='40px') image.style.paddingBottom = '20px';
}



function hidePage ()
{
  document.getElementById('page').style.display = 'none';      // skryti stranky  
  getImageFrame().style.visibility = 'visible';                // zobrazeni ramu s velkou fotkou
}

function showPage ()
{
  getImageFrame().style.visibility = 'hidden';                  // skryti ramu s velkou fotkou
  document.getElementById('page').style.display = 'block';      // zobrazeni stranky
}



function getImageFrame ()
{
  return document.getElementById('bigImage');
}

function getImageInFrame ()
{
  return getImageFrame().firstChild;
}

function getDescription ()
{
  return getImageFrame().lastChild;
}



function parseIndexFromID (id)
{
  return (id.replace(/^img(\d+)$/, "$1")*1);
}
function createID (index)
{
  return ('img'+index);
}

function getLinkText (link)
{
  return ((link.firstChild)? ((link.firstChild.nodeType==1)? link.firstChild.alt : link.firstChild.nodeValue) : '');
}

function basename (filename)
{
  return filename.replace(/^.*[\/\\]/g, '');
}

function isObject (variable)
{
  return (variable !== null) && (typeof(variable) == 'object');
}
/* ]]> */
