﻿function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function prepLinks(){
	/* this function targets which links should be prepped with the onclick function for the text swap and calls prepLinks2 */
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("ssmbp_intbox1")) return false;
	if (!document.getElementById("ssmbp_intbox2")) return false;
	if (!document.getElementById("ssmbp_intbox3")) return false;
	if (!document.getElementById("keysuccesslink")) return false;
	
	prepLinks2(document.getElementById("ssmbp_intbox1"));
	prepLinks2(document.getElementById("ssmbp_intbox2"));
	prepLinks2(document.getElementById("ssmbp_intbox3"));
	prepLinks2(document.getElementById("keysuccesslink"));
}

function prepLinks2(boxholder){
	/* this function actually adds the onclick function to the appropriate links */
	var links = boxholder.getElementsByTagName("a");
	for ( var i=0; i < links.length; i++) {
		links[i].onclick=function(){
			show(this.getAttribute("rel"));
			return false;
		}
	}
}

function show(boxid){
	/* this function first hides all of the boxes, then shows the targeted box */
	if (!document.getElementById) return false;
	if (!document.getElementById("ssmbp_intbox1")) return false;
	if (!document.getElementById("ssmbp_intbox2")) return false;
	if (!document.getElementById("ssmbp_intbox3")) return false;
	if (!document.getElementById("intboxkey")) return false;
	
	document.getElementById("ssmbp_intbox1").style.display="none";
	document.getElementById("ssmbp_intbox2").style.display="none";
	document.getElementById("ssmbp_intbox3").style.display="none";
	document.getElementById("intboxkey").style.display="none";
	document.getElementById(boxid).style.display="block";

}

function tooltipprep(){
	/* this function preps the tooltip links with the onmouseover and onmouseout functions */
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("tooltiplinks")) return false;

	var links = document.getElementById("tooltiplinks").getElementsByTagName("a");
	for ( var i=0; i < links.length; i++) {
		links[i].onmouseover=function(){
			/* the next few lines move the title attribute into a new <span> to store it for the tooltip */
			var tip = document.createElement("span");
			var tipText = document.createTextNode(this.getAttribute("title"));
			tip.appendChild(tipText);
			this.appendChild(tip);
			this._tooltip = tip;
			this.title=""; /* keeps the title from appearing in the browser's default tooltip */
			ddrivetip(tip.innerHTML);
		}
		links[i].onmouseout=function(){
			/* removes the span and sets the title of the link back to what it should be */
			this.title = this._tooltip.childNodes[0].nodeValue;      
			this.removeChild(this._tooltip);
			this._tooltip = null;
			
			// Fix for Safari2/Opera9 repaint issue
			document.documentElement.style.position = "static";
			hideddrivetip();
		}
	}
}


addLoadEvent(prepLinks);
addLoadEvent(tooltipprep);
