//flexTPS - flexible TelePresense System
//Copyright (c) 2003-2005  Christopher Stanton
//
//Visit: http://flextps.org
//
//This program is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2 of the License, or
//(at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA

var sBegin = agt.indexOf('safari/');
if (sBegin !=-1) {
  sEnd = agt.indexOf(' ',sBegin);
  if (sEnd == -1) sEnd = agt.length;
  safari_build = parseFloat(agt.substring(sBegin+7,sEnd));
}                                 

var hasJava = true; //is_java;
var hasMJPEG = is_gecko || (is_safari && safari_build >= 416.12);
//var hasActivex = is_ie && is_win;

var topzindex = 0;

var videoBoxesLayedOut = 0;

function getNameFromIndex(i) {
	if ( streams[index].SITE ){
		return streams[i].SITE + ":" + streams[i].FEED + ":" + streams[i].STREAM;
	} else {
		return streams[i].FEED + ":" + streams[i].STREAM;
	}
}

function selectStream(index){
	if (streams[index].VISIBILITY == false) {
		if ( streams[index].FPS > 0 ) {
//		if (streams[index].FPS > 0  || document.getElementById("container-" + index).style.zIndex == 0) {
//			if (!(is_safari && !hasMJPEG)) {
			streamVideo(index);
//			}
		}

		if ( streams[index].ROBOTIC_ENABLED ) {
			configure_controls(index);
		}
	}

	showVideoBox(index);
}

function unselectStream(index){
	hideVideoBox(index);

	if ( streams[index].FPS > 0 ){
		if (hasMJPEG) {
			document.getElementById("stream-" + index).src = "/images/connecting_to_stream.jpg"; 
		} else if (hasJava) {
			document.applets["stream-" + index].setImageLocation("/images/connecting_to_stream.jpg");
		}
	}
}

function toggleSize(index) {
	var selectedSize = streams[index].SIZE;

	if (selectedSize == 'large') {
		selectedSize = 'medium';
	} else {
		selectedSize = 'large';
	}

	streams[index].SIZE = selectedSize;

	if ( streams[index].ROBOTIC_ENABLED ) {
		if ( streams[index].ROBOTIC_IRIS ) {
			document.getElementById("airis_image-" + index).src = '/images/robotic_control-irisbar-' + selectedSize + '.gif';
		}

		if ( streams[index].ROBOTIC_FOCUS ) {
			document.getElementById("afocus_image-" + index).src = '/images/robotic_control-focusbar-' + selectedSize + '.gif';
		}

		if ( streams[index].ROBOTIC_ZOOM ){
			document.getElementById("azoom_image-" + index).src = '/images/robotic_control-zoombar-' + selectedSize + '.gif';
		}

		if ( streams[index].ROBOTIC_TILT ){
			document.getElementById("atilt_image-" + index).src = '/images/robotic_control-tiltbar-' + selectedSize + '.gif';
		}

		if ( streams[index].ROBOTIC_PAN ){
			document.getElementById("apan_image-" + index).src = '/images/robotic_control-panbar-' + selectedSize + '.gif';
		}
		configure_controls(index);
	}

	showVideoBox(index);
}

function setFrameRate(index) {
	var selectedIndex = document.getElementById("frameRateSelect-" + index).selectedIndex
	streams[index].FPS = document.getElementById("frameRateSelect-" + index)[selectedIndex].value

	if ( streams[index].ROBOTIC_ENABLED ){
		configure_controls(index);
	}

	showVideoBox(index);
	streamVideo(index);
}

function reconnectToStream(index) {
	if ( streams[index].ROBOTIC_ENABLED ){
		configure_controls(index);
	}

	showVideoBox(index);
	streamVideo(index);
}

function showVideoBox(index) {
	//not layed out yet
	if (streams[index].ZINDEX == 0) {
		var right = 200;
		var top = 160;
		streams[index].XPOS = right + 50*videoBoxesLayedOut;
		streams[index].YPOS = top + 50*videoBoxesLayedOut;
		videoBoxesLayedOut++;
	}

	if (!loading) {
		++topzindex;

		if ( is_ie ) {
			++topzindex;
		}

		streams[index].ZINDEX = topzindex;
	}

	var selectedSize = streams[index].SIZE;
	var imageWidth = parseInt(size[selectedSize].WIDTH);
	var imageHeight = parseInt(size[selectedSize].HEIGHT);
	var containerWidth = imageWidth;

	if (is_ie) containerWidth += 4;

	if ( streams[index].ROBOTIC_ENABLED ){ 
		//include border and controls in width if robotic controls are enabled
		containerWidth += 2 + 24;

		if ( streams[index].ROBOTIC_IRIS ){
			document.getElementById("airis_image-" + index).style.width = imageWidth - 40 - 40;
		}
		if ( streams[index].ROBOTIC_FOCUS ){
			document.getElementById("afocus_image-" + index).style.width = imageWidth - 40 - 40;
		}
		if ( streams[index].ROBOTIC_ZOOM ){
			document.getElementById("azoom_image-" + index).style.width = imageWidth - 40 - 40;
		}
		if ( streams[index].ROBOTIC_PAN ){
			document.getElementById("apan_image-" + index).style.width = imageWidth - 24 - 24;
		}
		if ( streams[index].ROBOTIC_TILT ){
			document.getElementById("atilt_image-" + index).style.height = imageHeight - 24 - 24;
		}
	}

	var container = document.getElementById("container-" + index);
	container.style.left = streams[index].XPOS;
	container.style.top = streams[index].YPOS;
	container.style.width = containerWidth;
	container.style.zIndex = streams[index].ZINDEX;

	document.getElementById("video-" + index).style.width = imageWidth;
	document.getElementById("video-" + index).style.height = imageHeight;

	//WHY NOT SAFARI?
	if (!(is_safari && !hasMJPEG)) {
		document.getElementById("stream-" + index).style.width = imageWidth;
		document.getElementById("stream-" + index).style.height = imageHeight;
	}

	streams[index].VISIBILITY = true;
	container.style.display = "block";

	if ( is_ie ) {
		containerWidth = container.offsetWidth;
		var containerHeight = container.offsetHeight;
	
		var shim = document.getElementById("div_shim-" + index);
		shim.style.left = streams[index].XPOS;
		shim.style.top = streams[index].YPOS;
		shim.style.width = containerWidth;
		shim.style.height = containerHeight;
		shim.style.zIndex = streams[index].ZINDEX - 1;
		shim.style.display = "block";
	}

}

function hideVideoBox(index) {
	streams[index].VISIBILITY = false;
	document.getElementById("container-" + index).style.display = "none";

	if ( is_ie ) {
		document.getElementById("div_shim-" + index).style.display = "none";
	}
}

function updateVideoBoxPositions() {
	for (var i=0; i<streams.length; i++) {
		var index = getNameFromIndex(i);

		streams[index].XPOS = document.getElementById("container-" + index).style.left;
		streams[index].YPOS = document.getElementById("container-" + index).style.top;

		if ( is_ie ) {
			document.getElementById("div_shim-" + index).style.left = streams[index].XPOS;
			document.getElementById("div_shim-" + index).style.top = streams[index].YPOS;
		}
	}
}

function updateDivShimPosition(index, left, top) {
	if ( is_ie ) {
		document.getElementById("div_shim-" + index).style.left = left;
		document.getElementById("div_shim-" + index).style.top = top;
	}
}

function updateVideoBoxZIndexs() {
	for (var i=0; i<streams.length; i++) {
		var index = getNameFromIndex(i);

		streams[index].ZINDEX = document.getElementById("container-" + index).style.zIndex;

		if ( is_ie ) {
			document.getElementById("div_shim-" + index).style.zIndex = streams[index].ZINDEX - 1;
		}
	}
}


function irisClose(index) {
	if ( active_robotic_controls(index) ){
		frames["nowhere"].location.href = portal_url(index) + roboticResourceURL(index) + "?ctrl=riris&amp;value=close"
	}
}

function irisOpen(index) {
	if ( active_robotic_controls(index) ){
		frames["nowhere"].location.href = portal_url(index) + roboticResourceURL(index) + "?ctrl=riris&amp;value=open"
	}
}

function irisAuto(index) {
	if ( active_robotic_controls(index) ){
		frames["nowhere"].location.href = portal_url(index) + roboticResourceURL(index) + "?ctrl=iris&amp;value=auto"
	}
}

function focusNear(index) {
	if ( active_robotic_controls(index) ){
		frames["nowhere"].location.href = portal_url(index) + roboticResourceURL(index) + "?ctrl=rfocus&amp;value=near"
	}
}

function focusFar(index) {
	if ( active_robotic_controls(index) ){
		frames["nowhere"].location.href = roboticResourceURL(index) + "?ctrl=rfocus&amp;value=far"
	}
}

function focusAuto(index) {
	if ( active_robotic_controls(index) ){
		frames["nowhere"].location.href = roboticResourceURL(index) + "?ctrl=focus&amp;value=auto"
	}
}

function zoomIn(index) {
	if ( active_robotic_controls(index) ){
		frames["nowhere"].location.href = roboticResourceURL(index) + "?ctrl=rzoom&amp;value=in"
	}
}

function zoomOut(index) {
	if ( active_robotic_controls(index) ){
		frames["nowhere"].location.href = roboticResourceURL(index) + "?ctrl=rzoom&amp;value=out"
	}
}

function tiltUp(index) {
	if ( active_robotic_controls(index) ){
		frames["nowhere"].location.href = roboticResourceURL(index) + "?ctrl=rtilt&amp;value=up"
	}
}

function tiltDown(index) {
	if ( active_robotic_controls(index) ){
		frames["nowhere"].location.href = roboticResourceURL(index) + "?ctrl=rtilt&amp;value=down"
	}
}

function panLeft(index) {
	if ( active_robotic_controls(index) ){
		frames["nowhere"].location.href = roboticResourceURL(index) + "?ctrl=rpan&amp;value=left"
	}
}

function panRight(index) {
	if ( active_robotic_controls(index) ){
		frames["nowhere"].location.href = roboticResourceURL(index) + "?ctrl=rpan&amp;value=right"
	}
}

function seekHome(index) {
	if ( active_robotic_controls(index) ){
		frames["nowhere"].location.href = roboticResourceURL(index) + "?ctrl=home"
	}
}

//------------------------------------------------------------------------------

function active_robotic_controls(index) {
	var active = false

	if (streams[index].FPS > 0) {
		if ( streams[index].ROBOTIC_ENABLED ){ 
			active = true
		}
	}

	return active
}

function jpegResourceURL(index) {
	return portal_url(index) + "/feeds/" + streams[index].FEED + "/" + streams[index].STREAM + "/jpeg";
}

function mjpegResourceURL(index) {
	return portal_url(index) + "/feeds/" + streams[index].FEED + "/" + streams[index].STREAM + "/mjpeg";
}

function roboticResourceURL(index) {
	return portal_url(index) + "/feeds/" + streams[index].FEED + "/" + streams[index].STREAM + "/robotic";
}

function portal_url(index) {
	var url = "";

	if ( streams[index].IP ){
		url = "http://" + streams[index].IP;
	}

	return url;
}

function streamVideo(index) {
	var stream = document.getElementById("stream-" + index);
	var location;

	if ( streams[index].FPS > 0 ) {
		location = mjpegResourceURL(index) + "/" + streams[index].FPS + "?status_frame=true&amp;random=" + Math.random();
		document.getElementById("snapshot-" + index).href = jpegResourceURL(index) + "?attachment=true";
	} else {
		location = portal_url(index) + "/images/disconnected_from_stream.jpg";
		document.getElementById("snapshot-" + index).href = '#disconnected#';
	}

	if (hasMJPEG) {
		stream.src = location;
	} else if (hasJava) {
		if ( streams[index].FPS > 0 ) {
			document.applets["stream-" + index].setVideoLocation(location);
		} else {
			document.applets["stream-" + index].setImageLocation(location);
		}
	}
}

function configure_controls(index) {
	var url = portal_url(index);

	if (active_robotic_controls(index)){
		var selectedSize = streams[index].SIZE;
		var imageWidth = parseInt(size[selectedSize].WIDTH);
		var imageHeight = parseInt(size[selectedSize].HEIGHT);
		var barWidth = 0;
		var barHeight = 0;

		if ( streams[index].ROBOTIC_TILT && streams[index].ROBOTIC_PAN ) {
			var roboticURL = roboticResourceURL(index) + "?ctrl=center&amp;imageheight=" + imageHeight + "&amp;imagewidth=" + imageWidth + "&amp;value=";
			if (hasMJPEG) {
				document.getElementById("robotic-" + index).href = roboticURL;
				document.getElementById("stream-" + index).isMap = true;
			} else if (hasJava) {
				document.getElementById("stream-" + index).setRoboticLocation(roboticURL);
				document.getElementById("stream-" + index).setRoboticEnabled(true);
			}
		}

		if ( streams[index].ROBOTIC_IRIS ){
			barWidth = imageWidth - 40 -40; 
			document.getElementById("airis-" + index).href = roboticResourceURL(index) + "?ctrl=airis&amp;imagewidth=" + barWidth + "&amp;value=";
			document.getElementById("airis_image-" + index).isMap = true;
		}
		if ( streams[index].ROBOTIC_FOCUS ){ 
			barWidth = imageWidth - 40 -40; 
			document.getElementById("afocus-" + index).href = roboticResourceURL(index) + "?ctrl=afocus&amp;imagewidth=" + barWidth + "&amp;value=";
			document.getElementById("afocus_image-" + index).isMap = true;
		}
		if ( streams[index].ROBOTIC_ZOOM ){ 
			barWidth = imageWidth - 40 -40; 
			document.getElementById("azoom-" + index).href = roboticResourceURL(index) + "?ctrl=azoom&amp;imagewidth=" + barWidth + "&amp;value=";
			document.getElementById("azoom_image-" + index).isMap = true;
		}
		if ( streams[index].ROBOTIC_TILT ){ 
			barHeight = imageHeight - 24 - 24;
			document.getElementById("atilt-" + index).href = roboticResourceURL(index) + "?ctrl=atilt&amp;imageheight=" + barHeight + "&amp;value=";
			document.getElementById("atilt_image-" + index).isMap = true;
		}
		if ( streams[index].ROBOTIC_PAN ){
			barWidth = imageWidth - 24 - 24;
			document.getElementById("apan-" + index).href = roboticResourceURL(index) + "?ctrl=apan&amp;imagewidth=" + barWidth + "&amp;value=";
			document.getElementById("apan_image-" + index).isMap = true;
		}
	} else {
		if ( streams[index].ROBOTIC_TILT && streams[index].ROBOTIC_PAN ) {
			if (hasMJPEG) {
				document.getElementById("robotic-" + index).href = "#disconnected#";
				document.getElementById("stream-" + index).isMap = false;
			} else if (hasJava) {
				document.getElementById("stream-" + index).setRoboticEnabled(false);
			}
		}
		if ( streams[index].ROBOTIC_IRIS ){ 
			document.getElementById("airis-" + index).href = '#disconnected#';
			document.getElementById("airis_image-" + index).isMap = false;
		}
		if ( streams[index].ROBOTIC_FOCUS ){ 
			document.getElementById("afocus-" + index).href = '#disconnected#';
			document.getElementById("afocus_image-" + index).isMap = false;
		}
		if ( streams[index].ROBOTIC_ZOOM ){ 
			document.getElementById("azoom-" + index).href = '#disconnected#';
			document.getElementById("azoom_image-" + index).isMap = false;
		}
		if ( streams[index].ROBOTIC_TILT ){ 
			document.getElementById("atilt-" + index).href = '#disconnected#';
			document.getElementById("atilt_image-" + index).isMap = false;
		}
		if ( streams[index].ROBOTIC_PAN ){ 
			document.getElementById("apan-" + index).href = '#disconnected#';
			document.getElementById("apan_image-" + index).isMap = false;
		}
	}
}

function initVideoBox(index) {
	var url = portal_url(index);

	streams[index].NAME = getNameFromIndex(index);

	//Safari has Java Applet bugs so it needs to start with a FPS=0 so initialization will
	//happen later (when the user changes the FPS)
	if ( is_safari && !hasMJPEG ){
		streams[index].FPS = 0;
	}

	if ( streams[index].MAX_FPS < 0 ){
		streams[index].MAX_FPS = 0;
	}

	if ( streams[index].FPS > streams[index].MAX_FPS ){
		streams[index].FPS = streams[index].MAX_FPS;
	} else if ( streams[index].FPS < 0 ){
		streams[index].FPS = 0;
	}

	var selectedSize = "medium";
	if (streams[index].SIZE == 'large') {
		selectedSize = "large";
	}

	var imageWidth = parseInt(size[selectedSize].WIDTH);
	var imageHeight = parseInt(size[selectedSize].HEIGHT);
	var initialImage = "/images/disconnected_from_stream.jpg";

	if ( streams[index].FPS > 0 ){
		initialImage = "/images/connecting_to_stream.jpg"
	}

	document.write('<div class=\"container\" id=\"container-' + index + '\">');
	document.write('<div class=\"header\" id=\"header-' + index + '\">');
	document.write('<span class=\"headerControls\">');
	document.write('<a href=\"#\" onclick=\"toggleSize(\'' + index + '\'); return false;\"><img src=\"/images/video_box-resize-round.gif\" width=\"23\" height=\"18\"></a>');
	document.write('<a href=\"#\" onclick=\"unselectStream(\'' + index + '\'); return false;\"><img src=\"/images/video_box-close.gif\" width=\"23\" height=\"18\"></a>');
	document.write('</span>');
	document.write(index);
	document.write('</div>');

	if ( streams[index].ROBOTIC_ENABLED ){ 
		if ( streams[index].ROBOTIC_IRIS ){ 
			document.write('<div class=\"iris\" id=\"iris-' + index + '\">');
			document.write('<a href=\"#\" onclick=\"irisClose(\'' + index + '\'); return false;\"><IMG SRC=\"/images/robotic_control-close.gif\" width=\"40\" height=\"24\"></a>');
			document.write('<a href=\"#\" target=\"nowhere\" id=\"airis-' + index + '\"><IMG height=\"24\" SRC=\"/images/robotic_control-irisbar-' + selectedSize + '.gif\" ALT=\"Iris Bar\" id=\"airis_image-' + index + '\" ISMAP></a>');
			document.write('<a href=\"#\" onclick=\"irisOpen(\'' + index + '\'); return false;\"><IMG SRC=\"/images/robotic_control-open.gif\" width=\"40\" height=\"24\" class=\"right\"></a>');
			document.write('<a href=\"#\" onclick=\"irisAuto(\'' + index + '\'); return false;\"><IMG SRC=\"/images/robotic_control-auto.gif\" width=\"24\" height=\"24\" class=\"auto\"></a>');
			document.write('</div>');
		}

		if ( streams[index].ROBOTIC_FOCUS ){ 
			document.write('<div class=\"focus\" id=\"focus-' + index + '\">');
			document.write('<a href=\"#\" onclick=\"focusNear(\'' + index + '\'); return false;\"><IMG SRC=\"/images/robotic_control-near.gif\" width=\"40\" height=\"24\"></a>');
			document.write('<a href=\"#\" target=\"nowhere\" id=\"afocus-' + index + '\"><IMG height=\"24\" SRC=\"/images/robotic_control-focusbar-' + selectedSize + '.gif\" ALT=\"Zoom Bar\" id=\"afocus_image-' + index + '\" ISMAP></a>');
			document.write('<a href=\"#\" onclick=\"focusFar(\'' + index + '\'); return false;\"><IMG SRC=\"/images/robotic_control-far.gif\" width=\"40\" height=\"24\" class=\"right\"></a>');
			document.write('<a href=\"#\" onclick=\"focusAuto(\'' + index + '\'); return false;\"><IMG SRC=\"/images/robotic_control-auto.gif\" width=\"24\" height=\"24\" class=\"auto\"></a>');
			document.write('</div>');
		}

		if ( streams[index].ROBOTIC_ZOOM ){ 
			document.write('<div class=\"zoom\" id=\"zoom-' + index + '\">');
			document.write('<a href=\"#\" onclick=\"zoomOut(\'' + index + '\'); return false;\"><IMG SRC=\"/images/robotic_control-minus.gif\" width=\"40\" height=\"24\"></a>');
			document.write('<a href=\"#\" target=\"nowhere\" id=\"azoom-' + index + '\"><IMG height=\"24\" SRC=\"/images/robotic_control-zoombar-' + selectedSize + '.gif\" ALT=\"Zoom Bar\" id=\"azoom_image-' + index + '\" ISMAP></a>');
			document.write('<a href=\"#\" onclick=\"zoomIn(\'' + index + '\'); return false;\"><IMG SRC=\"/images/robotic_control-plus.gif\" width=\"40\" height=\"24\" class=\"right\"></a>');
			document.write('</div>');
		}

		document.write('<div>');
		document.write('<div class=\"video\" id=\"video-' + index + '\">');
		if (hasMJPEG) {
			if ( streams[index].ROBOTIC_TILT && streams[index].ROBOTIC_PAN ) {
				document.write('<A HREF=\"#disconnected#\" TARGET=\"nowhere\" id=\"robotic-' + index + '\">');
				document.write('<img SRC=\"' + initialImage + '\" ALT=\"Connection error!\" BORDER=\"0\" id=\"stream-' + index + '\" ISMAP></a>');
			} else {
				document.write('<img SRC=\"' + initialImage + '\" ALT=\"Connection error!\" BORDER=\"0\" id=\"stream-' + index + '\">');
			}
		} else if (hasJava) {
			document.write('<APPLET name=\"stream-' + index + '\" id=\"stream-' + index + '\" archive=\"' + url + '/java/flexTPSVideoApplet.jar\" code=\"org.nees.buffalo.flexTPS.VideoApplet.class\" WIDTH=\"' + imageWidth + '\" HEIGHT=\"' + imageHeight + '\">');
			document.write('<PARAM NAME=\"imageLocation\" id=\"location-' + index + '\"  VALUE=\"' + url + initialImage + '\">');
			document.write('</APPLET>');
		}
		document.write('</div>');

		if ( streams[index].ROBOTIC_TILT ){ 
			document.write('<div class=\"tilt\" id=\"tilt-' + index + '\">');
			document.write('<a href=\"#\" onclick=\"tiltUp(\'' + index + '\'); return false;\"><IMG SRC=\"/images/robotic_control-up.gif\" width=\"24\" height=\"24\"></a><br>');
			document.write('<a href=\"#\" target=\"nowhere\" id=\"atilt-' + index + '\"><IMG width=\"24\" SRC=\"/images/robotic_control-tiltbar-' + selectedSize + '.gif\" ALT=\"Tilt Bar\" id=\"atilt_image-' + index + '\" ISMAP></a><br>');
			document.write('<a href=\"#\" onclick=\"tiltDown(\'' + index + '\'); return false;\"><IMG SRC=\"/images/robotic_control-down.gif\" width=\"24\" height=\"24\"></a><br>');
			document.write('</div>');
		}

		document.write('</div>');

		if ( streams[index].ROBOTIC_PAN ){ 
			document.write('<div class=\"pan\" id=\"pan-' + index + '\">');
			document.write('<a href=\"#\" onclick=\"panLeft(\'' + index + '\'); return false;\"><IMG SRC=\"/images/robotic_control-left.gif\" width=\"24\" height=\"24\"></a>');
			document.write('<a href=\"#\" target=\"nowhere\" id=\"apan-' + index + '\"><IMG height=\"24\" SRC=\"/images/robotic_control-panbar-' + selectedSize + '.gif\" ALT=\"Pan Bar\" id=\"apan_image-' + index + '\" ISMAP></a>');
			document.write('<a href=\"#\" onclick=\"panRight(\'' + index + '\'); return false;\"><IMG SRC=\"/images/robotic_control-right.gif\" width=\"24\" height=\"24\"></a>');
			if ( streams[index].ROBOTIC_TILT ){ 
				document.write('<a href=\"#\" onclick=\"seekHome(\'' + index + '\'); return false;\"><IMG SRC=\"/images/robotic_control-home.gif\" width=\"24\" height=\"24\" class=\"home\"></a>');
			}
			document.write('</div>');
		}
	} else {
		document.write('<div class=\"video\" id=\"video-' + index + '\">');
		if (hasMJPEG) {
			document.write('<img SRC=\"' + initialImage + '\" ALT=\"Connection error!\" BORDER=\"0\" id=\"stream-' + index + '\">');
		} else if (hasJava) {
			document.write('<APPLET name=\"stream-' + index + '\" id=\"stream-' + index + '\" archive=\"' + url + '/java/flexTPSVideoApplet.jar\" code=\"org.nees.buffalo.flexTPS.VideoApplet.class\" WIDTH=\"' + imageWidth + '\" HEIGHT=\"' + imageHeight + '\">');
			document.write('<PARAM NAME=\"imageLocation\" VALUE=\"' + url + initialImage + '\">');
			document.write('</APPLET>');
		}
		document.write('</div>');
	}

	document.write('<div class=\"control\" id=\"control-' + index + '\">');
	document.write('<span class=\"snapshot\"><a href=\"#disconnected#\" id=\"snapshot-' + index + '\" target=\"nowhere\"><IMG SRC=\"/images/video_box-snapshot.gif\" width=\"111\" height=\"24\"></a></span>');
	document.write('<span class=\"reconnect\"><a href=\"#\" onclick=\"reconnectToStream(\'' + index + '\'); return false;\"><IMG SRC=\"/images/video_box-reconnect.gif\" width=\"93\" height=\"24\"></a></span>');
	document.write('<form class=\"inline\" id=\"form-' + index + '\">');
	document.write('frame rate: <select id=\"frameRateSelect-' + index + '\" onChange=\"setFrameRate(\'' + index + '\')\">');

	for (var j=0; j<validFPS.length && validFPS[j] <= streams[index].MAX_FPS; j++) {
		if ( validFPS[j] <= streams[index].FPS && j<validFPS.length-1 && validFPS[j+1] > streams[index].FPS ){
			document.write('<option value=\"' + validFPS[j] + '\" selected>' + validFPS[j] + ' fps</option>');
		} else if (j == validFPS.length-1 && validFPS[j] <= streams[index].FPS){
			document.write('<option value=\"' + validFPS[j] + '\" selected>' + validFPS[j] + ' fps</option>');
		} else {
			document.write('<option value=\"' + validFPS[j] + '\">' + validFPS[j] + ' fps</option>');
		}
	}
	document.write('</select>');
	document.write('</form>');
	document.write('</div>');

	document.write('</div>');
	if ( is_ie ){
		document.write('<iframe id=\"div_shim-' + index + '\" src="javascript:false;" scrolling="no" frameborder="1" style=\"position:absolute; top:0px; left:0px; display:none;\"></iframe>');
	}
}

function printStreams() {
	var streamString = "Top zindex: " + topzindex + "\n";
	streamString += "Video box layed out: " + videoBoxesLayedOut + "\n\n";

	for (var i=0; i<streams.length; i++) {
		var index = getNameFromIndex(i);
		var selectedSize = streams[index].SIZE;

		streamString += index + "\n";
		streamString += "Size: " + selectedSize + "\n";
		streamString += "Width: " + size[selectedSize].WIDTH + "\n";
		streamString += "Height: " + size[selectedSize].HEIGHT + "\n";
		streamString += "X: " + streams[index].XPOS + "\n";
		streamString += "Y: " + streams[index].YPOS + "\n";
		streamString += "Z-Index: " + streams[index].ZINDEX + "\n";
		streamString += "Visibility: " + streams[index].VISIBILITY + "\n";
		streamString += "FPS: " + streams[index].FPS + "\n\n";

		if ( is_ie ){
			streamString += "Container height: " + document.getElementById("container-" + index).style.height + "\n";
			streamString += "Container width: " + document.getElementById("container-" + index).style.width + "\n";
			streamString += "iFrame ID: " + document.getElementById("div_shim-" + index).id + "\n";
			streamString += "iFrame index: " + document.getElementById("div_shim-" + index).id.substring(9,document.getElementById("div_shim-" + index).id.length) + "\n";
			streamString += "iFrame height: " + document.getElementById("div_shim-" + index).style.height + "\n";
			streamString += "iFrame width: " + document.getElementById("div_shim-" + index).style.width + "\n";
			streamString += "iFrame X: " + document.getElementById("div_shim-" + index).style.left + "\n";
			streamString += "iFrame Y: " + document.getElementById("div_shim-" + index).style.top + "\n\n";
		}
	}
	alert(streamString);
}
