
var _BubbleManager = new Object();

var BubbleManager = function() {
  this.thumbs = [];

  this.prepare();
  this.bindEvents();
};

BubbleManager.prototype.prepare = function() {
  var aList = document.getElementsByTagName('a');
  for(var i=0; i<aList.length; i++) {
    if(aList[i].getAttribute('rel') == 'bubble' && document.getElementsByClassName('bubble', aList[i])[0])
      this.thumbs.push(aList[i]);
  }
};

BubbleManager.prototype.bindEvents = function() {
  var self = this;
  var list = this.thumbs;
  var bubble;

  for(var i=0; i<list.length; i++) {
    list[i].id = 'bubble'+i;
    list[i].onmousemove = _moveBubble;
    list[i].onmouseover = function() { document.getElementsByClassName('bubble', this.id)[0].style.display = 'block'; };
    list[i].onmouseout = function() { document.getElementsByClassName('bubble', this.id)[0].style.display = 'none'; };
  }
};

function _moveBubble(e) {
  var mPos = _getMousePos(e);
  var bubble = document.getElementsByClassName('bubble', this)[0];
  
  bubble.style.top = (mPos[1] - 105) + 'px';
  bubble.style.left = (mPos[0] - 38) + 'px';
}

function _getMousePos(e) {
  var x = 0;
  var y = 0;
  if(!e) var e = window.event;

  if(e.pageX || e.pageY) {
	  x = e.pageX;
	  y = e.pageY;
	}
	else if(e.clientX || e.clientY) {
	  x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}

  return [x, y];
}

var _LoadBubble = function() {
  if(document.getElementById && document.getElementsByTagName && document.createElement) {
    _BubbleManager = new BubbleManager();
  }
  else
    return false;
};

if(window.addEventListener)
  window.addEventListener('load', _LoadBubble, false);
else if(window.attachEvent)
  window.attachEvent('onload', _LoadBubble);
