horus.cspot.gallery={};


horus.cspot.gallery.thumbfix=
  function () {
    for (var chunkid in horus.cspot.gallery.data) {
      var options=horus.cspot.gallery.data[chunkid];
      var gridsize=options.thumbgridsize;
      var wrapper=document.getElementById('thumblist'+chunkid);
      var wrapwidth=wrapper.offsetWidth;
      var perline=Math.floor(wrapwidth/gridsize);
      var offset=Math.floor((wrapwidth-gridsize*perline)/2);
      var therow=-1;
      var thecol=perline;

      for (var thisitem=horus.firstTag(wrapper, 'div.thumb');
	   thisitem; thisitem=horus.nextTag(thisitem, 'div.thumb')) {
	if (thecol>=perline) {
	  therow++;
	  thecol=0;
	  wrapper.style.height=((therow+1)*gridsize)+'px';
	}

	thisitem.style.top=(therow*gridsize)+'px';
	thisitem.style.left=(offset+thecol*gridsize)+'px';
	thisitem.style.display='';
	thecol++;
      }
    }
  };


horus.cspot.gallery.init=
  function () {
    for (var chunkid in horus.cspot.gallery.data) {
      var options=horus.cspot.gallery.data[chunkid];

      if (typeof options=='number')
	horus.cspot.gallery.data[chunkid]=horus.cspot.gallery.opt[options];

    }

    horus.cspot.gallery.thumbfix();

    for (var chunkid in horus.cspot.gallery.data)
      document.getElementById('loading'+chunkid).style.display='none';

    horus.resizeAction(horus.cspot.gallery.thumbfix);
  };


horus.afterLoad(horus.cspot.gallery.init);
