

// Return the given object
function getDOMObj(obj){
	if(document.getElementById && document.getElementById(obj) != null){
		return document.getElementById(obj);
	}else if(document.layers && document.layers[obj] != null){
		return document.layers[obj];
	}else if(document.all){
		return document.all[obj];
	}
}

// Generic overLib display
function displayOvLib(task,tip){

	var msg = "";
	var capn = "";
	var wd = 220;
	var ht = 28;
	
	var lightbox = false;

	switch (task){
	
		case "tooltip":
			msg = tip;
			//wd = Math.round(tip.length + (tip.length*1));
			wd = getTooltipWidth(msg);
			break;
	
	
		// Lightbox control panel
	
		case "player":
			msg = (playerOn ? "Stop" : "Start") + " the slideshow";
			wd = 110;
			ht = 10;
			lightbox = true;
			break;

		case "speed":
			msg = "Set slideshow speed<br>Current: " + playerSpeedRealnames[playerSpeed] + " (" + playerSpeeds[playerSpeed]/1000 + "s)"
			wd = 120;
			ht = 28;
			lightbox = true;
			break;
	
		case "help":
			//msg =  "<b>Slideshow</b> Start &amp; stop the image slideshow<br>";
			//msg += "<b>Speed</b> Set the slideshow speed; fast to slow <br>";
			msg += "<b>Navigation</b><br> Next image - click on right side of image, hit left arrow or <em>n</em> key <br>Previous image - Click on left side of image, hit right arrow or <em>p</em> key<br>"
			msg += "<b>Slideshow speed</b><br> On a slow network use a a slower speed to give the image time to download<br>";
			msg += "<b>Close image</b><br> Click on <em>CLOSE</em>, or on the background<br>";
			//capn = "Help"
			ht = 125;
			lightbox = true;
			break;
			
		case "close":
			msg = "Return to image index";
			wd = 120;
			ht = 15;
			lightbox = true;
			break;	
	
	}
	
	if(task == "tooltip"){
		return overlib(msg, WIDTH, wd, DELAY, 300, TIMEOUT, 1300, TEXTSIZE, "9px", AUTOSTATUS)
	}else if(lightbox){
		return overlib(msg, LEFT, ABOVE, WIDTH, wd, TEXTSIZE, "9px", HEIGHT, ht)		
	}else if(capn.length > 0){
		return overlib(msg, WIDTH, wd, CAPTION, capn);
	}else return overlib(msg, WIDTH, wd);
	
}


//Ref: http://www.thescripts.com/forum/thread89923.html
function getTooltipWidth(tip){
	var tt = getDOMObj("ttDiv");
	if(!tt){
		creatediv("ttDiv",null,null,null,10,10);
		tt = getDOMObj("ttDiv");
	}
	if(!tt)return 100;
	tt.innerHTML = tip;
	ttWd = tt.offsetWidth;
	//alert(ttWd);
	return (ttWd > 180 ? 180 : ttWd);
	
}
	
// Ref: http://wiki.ittoolbox.com/index.php/Dynamically_Creating_a_Div_in_Javascript
function creatediv(id, html, width, height, left, top) {
   var newdiv = document.createElement('div');
   newdiv.setAttribute('id', id);
   if(width) {
       newdiv.style.width = width;
   }
   if (height) {
       newdiv.style.height = height;
   }
   if ((left || top) || (left && top)) {
       newdiv.style.position = "absolute";
       if (left) {
           newdiv.style.left = left;
       }
       if (top) {
           newdiv.style.top = top;
       }
   }
   newdiv.style.display = "none";
//   newdiv.style.background = "#00C";
//   newdiv.style.border = "4px solid #000";
//   if (html) {
//       newdiv.innerHTML = html;
//   } else {
//       newdiv.innerHTML = "nothing";
//   }
   document.body.appendChild(newdiv);
}

function mai1(user,machine){
	prot = 'mai';
	ocol = 'lto:';
	document.location = prot + ocol + user + '@' + machine;
}

	function getHost() {
		var url = window.location.href;
		var nohttp = url.split('//')[1];
		var hostPort = nohttp.split('/')[0];
		return hostPort;
	}


