/**
 * Blue Cross Blue Shield Overlay Functions
 **/
// Global Variables
var closePU = 1; 

// BCBS Overlay Class
var bcbsOverlayClass = function () {
	
	var xMousePos = 0; // Horizontal position of the mouse on the screen
	var yMousePos = 0; // Vertical position of the mouse on the screen
	var xMousePosMax = 0; // Width of the page
	var yMousePosMax = 0; // Height of the page
	
	// The Id of the overlay
	this.popElem;
	
	
	// Variable to determine if the page has loaded
	var pageLoadConfirm = false;
	
	
	// Function delegation for window.onload
	var addLoadEvent = function(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = function() {
				func();
				pageLoadConfirm = true;
			};
			
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
				pageLoadConfirm = true;
			};
		}
	};
	// Add the BCBS Overlay
	var addBCBSOverlay = function(div) {
		if(pageLoadConfirm) {
			if(document.getElementById(div).style.display=='none') {
				document.getElementById(div).style.top=(yMousePos*1+33)+"px";
				if((xMousePos*1-250)<0)
					var xpos=5;
				else
					var xpos=xMousePos*1-250;
				document.getElementById(div).style.left=(xpos)+"px";
				document.getElementById(div).style.display='';
				if(checkForInternetExplorer() && document.getElementById('bcbs-iframe')){
					var bcbsIframe = document.getElementById('bcbs-iframe');
					bcbsIframe.style.left = (xpos)+"px";
					bcbsIframe.style.top=(yMousePos*1+33)+"px";
					bcbsIframe.style.width = document.getElementById(div).offsetWidth+"px";
					bcbsIframe.style.height = document.getElementById(div).offsetHeight+"px";
					bcbsIframe.style.display = '';
					bcbsIframe.zoom = 1;
				}
			}
		}
	};
	
	// Initialize removal of the BCBS Overlay function
	var removeBCBSOverlay = function(div) {
		if(pageLoadConfirm){
			this.popElem = div;
			window.setTimeout(hideBCBSOverlay,1300);
		}
	};
	
	// Hide the BCBS Overlay function
	function hideBCBSOverlay () {
		if(closePU==1){ 
			document.getElementById(this.popElem).style.display='none';
			if(checkForInternetExplorer() && document.getElementById('bcbs-iframe')) {
				document.getElementById('bcbs-iframe').style.display='none';
			}
		}
	}
	
	// Bind mouse movements in the document to a function 
	var mouseMoveDetect = function() {
		document.onmousemove = getMouse;
	};
	
	// Determine mouse position on the screen
	var getMouse = function(e) {
		if (!e) var e = window.event;
		if (e.pageX || e.pageY) 	{
			xMousePos = e.pageX;
			yMousePos = e.pageY;
			xMousePosMax = window.innerWidth
				+ window.pageXOffset;
			yMousePosMax = window.innerHeight
				+ window.pageYOffset;
		}
		else if (e.clientX || e.clientY) 	{
			xMousePos = e.clientX + document.body.scrollLeft
				+ document.documentElement.scrollLeft;
			yMousePos = e.clientY + document.body.scrollTop
				+ document.documentElement.scrollTop;
			xMousePosMax = document.body.clientWidth
				+ document.body.scrollLeft;
			yMousePosMax = document.body.clientHeight
				+ document.body.scrollTop;
		}
	};
	
	
	// Check for Internet Explorer
	var checkForInternetExplorer = function() {
		if(navigator.appVersion.indexOf("MSIE")!=-1) {
			return  parseFloat(navigator.appVersion.split("MSIE")[1])<=6 ? true : false;
		}
		else {
			return  false;
		}
	};
	
	// Adds an iframe behind the div to protect bleed-through with select elements
	var bcbsIframeAdd = function() {
		if(checkForInternetExplorer) {
			var bcbsIframe = document.createElement('iframe');
			bcbsIframe.id = 'bcbs-iframe';
			bcbsIframe.setAttribute("src","javascript:'<html></html>';");
			bcbsIframe.style.position = "absolute";
			bcbsIframe.style.marginLeft = "245px";
			bcbsIframe.style.zIndex = "999";
			bcbsIframe.style.display = 'none';
			bcbsIframe.filter = "alpha(opacity=0)";
			document.body.appendChild(bcbsIframe);
		}
	};
	
	// Publicly Accessible Functions
	return {
		showPop: function(div) {
			addBCBSOverlay(div);
		},
		hidePop: function(div) {
			removeBCBSOverlay(div);
		},
		init: function() {
			addLoadEvent(mouseMoveDetect);
			addLoadEvent(bcbsIframeAdd);
		}
	};
}();

// Initialize the object
bcbsOverlayClass.init();


// Older Definitions for HTML inline event handlers

// Shows the BCBS pop-up
var bcbspopup = function(div){
	bcbsOverlayClass.showPop(div);
};
// Hides the BCBS pop-up
var hide = function(div) {
	bcbsOverlayClass.hidePop(div);
};
