document.getElementsByClassName = function(className) {
  var children = document.getElementsByTagName('*') || document.all;
  var elements = new Array();
  
  for (var i = 0, c = children.length; i < c; i++) {
    var child = children[i];
    var classNames = child.className.split(' ');
    for (var j = 0, cc = classNames.length; j < cc; j++) {
      if (classNames[j] == className) {
        elements.push(child);
        break;
      }
    }
  }
  
  return elements;
}

var thumb_div = null;
var thumb_pre = [];
var thumb_timer = 0;

function load_hovers()
{
	thumb_div = document.createElement('div');
    thumb_div.id = 'div-hover';
    document.body.appendChild(thumb_div);

	//var fx = new FX.Opacity({targ: thumb_div, min: 90, max: 92});
	//fx.toggle();

	var btns = [];
	var date =  document.getElementsByClassName('date-chg-btn');
	var dollar = document.getElementsByClassName('dollar-chg-btn');

	for (var d = 0, c = date.length; d < c; d++) { btns.push(date[d]) };
	for (var d = 0, c = dollar.length; d < c; d++) { btns.push(dollar[d]); }

	for (var b = 0, c = btns.length; b < c; b++) {
        
		if (!btns[b].id) continue;

        btns[b].onmouseover = function()
        {
            var id = this.id.replace(/btn$/i, 'div');
			thumb_div.className = this.id.match(/date/i) ? 'date' : 'dollar';
            thumb_div.innerHTML = document.getElementById(id).innerHTML;
            thumb_timer = setTimeout(function() {thumb_div.style.visibility = 'visible' }, 200);
            if (this.captureEvents) this.captureEvents(Event.MOUSEMOVE);
            this.onmousemove = hover_event;
        };
        thumb_div.onerror = function()
        {
            this.style.visibility = 'hidden';                    
        };
        btns[b].onmouseout = function()
        {
            clearTimeout(thumb_timer);
            thumb_div.style.visibility = 'hidden';
            thumb_div.innerHTML = '';
            thumb_div.style.left = '0px';
            thumb_div.style.top = '0px';
			thumb_div.className = '';
            if (this.releaseEvents) this.releaseEvents(Event.MOUSEMOVE);
            this.onmousemove = null;
        };
	}
}

function hover_event(e)
{
    var xcoord = 15;
    var ycoord = 5;
    var dwidth = get_doc_width();
    var dheight = get_doc_height();
    var x = 0;
    var y = 0;	
    
	if (typeof e != "undefined"){

        if (e.pageX || e.pageY) {
            x = e.pageX;
            y = e.pageY;
        } else if (e.clientX || e.clientY) {
            x = e.clientX;
            y = e.clientY;
        }

        if (dwidth - x < thumb_div.offsetWidth + xcoord){
            xcoord = x - xcoord - thumb_div.offsetWidth;
        } else {
            xcoord += x;
        } 
                    
        if (dheight + get_true_body().scrollTop - y < thumb_div.offsetHeight + ycoord){
            ycoord = y - ycoord - thumb_div.offsetHeight;
        } else {
            ycoord += y;
        }

    } else if (typeof window.event != "undefined"){

        if (dwidth - event.clientX < thumb_div.offsetWidth + xcoord){
            xcoord = event.clientX - xcoord - thumb_div.offsetWidth + get_true_body().scrollLeft;
        } else {
            xcoord += event.clientX + get_true_body().scrollLeft;
        }

        if (dheight - event.clientY < thumb_div.offsetHeight + ycoord){
            ycoord = event.clientY - ycoord - thumb_div.offsetHeight + get_true_body().scrollTop;
        } else {
            ycoord += event.clientY + get_true_body().scrollTop;
        }

    } else { return; }

    thumb_div.style.left = xcoord+'px';
    thumb_div.style.top = ycoord+'px';
}

function get_doc_width(){
    return (document.all? get_true_body().scrollLeft+get_true_body().clientWidth : pageXOffset+window.innerWidth-15);
}

function get_doc_height(){
    return (document.all? Math.min(get_true_body().scrollHeight, get_true_body().clientHeight) : Math.min(window.innerHeight));
}

function get_true_body(){
    return ((!window.opera && document.compatMode && document.compatMode!="BackCompat") || window.opera) ? document.documentElement : document.body;
}