function bookmark(url,title){
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
		window.external.AddFavorite(url,title);
	} else if (navigator.appName == "Netscape") {
		window.sidebar.addPanel(title,url,"");
	} else {
		alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
	}
}

function flash_swf(wrapper, filename, config){
}

function flash_flv(wrapper, filename, config){
}

/***
Line Limiter
***/
function applyLinesClass(){
	var lines = document.getElementsByTagName("span");
	for(var i=0; i<lines.length; i++){
		var classNames = lines[i].className.split(" ");
		for(var j=0; j<classNames.length; j++){
			if(classNames[j].match(/^lines\d+$/)){
				var numLines = classNames[j].substring(5);
				//setTimeout("shrink(document.getElementsByTagName('span')["+i+"],"+numLines+")",1000);
				limitLines(lines[i],numLines);
			}
		}
	}
}

function limitLines(container, numLines){
	var stopper1 = "&hellip;" // ...
	var stopper2 = "";
	var lineHeight = determineLineHeight(container);
	var totalHeight = numLines * lineHeight;
	var containerHeight = container.offsetHeight;
	// alert("Lines: "+numLines+"\nLine Height: "+lineHeight+"\nTotal Height: "+totalHeight+"\nContainer Height: "+containerHeight);
	var shrunk = containerHeight > totalHeight;

	var test = 1000;
	while(containerHeight > totalHeight && test-- > 0){
		var end = container.innerHTML.length - stopper2.length -2;//+6;
		if(container.innerHTML.charAt(end) == ';'){
			if(container.innerHTML.lastIndexOf("&") > container.innerHTML.lastIndexOf(" "))
				// Remove whole HTML entity
				end = container.innerHTML.lastIndexOf("&")-1
		}
		if(container.innerHTML.charAt(end) == '>'){
			// Skip whole HTML element
			var element = container.innerHTML.substring(container.innerHTML.lastIndexOf("<",end)-1,end+1)
			element = element.replace(/^\s/,"").replace(/\s$/,"");
			stopper2 = element + stopper2;
			end = container.innerHTML.lastIndexOf("<",end)-1
		}
		container.innerHTML = container.innerHTML.substring(0,end) + stopper1 + stopper2;
		containerHeight = container.offsetHeight;
	}
	if(shrunk){
		// Neaten up by finding last whitespace
		var end = container.innerHTML.lastIndexOf(" ");
		if(end > 0)
			container.innerHTML = container.innerHTML.substring(0,end) + stopper1 + stopper2;
	}
}


function determineLineHeight(container){
	var id = "TEMP_LINEHEIGHT"
	var span = document.createElement("span")
	span.id=id
	span.innerHTML = "X";
	container.appendChild(span)


	var lineheight = "";
	if(window.getComputedStyle){
		var style = window.getComputedStyle(span,"")
		lineheight = style.getPropertyValue("line-height");
	}else if(span.currentStyle){
		lineheight = span.currentStyle["lineHeight"];
	}
	if(lineheight.match(/\d*/)){
		container.removeChild(span);
		return lineheight.match(/\d*/)[0];
	}
	// no css defined - we'll have to guess
	lineheight = document.getElementById("TEMP_LINEHEIGHT").offsetHeight + 1;
	container.removeChild(span)
	return lineheight;
}
/***
End of line limiter
***/





/**
 PRIVATE
 **/

function loadJavaScript(filename){
  var head = document.getElementsByTagName("head");

  var scripts = head.getElementsByTagName("script");
  for(i=0; i<scripts.length; i++)
    if(scripts.src.matches(filename))
      return;

  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = filename;
  
  head.appendChild(script);
}

function toggleLeftNavigation(node){
	var parent = node.parentNode;
	if(parent.className == "white") parent.className = "grey";
	else if(parent.className == "grey") parent.className = "white";
}

function getObj(name) {
	/* 	
	This function returns the HTML element asked for, regardless of browser DOM.
	The element must have a proper id and, if your script must work in Netscape 4, you should have a position defined in the style sheet.
	It's called like this:
		var x = new getObj('layername');
	You cannot do anything with the object x itself, it is merely a container for its two properties:
		.obj, giving access to the actual HTML element. You have to use this property to read out or set anything else than styles.	e.g.:
			alert(x.obj.id);
		.style, giving access to the styles of the HTML element. You have to use this property to read out or set the styles of the element. e.g.:
			x.style.top = '20px';
	*/

	if (document.getElementById) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers) {
		this.obj = getObjNN4(document,name);
		this.style = this.obj;
	}
	
}

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	
	for (var i=0;i<x.length;i++)
	{
		
		if (x[i].id == name) {
			foundLayer = x[i];
		}
		else if (x[i].layers.length) {
			var tmp = getObjNN4(x[i],name);
		}
		
		if (tmp) {
			foundLayer = tmp;
		}
		
	}
	
	return foundLayer;
}



function footnote(number) {
location.href="#"+number;
}


function printPage(url){
	if(url.match(/\/publications\//gi) && !url.match(/\/publications\/home\.page/gi)) {
		var prefix = url.lastIndexOf(".page") ;
		var printURL = url.substring(0,prefix) + ".print";
		printerWindow=window.open(printURL,"_blank","width=800,height=600,toolbar=no,menubar=yes,location=yes,status=yes,scrollbars=yes"); 
	} else {
		window.print();
	}
} 

