/*
 * This script is writen by Michael Buckley.
 * Home page: http://codefisher.org/web_applications/hover_box

 * The code contained in these files are licensed under the
 * Attribution-ShareAlike 3.0 Unported. 

 * Furthermore;
 * You may not claim the works as your own.
 * You must provide a link back to codefisher.org when using on a website.
 * You may not redistribute these as a package as-is..
 * You must seek approval for commercial purposes, and for applications. 
 * 
 * Please don't remove this from this file.
 * if you want to contact me please use my contact page
 * http://codefisher.org/email 
 *
 * If you modify this script please give me credit for the original script.
 *
 * Linking back to me should you use this script is appreicated and required
 */

function showInfo(aEvent) {
 var target = getBox(aEvent);
 if(!target.hover_box){
  var hover_box = document.createElement('div');
  hover_box.className = 'hover-box';
  var new_image = target.cloneNode(true);
  new_image.removeAttribute('width');
  new_image.removeAttribute('height');
  var aSpan = document.createElement('span');
  aSpan.textContent = target.getAttribute('alt');
  hover_box.appendChild(new_image);
  hover_box.appendChild(aSpan);
  target.hover_box = document.body.appendChild(hover_box);
 }
 target.hover_box.style.display = 'block';
}

function hideInfo(aEvent) {
 var target = getBox(aEvent);
 if(target.hover_box){
  target.hover_box.style.display = 'none';
 }
}
function moveInfo(aEvent){
 var target = getBox(aEvent);
 if(target.hover_box){
   target.hover_box.style.top = (aEvent.clientY + document.documentElement.scrollTop + 15) + 'px';
   target.hover_box.style.left = (aEvent.clientX + 15) + 'px';
 }
}


function init_hover_box(){
 var images = document.images;
 var i = 0;
 while(images[i]){
  if(images[i].className.match('hoverimage')){
   setEventListener(images[i],'mouseover',showInfo,true);
   setEventListener(images[i],'mouseout',hideInfo,true);
   setEventListener(images[i],'mousemove',moveInfo,true);
  }
  i++;
 }
}

function getBox(aEvent){
 if(aEvent.srcElement){
  var target = aEvent.srcElement;
 } else {
  var target = aEvent.target;
 }
 return target;
}

function setEventListener(item,event,func,bool) {
 if(item.addEventListener){
	item.addEventListener(event,func,bool);
 } else {
	item.attachEvent('on'+event,func,bool);
 }
}

setEventListener(window,'load',init_hover_box,true);