
function hider (sID) {
  var sObj = document.getElementById(sID);
  var timeFunc = function () { sObj.style.visibility='visible';};
  setTimeout(timeFunc, Math.random() * 1000);
}

function draw_blocks (rows, cols) {
  this.document.open();
  this.document.writeln('<div style="position:absolute; right:0; top:100; z-index:18;"><nobr>');

  for (x = 0; x < rows; x++) {
    for (y = 0; y < cols; y++) {
      var num = 5;
      var image_num = Math.round(Math.random() * num);
      if (image_num != num)
        document.write('<img id="blk' + x.toString().concat(y.toString()) + '" onLoad="hider(this.id)" style="visibility:hidden;" src="../images/onetile' + image_num + '.gif" border="0">');
    }
    document.writeln('<br>');
  }

  this.document.writeln('</div>');
  this.document.close();
}

function revealer (imgArray, iName) {
  var pattern = /^.*\/(\w+)_.*/;
  var match = pattern.exec(iName);

  for (var x in imgArray) {
    document.getElementById(imgArray[x]).style.visibility="hidden";
  }

  document.getElementById(match[1]).style.visibility="visible";
}

var numLoaded = 0;

// separate the resize code so we can call it from onLoad event
function imgLoadHandler (iRef, iWT, iWR, iLT, iLR) {

    if (document.getElementById(iRef).width > document.getElementById(iRef).height) {
      document.getElementById(iRef).height="234";
      document.getElementById(iRef).width="335";
      document.getElementById(iRef + 'div').style.top=iWT;
      document.getElementById(iRef + 'div').style.right=iWR;
    } else {
      document.getElementById(iRef).width="239";
      document.getElementById(iRef).height="328";
      document.getElementById(iRef + 'div').style.top=iLT;
      document.getElementById(iRef + 'div').style.right=iLR;
    }

    numLoaded++;
}

function draw_images (iDisplayWideTop, iDisplayWideRight, iDisplayLongTop, iDisplayLongRight, imgArray, imgPath) {
  this.document.open();

  for (var x in imgArray) {
    var iRef = imgArray[x];

    this.document.writeln('<div id="' + iRef + 'div" style="position:absolute;visibility:hidden;right:100;top:0;z-index:30;">');
    this.document.writeln('  <img onLoad="javascript:imgLoadHandler(\'' + iRef + '\',' + iDisplayWideTop + ',' + iDisplayWideRight + ',' + iDisplayLongTop + ',' + iDisplayLongRight+ ');" border="0" id="' + iRef + '" src="'+ imgPath + iRef + '.jpg">');
    this.document.writeln('</div>');
  }

  this.document.close();

  while (1) {
    if (imgArray.length > numLoaded) {
      return 1;
    }
  }
}

