var dbcjs = dbcjs || {};
dbcjs.spectro = dbcjs.spectro || {};

dbcjs.spectro.openTrainingTooltip = function () {
	var self = this;
	this.tooltipContainer = null;
	
	this.initLayer = function () {
		this.tooltipContainer = document.createElement('div');
		this.tooltipContainer.id = 'spectroOpenTrainingTooltip';
		this.tooltipContainer.innerHTML = 'SPECTRO uses pop-up windows to ensure fast access speeds. Please disable or shut-off your pop-up blocker now.';
		document.body.appendChild(this.tooltipContainer);
	}
	
	this.initLinks = function () {
		var links = document.getElementsByName('spectroOpenTrainingLink');
		for (var i = 0; i < links.length; i++) {
			var curLink = links[i];
			curLink.onmouseover = function () {
				self.show(this);
			}
			curLink.onmouseout = function () {
				self.hide(this);
			}
		}
	}
	
	this.show = function (link) {
		var linkProps = {
			top: parseInt(getAbsTop(link), 10),
			left: parseInt(getAbsLeft(link), 10),
			width: parseInt(link.offsetWidth, 10),
			height: parseInt(link.offsetHeight, 10)
		};
				
		var layerProps = {
			top: linkProps.top,
			left: linkProps.left + linkProps.width,
			width: parseInt(this.tooltipContainer.offsetWidth, 10),
			height: parseInt(this.tooltipContainer.offsetHeight, 10)
		};
		
		if (!document.all) {
			layerProps.top += 4;
		}
		
		var windowProps = getWindowProperties();
		if ((layerProps.top + layerProps.height) > (windowProps.height - windowProps.scrollY)) {
			layerProps.top = (windowProps.height + windowProps.scrollY) - layerProps.height;
			if (!document.all) {
				layerProps.top -= 10;
			}
		}
		
		if ((layerProps.left + layerProps.width) > (windowProps.width - windowProps.scrollX)) {
			layerProps.left = linkProps.left - layerProps.width;
		}
		
		
		if (!document.all) {
			layerProps.top -= 8;
		}
		
		this.tooltipContainer.style.top = layerProps.top + 'px';
		this.tooltipContainer.style.left = layerProps.left + 'px';
	}
	
	this.hide = function (link) {
		this.tooltipContainer.style.top = '-1000px';
		this.tooltipContainer.style.left = '-1000px';
	}
	
	return {
		init: function () {
			self.initLayer();
			self.initLinks();
		}		
	}
}();

dbcAddEvent(
	'load',
	window,
	dbcjs.spectro.openTrainingTooltip.init
);