
var divmax = document.createElement('div');
var fotomax = document.createElement('img');
var popismax = document.createElement('div');
var divclose = document.createElement('div');

window.onload=function()
{
  divmax.setAttribute('id', 'divmax');
  divmax.style.display = 'none';

  fotomax.setAttribute('id', 'fotomax');
  popismax.setAttribute('id', 'popismax');
  divclose.setAttribute('id', 'close');
  divclose.innerHTML = 'close image';

  divmax.appendChild(fotomax);
  divmax.appendChild(popismax);
  divmax.appendChild(divclose);
  document.body.appendChild(divmax);
}

divmax.onclick = function()
{
  this.style.display = 'none';
}
        
function getScrollXY()
{
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' )
  {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  }
  else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  }
  else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getSize()
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' )
  {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  }
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
  {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  }
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
  {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [ myWidth , myHeight]
}

function pos(divmax,position,dimension,fotomax,popismax)
{
    //alert("dim0" + dimension[0] + " divmax" + divmax.offsetWidth);
    if (dimension[0] < divmax.offsetWidth)
    {
      fotomax.style.width = dimension[0] - 80 + "px";
      fotomax.style.height = "auto";
    }
    //alert("dim1" + dimension[1] + " divmax" + divmax.offsetHeight);
    if (dimension[1] < divmax.offsetHeight)
    {
      fotomax.style.height = dimension[1] - popismax.offsetHeight - 50 + "px";
      fotomax.style.width = "auto";
    }
    divmax.style.left = position[0] + (dimension[0] - divmax.offsetWidth)/2 + "px";
    divmax.style.top = position[1] + (dimension[1] - divmax.offsetHeight)/2 + "px";
    if (divmax.style.display == 'block')
      setTimeout(function(){pos(divmax,position,dimension,fotomax,popismax);},100);
}

function maximalize(img)
{

  var position = getScrollXY();
  var dimension = getSize();
  var foto = img.src;
  var desc = img.title;
  
  //var folders = foto.split('/');
  //var last = folders.pop();
  //folders.push('100');
  //folders.push(last);
  //foto = folders.join('/');

  divmax.style.display = "block";
  fotomax.src = foto;
  popismax.innerHTML = desc;
  fotomax.alt = desc;
  fotomax.style.width = "auto";
  fotomax.style.height = "auto";
  setTimeout(function(){pos(divmax,position,dimension,fotomax,popismax);},100);
  
}

