/*
  based on script by Alessandro Fulciniti
  http://pro.html.it
-------------------------------------*/

function enableAcronym(id) {
  if(!document.getElementById || !document.getElementsByTagName) return;
  
  var links,i,node;
  
  node = document.createElement("span");
  node.id = "post-it";
  node.setAttribute("id","post-it");
  node.style.position = "absolute";
  document.getElementsByTagName("body")[0].appendChild(node);
  
  acronym = document.getElementById(id).getElementsByTagName("span");
  
  var links = new Array();
	
	var j = 0;	
	for (var i=0; i<acronym.length; i++) {
    if(acronym[i].className.indexOf("tooltip") != -1) {
      links[j] = acronym[i];
      j++;
    } 
  }
  
  for(i=0;i<links.length;i++){
    prepareNode(links[i]);
  }
}

function prepareNode(element) {
  var tooltip, title, strong, span, link;
  
  title = element.getAttribute("title");  
  if(title == null || title.length == 0) return;  
  element.removeAttribute("title");  
   
  /* span */ 
  tooltip = createElement("span","acronym");
  span = createElement("span","top");
  span.appendChild(document.createTextNode(title));
  tooltip.appendChild(span);    
  
  element.tooltip = tooltip;
  element.onmouseover = showAcronym;
  element.onmouseout = hideAcronym;
  element.onmousemove = setPosition;
}
 


function showAcronym(element) {      
  //setOpacity(0);  
  document.getElementById("post-it").appendChild(this.tooltip);   
  setPosition(element);   
  //_opacity = 0;
  //_interval = window.setInterval("makeOpaque()",10);     
}

function hideAcronym(element) {    
  var node = document.getElementById("post-it");
  if(node.childNodes.length > 0) node.removeChild(node.firstChild);  
  //window.clearInterval(_interval);
}

function makeOpaque() {  
  setOpacity(_opacity);
  _opacity = increment(_opacity);
}

function increment(number) { 
  number += 0.05;
  if (number > 0.95) window.clearInterval(_interval);
  return number;
}
function setOpacity(_opacity) {
  document.getElementById("post-it").style.opacity = _opacity;
  document.getElementById("post-it").style.KHTMLOpacity = _opacity;
  document.getElementById("post-it").style.filter = "alpha(opacity:" + _opacity*100 + ")";
}

function createElement(element,className) {
  var node = document.createElement(element); 
   
  node.className = className;
  node.style.display = "block";
  return(node);
}


function setPosition(node) {
  
  getPosition(node); 
  
  var x = coord[0];
  var y = coord[1];

  var boxWidth = 670;
  var toolWidth = 400;
  var portWidth = viewport.viewportSize().width;

  var a = x + toolWidth;
  var b = (portWidth + boxWidth)/2;
  
  if(a > b) {
    x = x - (a - b);  
  }
  
  //document.getElementById("control").innerHTML = ie + " : " + version ;
  
  document.getElementById("post-it").style.top = (y + 10) + "px";
  document.getElementById("post-it").style.left = (x + 5) + "px";
}



function getPosition(node) {
  var posx = 0, posy = 0;
  coord = new Array();
    
  if(node == null) node = window.event;
  if(node.pageX || node.pageY){
    posx = node.pageX; 
    posy = node.pageY;
      
  } else if(node.clientX || node.clientY){    
  
    if(document.documentElement.scrollTop){
      posx = node.clientX + document.documentElement.scrollLeft;
      posy = node.clientY + document.documentElement.scrollTop; 
                   
    } else {
      posx = node.clientX + document.body.scrollLeft;
      posy = node.clientY + document.body.scrollTop;
    }
  }
    
  coord[0] = posx;
  coord[1] = posy; 
  
  return coord;
}


var viewport = {  
  viewportSize: function() {
    return { 
      width: this.viewportWidth(), 
      height: this.viewportHeight() 
    };
  },
  
  viewportWidth: function() {
    return self.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);
  },
  
  viewportHeight: function() {
    return self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
  }   
};



