function screenMe(tog, whom, bod, shade) {
	// Check if the movie is there.
	if ((document.getElementById('movie-space')) && (document.getElementById('movie-case'))) {
		if (tog == 'on') {
			document.getElementById('movie-space').style.height = document.getElementById('movie-case').offsetHeight + 'px';
			document.getElementById('movie-space').style.width = document.getElementById('movie-case').offsetWidth + 'px';
			document.getElementById('movie-space').style.display = 'block';
			document.getElementById('movie-case').style.display = 'none';
		}
		if (tog == 'off') {
			document.getElementById('movie-space').style.display = 'none';
			document.getElementById('movie-case').style.display = 'block';
		}
	}
	

	// Make sure the passed whom is valid.
	if ((whom != 'win') && (!document.getElementById(whom))) {return false;}

	/* get the parent element */
	if (whom == 'win') {var par = document.getElementsByTagName("body")[0];}
	else {var par = document.getElementById(whom);}

	// Screens on.
	if (tog == 'on') {
		// check if the parent element is positioned
		if (par.style.position == '') {par.style.position = 'relative';}

		// if it doesn't already exist, create the screen
		if (!document.getElementById('screen_' + whom)) {var bar = document.createElement('div');}
		// if it does, get and clear it
		else {
			var bar = document.getElementById('screen_' + whom);
			if (bar.childNodes.length > 0) {infanticide('screen_' + whom);}
		}

		/* Set some of the screen's attributes. */
		bar.setAttribute('id', 'screen_' + whom);
		bar.setAttribute('style', '');
		bar.style.display = 'none';
		bar.style.position = 'fixed';
		bar.style.top = '0px';
		bar.style.left = '0px';
		bar.style.width = '100%';
		bar.style.height = '100%';
		bar.style.textAlign = 'center';
		bar.style.opacity = 0;
		bar.style.MozOpacity = 0;
		bar.style.KhtmlOpacity = 0;
		bar.style.filter = "alpha(opacity=0)";
		// Set the shade.
		if (shade) {bar.style.backgroundColor = shade;}
		else {bar.style.backgroundColor = '';}

		/* Create a case for the bod. */
		var bc = document.createElement('div');
		bc.setAttribute('id', whom + '_bodcase');
		// If bod is an object. 
		if (typeof(bod) == 'object') {
			bar.removeAttribute('onclick');
			// Clone the bod.
			var nod = bod.cloneNode(true);
			// And ensure the text is aligned left.
			nod.style.textAlign = 'left';
			// Create a case for the clone.
			var pod = document.createElement('div');
			pod.style.height = bod.offsetHeight + 'px';
			pod.style.width = bod.offsetWidth + 'px';
			// Insert the clone to its case.
			pod.appendChild(nod);
			// Set the pod's case stylees.
			//bc.style.textAlign = 'center';
			bc.style.border = '10px solid #000000';
			bc.style.backgroundColor = 'rgb(255,255,255)';
			if (bod.style.height) {bc.style.height = (parseInt(bod.style.height.replace(/px/, '')) + 150) + 'px';}
			else {bc.style.height = (parseInt(bod.offsetHeight) + 150) + 'px';}
			if (bod.style.width) {bc.style.width = (parseInt(bod.style.width.replace(/px/, '')) + 150) + 'px';}
			else {bc.style.width = (parseInt(bod.offsetWidth) + 150) + 'px';}
			// Append the pod.
			bc.appendChild(pod);
			// And center the pod in its case.
			abscent(bc, pod);
		}
		// If not, then assume it's a path to an image.
		else {
			bar.setAttribute('onclick', "screenMe('off', '"+whom+"')");
			var nimg = new Image();
			nimg.src = bod;
			nimg.className = 'screenImg';
			bc.style.height = nimg.height + 'px';
			bc.style.width = nimg.width + 'px';
			bc.appendChild(nimg);
		}

		/* Create the close box. */
		var ixt = "<span style=\"cursor:pointer\" onclick=\"screenMe('off', '"+whom+"')\">close</span>";
		var vc = document.createElement('div');
		vc.className = 'shade_box_close_box';
		vc.setAttribute('onclick', "screenMe('off', '"+whom+"')");
		vc.setAttribute('onmouseover', 'this.style.backgroundColor="#0000FF"');
		vc.setAttribute('onmouseout', 'this.style.backgroundColor="#FF0000"');
		vc.innerHTML = ixt;
		// Append it to the bod case.
		bc.appendChild(vc);

		/* Insert the body in the screen. */
		bar.appendChild(bc);
		/* Insert the screen to the parent. */
		par.appendChild(bar);
		/* Center the screen in the parent. */
		abscent('win', bc);
		// Disappear the video, if it exists.
		if (document.getElementById('ecovid')) {
			holdim('ecovid_case', 'hw');
			document.getElementById('ecovid').style.display = 'none';
		}
		/* Fade it up! */
		toggleFade(bar.id, 100, 300);
	}

	// Screens off.
	if (tog == 'off') {
		if (!document.getElementById('screen_' + whom)) {return false;}
		toggleFade('screen_' + whom, 100, 300);
		setTimeout("infanticide('screen_" + whom + "');", 250);
		// Reappear the video, if it exists.
		if (document.getElementById('ecovid')) {
			holdim('ecovid_case', 'xhw');
			document.getElementById('ecovid').style.display = 'block';
		}
	}
}


function abscent(par, chi) {
  if (par == 'win') {
	if (window.innerWidth) {
	  var pw = (parseInt(window.innerWidth) - 16);
	  var ph = window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
	  var pw = (parseInt(document.documentElement.clientWidth) - 20);
	  var ph = document.documentElement.clientHeight;
	}
	else if (document.body) {
	  var pw = (parseInt(document.body.clientWidth) - 20);
	  var ph = document.body.clientHeight;
	}
  }
  else {
	if (par.style.height) {var ph = par.style.height.replace(/px/, '');}
	else {var ph = par.offsetHeight;}
	if (par.style.width) {var pw = par.style.width.replace(/px/, '');}
	else {var pw = par.offsetWidth;}
  }

  // Get the dims.
  if (chi.style.height) {var ch = chi.style.height.replace(/px/, '');}
  else {var ch = chi.offsetHeight;}
  if (chi.style.width) {var cw = chi.style.width.replace(/px/, '');}
  else {var cw = chi.offsetWidth;}

  // Position the child.
  chi.style.position = 'absolute';
  chi.style.top = Math.round((parseInt(ph) / 2) - (parseInt(ch) / 2)) + 'px';
  chi.style.left = Math.round((parseInt(pw) / 2) - (parseInt(cw) / 2)) + 'px';
}


function infanticide(where) {
  var killbox = document.getElementById(where);
  while (killbox.childNodes[0]) {
    killbox.removeChild(killbox.childNodes[0]);
  }
  if (killbox.childNodes[0]) {infanticide(where);}
  else {return true;}
}


/* Start fade functions */

function toggleFade(thisdiv, howmuch, howlong) {
  if (document.getElementById(thisdiv).style.opacity == (howmuch/100)) {fadeMe(thisdiv, howmuch, 0, howlong);}
  else {fadeMe(thisdiv, 0, howmuch, howlong);}
}

function fadeMe(thisdiv, fropac, topac, howlong) {
  var box = document.getElementById(thisdiv).style;
  if (fropac == 0) {box.zIndex = 1000; box.display = "block"; opacity(thisdiv, fropac, topac, howlong);}
  if (topac == 0) {
	opacity(thisdiv, fropac, topac, howlong);
	setTimeout("document.getElementById('" + thisdiv + "').style.zIndex = '-3'", howlong);
	//	setTimeout("document.getElementById('" + thisdiv + "').style.display = 'none'", howlong);
  }
}

function opacity(id, opacStart, opacEnd, millisec) {
  //speed for each frame
  var speed = Math.round(millisec / 100);
  var timer = 0;

  //determine the direction for the blending, if start and end are the same nothing happens
  if(opacStart > opacEnd) {
	for(i = opacStart; i >= opacEnd; i--) {
	  setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
	  timer++;
	}
  } else if(opacStart < opacEnd) {
	for(i = opacStart; i <= opacEnd; i++) {
	  setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
	  timer++;
	}
  }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
  var fadingdiv = document.getElementById(id).style;
  fadingdiv.opacity = (opacity / 100);
  fadingdiv.MozOpacity = (opacity / 100);
  fadingdiv.KhtmlOpacity = (opacity / 100);
  fadingdiv.filter = "alpha(opacity=" + opacity + ")";
  //	alert(id + ' ' + opacity);
  return true;
}

/* End fade functions */


function holdim(which, dim) {
  if (document.getElementById(which)) {
	if (dim.indexOf('x') != -1) {
	  if (dim.indexOf('xh') != -1) {
		document.getElementById(which).style.height = '';
	  }
	  if (dim.indexOf('xw') != -1) {
		document.getElementById(which).style.width = '';
	  }
	}
	else {
	  if (dim.indexOf('h') != -1) {
		document.getElementById(which).style.height = document.getElementById(which).offsetHeight + 'px';
	  }
	  if (dim.indexOf('w') != -1) {
		document.getElementById(which).style.width = document.getElementById(which).offsetWidth + 'px';
	  }
	}
  }
  else {return false;}
}
