function enableTooltips(enableTooltipsContainer){
  var links,classes,i,j,h,btciframe;
  if(!document.getElementById || !document.getElementsByTagName) return;
  classes=getElementsWithTitleOrAlt(enableTooltipsContainer);
  if (classes.length > 0) {
    for (j = 0; j < classes.length; j++) {
	    Prepare(classes[j]);
    }
  }
}

function getElementsWithTitleOrAlt(node) {
	if(!node) node = document.getElementsByTagName("body")[0];
	var a = [];
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++) {
	  var elementForTitle = els[i];
		if(elementForTitle.title.length > 0) { 
		  a.push(elementForTitle);
		}
		//else if (elementForTitle.getAttribute("alt") != null && elementForTitle.getAttribute("alt").length > 0) {
		  //a.push(elementForTitle);
		//}
  }
	return a;
};

/**
 * Attaches a <strong class="highlight">event</strong> listener
 * @author sos
 * @param el {HTMLElement} The element to which you would attach this listener
 * @param ev {String} The <strong class="highlight">event</strong> name (eg. click)
 * @param fn {Function} The <strong class="highlight">event</strong> listener function
 */
function addEvent(el, ev, fn) {
    if(el.addEventListener) {
      el.addEventListener(ev, fn, false);
    }
    else {
      el.attachEvent('on' + ev, fn);
    }
}

function Prepare(el){
  var tooltip,t;
  t=el.getAttribute("title");
  if (t == null || t.length == 0) {
    t = el.getAttribute("alt");
  }
  if(t!=null && t.length>0 && el.className.indexOf('noToolTip') == -1) {
	  el.removeAttribute("title");
	  el.removeAttribute("alt");
	  tooltip=CreateEl("span","tooltip");
    tooltip.innerHTML = t;
	  el.tooltip=tooltip;
	  addEvent(el, 'mouseover', showTooltipEvent);
    addEvent(el, 'mouseout', hideTooltip);
    //el.onmouseover= showTooltip;  //delayTooltip;
	  //el.onmouseout=hideTooltip;
  }
}

function GetTarget(e) {
	var target;
	if (!e) var e = window.event;
	if (e.target) target = e.target;
	else if (e.srcElement) target = e.srcElement;
	if (target.nodeType == 3) // defeat Safari bug
		target = target.parentNode;
	return target;
}

function GetCurrentTarget(e) {
	var target;
	if (!e) var e = window.event;
	    //alert(e.currentTarget + ' ' + this.id);
	if (e.currentTarget) {
	  target = e.currentTarget;
	  if (target == this) {
	  }
	}
  return target;
}

function GetParent(el)
{
  if (el != null) {
	  return(el.parentNode || el.parentElement || el.offsetParent);
	}
	else { return null; }
}

function showTooltipEvent(e){

  var currentTarget = GetCurrentTarget(e);
  var target = GetTarget(e);
  if (target != null && target.tooltip != null) {
    if (currentTarget != null) {
      //CurrentTarget is supported, so make sure tip is only set once
      if (currentTarget == target) {
        Tip(target.tooltip.innerHTML);
      }
    }
    else {
      //CurrentTarget isnt supported, so set ToolTip multiple times while bubbling
      Tip(target.tooltip.innerHTML);
    }
  }
  else {
    //First check two types of parents before showing currentTargets tooltip, 
    //because of possible lvls of titles where showing the child's title is preferred
    var targetParent = GetParent(target);
    if (targetParent != null && targetParent.tooltip != null) {
      Tip(targetParent.tooltip.innerHTML);
    }
    else {
      //Check for 2nd lvl of parent
      targetParent = GetParent(targetParent);
      if (targetParent != null && targetParent.tooltip != null) {
        Tip(targetParent.tooltip.innerHTML);
      }
      else if (currentTarget != null && currentTarget.tooltip != null) {
        //target en target.parentElement dont have a tooltip, so current Tooltip can be shown
        Tip(currentTarget.tooltip.innerHTML);
      }
    }
  }
}

function showTooltip(e){
  Tip(this.tooltip.innerHTML);
}

function hideTooltip(e){
  UnTip();
}

//function setOpacity(el){
//el.style.filter="alpha(opacity:95)";
//el.style.KHTMLOpacity="0.95";
//el.style.MozOpacity="0.95";
//el.style.opacity="0.95";
//}

function CreateEl(t,c){
var x=document.createElement(t);
x.className=c;
x.style.display="block";
return(x);
}

//function AddCss(){
//return;
//var l=CreateEl("link");
//l.setAttribute("type","text/css");
//l.setAttribute("rel","stylesheet");
//l.setAttribute("href","bt.css");
//l.setAttribute("media","screen");
//document.getElementsByTagName("head")[0].appendChild(l);
//}

//function Locate(e){
//	var posx=0,posy=0,scrollX=0;
//	if (e==null) {
//	  e=window.event;
//	}
// 	if (e.pageX || e.pageY) {
//		alert('pageX: ' + e.pageX + ' - pageY: ' + e.pageY);
//		scrollX = window.pageXOffset;
//	    posx=e.pageX; posy=e.pageY;
//  } 
//  else if (e.clientX || e.clientY) {
//		scrollX = document.documentElement.scrollLeft;
//		
//		if (document.documentElement.scrollTop) {
//      posy=e.clientY+document.documentElement.scrollTop;
//    }
//    else {
//      posy=e.clientY+document.body.scrollTop;
//    }
//    if (document.documentElement.scrollLeft) {
//		  posx=e.clientX + document.documentElement.scrollLeft;
//    }
//    else {
//      posx=e.clientX+document.body.scrollLeft;
//    }
//	}
//	var tooltipWidth = 220;
//	var tooltipHeight = document.getElementById("btc").offsetHeight;
//	var sizes = sreenSize();
//	var posXdiff = ( (sizes[0] - e.clientX - 30) > tooltipWidth ? 20 : tooltipWidth + 30); //tooltipWidth - (sizes[0] - posx) - scrollX);
//	var posYdiff = ( (sizes[1] - e.clientY - 30) > tooltipHeight ? -10 : tooltipHeight + 30);

//	document.getElementById("btc").style.top=(posy-posYdiff)+"px";
//	document.getElementById("btc").style.left=(posx - posXdiff)+"px";
//	document.getElementById("btc-iframe").style.top=(posy-posYdiff)+"px";
//	document.getElementById("btc-iframe").style.left=(posx - posXdiff)+"px";
//}

//function sreenSize() {
//  var myWidth = 0, myHeight = 0;
//  if( typeof( window.innerWidth ) == 'number' ) {
//    //Non-IE
//    myWidth = window.innerWidth;
//    myHeight = window.innerHeight;
//  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//    //IE 6+ in 'standards compliant mode'
//    myWidth = document.documentElement.clientWidth;
//    myHeight = document.documentElement.clientHeight;
//  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//    //IE 4 compatible
//    myWidth = document.body.clientWidth;
//    myHeight = document.body.clientHeight;
//  }
//  return new Array(myWidth,myHeight);
//}
