// class
function Obrazky()
{
  this.pics = new Array();

  /* konstrukcia noveho objektu <Obrazky> */
  if (document.images)
  { 		
    var j = this.pics.length;
    var args = Obrazky.arguments;
    for (var i=0; i<args.length; i++)
    {
      this.pics[j] = new Image();
      this.pics[j].src = args[i];
      this.pics[j].fitToArea = fitToArea;
      this.pics[j].getFilename = getFilename;
      j++;
    }
  }

  /* metoda kazdeho objektu <Image> z pola (pics) */
  function fitToArea(area_id, img_id)
  { // alert('fitToArea >>\n  area_id: '+area_id+'\n  img_id: '+img_id);
    var x = this.width, y = this.height;
    var R = x/y;
    //alert('x: ' + x + '\ny: ' + y + '\nR: ' + R);
    var area = document.getElementById(area_id).style;
    //alert('Area: ' + area.width + ' x ' + area.height);
    var W = parseInt(area.width, 10);
    var H = parseInt(area.height, 10);
    //alert(W + ' x ' + H);
    var nx=x, ny=y;
    //alert(nx + ' x ' + ny);
    if (x>W || y>H)
    { // obrazok presahuje oblast
      if ((ny=Math.round(W/R)) <= H) nx=W;
      else if ((nx=Math.round(H*R)) <= W) ny=H;
    }
    var img = document.getElementById(img_id);
    img.style.width = nx + 'px';
    img.style.height = ny + 'px';
    img.style.marginLeft = Math.round((W-nx)/2) + 'px';
    img.style.marginTop = Math.round((H-ny)/2) + 'px';
    img.src=this.src;
    //alert('area: '+W+' x '+H+'\nsrc: '+this.src+'\nimage: '+x+' x '+y+
    // '\nR = '+R+'\nnx = '+nx+'\nny = '+ny+
    // '\nimg.width = '+img.width+'\nimg.height = '+img.height);
  }
  
  /* getFilename */
  function getFilename()
  {
    var txt = this.src;
    var pom = 0;
    while ((txt.indexOf('/', pom)) !=-1)
    {
      pom = txt.indexOf('/', pom);
      pom += 1;
    }
    return txt.substr(pom);
  }

}
