var base = document.URL.indexOf("/fr/") >= 0 ? "../" : "";

var gDefaultTooltip = "";

/**** SubWin ****/

var isNav4, isIE4, isMac;
if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
	isNav4 = (navigator.appName == "Netscape") ? true : false
	isNav6 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 5) ? true : false
	isIE4  = (navigator.appName.indexOf("Microsoft") != -1) ? true : false
	isMac  = (navigator.platform.indexOf("Mac") != -1) ? true : false
}

function openImageWin(url, winWidth, winHeight) {
	openSubWin(url, winWidth + 20, winHeight + 20);
}

function openMovieWin(url, winWidth, winHeight) {
	openSubWin(url, winWidth + 20, winHeight + 35);
}

function openSubWin(url, winWidth, winHeight) {
	if (isNav4 || isIE4) {
		var screenPosX,screenPosY;
		screenPosX = (screen.availWidth - winWidth) / 2;
		screenPosY = (screen.availHeight - winHeight) / 2;
		if (isNav4 || isNav6) {
			window.open(url, 'subwin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0, copyhistory=0,width='+winWidth+',height='+winHeight+',screenX='+screenPosX+',screenY='+screenPosY+'');
		}
		if (isIE4) {
			newwin = window.open(url, 'subwin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0, copyhistory=0,width='+winWidth+',height='+winHeight+',left='+screenPosX+',top='+screenPosY+'');    
		}
	} else {
		window.open(url, 'subwin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0, copyhistory=0,width='+winWidth+',height='+winHeight);
	}
}


/**** Tool Tips ****/

function initializeTooltips(defaultTooltip) {
	var newDiv = document.createElement('div');
	newDiv.setAttribute('id', 'tooltip');
	newDiv.style.cssText = 'position:absolute; visibility:hidden; font-family: \'Lucida Grande\', Helvetica; font-size: 11px; border: 1px solid #AAA; padding: 3px;';
	document.body.appendChild(newDiv);
	gDefaultTooltip = defaultTooltip;
}

function showtip(hovered,event){
	// Makes the "tooltip" element visible and moves it to the 
	// (x,y) of the mouse event (plus some buffer zone)
	
	var agent = navigator.userAgent;
	if (agent.indexOf("MSIE") > 0 && agent.indexOf("Mac") > 0) { 
		// IE-Mac no longer supported, and the CSS functionality is not up to the par needed for this
		return;
	}
	
	var abstract_text = hovered.getElementsByTagName('img').item(0).getAttribute('alt');
	if (abstract_text == "_") {
		abstract_text = gDefaultTooltip;
	}
	if(!abstract_text) { 
		return; 
	} 
	
	// Event-handling code for cross-browser support
	var mouse_event;
	if(!event) { mouse_event = window.event; } else { mouse_event = event; }
	
	var tooltip = document.getElementById("tooltip");
	tooltip.innerHTML = abstract_text;
	
	tooltip.style.backgroundColor = "#FDFEC8";
	
	var xcoord = 0;
	var ycoord = 0;
	
	if(mouse_event.pageX || mouse_event.pageY) {
	 	xcoord = event.pageX;
	 	ycoord = event.pageY;
	} else if(mouse_event.clientX || mouse_event.clientY) {
		xcoord = mouse_event.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft);
		ycoord = mouse_event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	}
	
	tooltip.style.left = xcoord + 4 + "px";
	tooltip.style.top = ycoord + 10 + "px";
	tooltip.style.visibility="visible";
}

function hidetip() {
	document.getElementById("tooltip").style.visibility="hidden";
}
