document.write('<style type="text/css">#ciscoFlagDiv { position:absolute; left:-26px; padding:0px; visibility: hidden; z-index:100; text-align:left; }</style>');
document.write('<div id="ciscoFlagDiv"><img src="http://www.cisco.com/web/europe/images/usflag.gif" width="16" height="11" alt="" border="0" /></div>');

var ie  = document.all;
var ns6 = document.getElementById && !document.all; 

if(ns6) {
	var offsetXpoint = -78;
	var offsetYpoint = 19;
}
else {
	var offsetXpoint = -80;
	var offsetYpoint = 17;
}

var enableTip = false;
var tipObj = "";

if (ie || ns6) {
	var tipObj = document.all? document.all["ciscoFlagDiv"] : document.getElementById? document.getElementById("ciscoFlagDiv") : "";
}

function ieTrueBody()	{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function showFlag() {
	if (ns6 || ie) {
		enableTip = true;
		return false;
	}
}

function positionTip(e) {
	if (enableTip) {
		var curX = (ns6)?e.pageX : event.clientX+ieTrueBody().scrollLeft;
		var curY = (ns6)?e.pageY : event.clientY+ieTrueBody().scrollTop;
		
		// find out how close the mouse is to the corner of the window
		var rightedge  = ie&&!window.opera? ieTrueBody().clientWidth-event.clientX-offsetXpoint : window.innerWidth-e.clientX-offsetXpoint-20;
		var bottomedge = ie&&!window.opera? ieTrueBody().clientHeight-event.clientY-offsetYpoint : window.innerHeight-e.clientY-offsetYpoint-20;
		
		var leftedge = (offsetXpoint<0)? offsetXpoint*(-1) : -1000;
		
		// if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipObj.offsetWidth) {
			//move the horizontal position of the menu to the left by it's width
			tipObj.style.left=ie? ieTrueBody().scrollLeft+event.clientX-tipObj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipObj.offsetWidth + "px";
		}
		else {
			// position the horizontal position of the menu where the mouse is positioned
			tipObj.style.left = (curX + offsetXpoint + 70) + "px";
		}
		
		// same concept with the vertical position
		if (bottomedge < tipObj.offsetHeight) {
			tipObj.style.top=ie? ieTrueBody().scrollTop+event.clientY-tipObj.offsetHeight-offsetYpoint+"px" : window.pageYOffset+e.clientY-tipObj.offsetHeight-offsetYpoint+"px";
		}
		else {
			tipObj.style.top = curY + offsetYpoint + "px";
			tipObj.style.visibility = "visible";
		}
	}
}

function hideFlag() {
	if (ns6 || ie) {
		enableTip = false;
		tipObj.style.visibility = "hidden";
		tipObj.style.left = "-1000px";
	}
}

document.onmousemove = positionTip;

window.onload = function () {
	var a = document.getElementsByTagName("a");

	for (var i = 0; i <a.length; i++) {

		// only handle cisco links
		if(a[i].href.indexOf("cisco.com") >= 0) {
			if(a[i].href.indexOf("/web/" + countrySite + "/") == -1) {
	
				if (a[i].addEventListener) {
					a[i].addEventListener("mouseover", showFlag, false);
					a[i].addEventListener("mouseout", hideFlag, false);
				}
				else if (a[i].attachEvent){
					window.event.cancelBubble = true;
					a[i].attachEvent("onmouseover", showFlag);
					a[i].attachEvent("onmouseout", hideFlag);
				}
			}
		}
	}
}

