// kidLib.js
// version 1.06, 4-5-05
// Copyright, Michael Robinton <michael@bizsystems.com>
// you may use this library for any purpose with attribution.
//
// *********** INSTRUCTIONS *************
//
// DEPENDENCIES: winUtils.js
//
// The page this library is used on must have a default picture of the form
// <div id="idkid" style="
//   position: absolute;
//   top: 1; 
//   left: 1;
//   z-index: 111;
//   visibility: hidden;
// ">
//
//
// and at the bottom of the page to activate navigator events for the mouse
//
// <script language=javascript>
// if (window.Event) {
//   document.captureEvents(Event.MOUSEOVER); // window, document, etc...
// }
// </script>
//
//
// to creat a linked popup picture put this in a javascript tag pair
// kidlink(
//	id/name of link
//	url of link
//	url link text
//	description text
//	image url
//	image alt text
// );
// ************ END INSTRUCTIONS *********

function kidlink(id,url,utext,text,img,alt) {
  document.writeln("<a id=" + id + 
    " href=" + url +
    " onMouseOver=\"return kidoverit(this,event);\" onMouseOut=\"return kidoffit();\"><img name=" + id + 
    " src=" + img +
    " alt=\"" + alt + "\"" +
    " width=72" +
    " align=right" +
    " vspace=1" + 
    " hspace=1" +
    " border=2></a><a href=" + url +
    ">" + utext + "</a> " + text + "<hr width=50% align=right>");
}


// the kid picture

var domkidpic = 0;

function kidoverit(that,e) {	// old versions of konq don't supply event
  if (!e) {
    e = window.event;
  }
  var img = new Image();
  var kx = eval('document.images.' + that.id);
  img.src = kx.src;
//alert(img.width + ' ' + img.height + ' ' + kx.width + ' ' + kx.height);
  window.status = kx.alt;
  if ( ! domkidpic ) {
    domkidpic = finDom('idkid',1);
  }
  domkidpic.visibility = 'hidden';
  document.kidpic.src = img.src;
  if (typeof(img.width) == 'number' && typeof(img.height) == 'number' && img.width > kx.width) {
    document.kidpic.width = img.width;  
    document.kidpic.height = img.height;
  }
  else {
    img.width = 0;			// flag img.width as a failure
  }
//alert(document.kidpic.src + ' ' + document.kidpic.width + ' ' + document.kidpic.height);
//  document.kidpic.alt = kx.alt;
  var wp = new Object();
  wp = findWinProp();
  var mouse = new Object();
  mouse = findCoords(e);
  var kidleft = kx.width;		// guess at mouse.x position if event failed
  if (mouse.valid > 0) {
    kidleft = mouse.x - wp.offx - img.width - kx.width - 20;
  }
  if (kidleft < 1 || img.width == 0) {
    kidleft = 10;
  }
  var kidtop = wp.offy + 30;
  domkidpic.left = kidleft; 
  domkidpic.top = kidtop;   
  domkidpic.visibility = 'visible';
/*  alert('mouse.valid = ' + mouse.valid + '  wp.invalid = ' + wp.invalid +'  mouse.x = ' + mouse.x + '  mouse.y = ' + mouse.y + "\n" +
'pageX = ' + e.pageX + '  clientX = ' + e.clientX + "\n" +
'pageY = ' + e.pageY + '  clientY = ' + e.clientY + "\n" +
'layerX = ' + e.layerX + ' offsetX = ' + e.offsetX + "\n" +
'layerY = ' + e.layerY + ' offsetY = ' + e.offsetY + "\n" +
'document.documentElement.scrollLeft = ' + document.documentElement.scrollLeft + "\n" +
'document.documentElement.scrollTop = ' + document.documentElement.scrollTop + "\n" +  
'document.body.scrollLeft = ' + document.body.scrollLeft + "\n" +
'document.body.scrollTop = ' + document.body.scrollTop + "\n" +  
'that.id = ' + that.id + ', kidpic.src = ' + kid.src + "\n" +  
'dom = ' + domkidpic + ' visibility = ' + domkidpic.visibility + "\n" +
'kidleft = ' + kidleft + ' kidtop = ' + kidtop + "\n" +
'img.width ' + img.width + ' kx.width ' + kx.width + "\n" +
'winx ' + wp.winx + ' winy ' + wp.winy + ' offx ' + wp.offx + ' offy ' + wp.offy + ' docx ' + wp.docx + ' docy ' + wp.docy +
' ');
 */
  return true;
}

function kidoffit() {
  domkidpic.visibility = 'hidden';
  window.status = '';
  return true;
}

