/**
* Called from some of the gateways and from the main webcams
* page.  Randomly selects an image from the available cams on campus.
* @ht  html image height attribute size
* @wt  html image width attribute size
* @showText 1/0 whether or not to display caption with image
**/
function selectCam(ht, wt, showText) {

        var activeCams = 3;  // number of active cameras
 
        // "random" selection of camera array index
	var indx = Math.round(1000 * Math.random() ) % activeCams;

        //image names array
	var camPic = new Array("quad","servery","morrell" );
	// folder names array
        var camURL = new Array("quad","coles-jewett","morrell");
	// page title array
        var camQx = new Array("Coles Tower View","Thorne Dining Hall","Peter Buck Center for Health and Fitness" );
        // caption array
	var camTxt = new Array("Coles Tower View","Thorne Dining Hall","Peter Buck Center for Health and Fitness")

        // array of camera addresses and location of image
	var ccc = new Array("http://webcam5.bowdoin.edu:4200/jpg/image.jpg","http://webcam4.bowdoin.edu:4200/axis-cgi/jpg/image.cgi?resolution=320x240","http://hatch-webcam-1.bowdoin.edu:4200/axis-cgi/jpg/image.cgi?resolution=320x240");

        // open current document and insert camera info
	document.open();
	document.write("<table border='0'><tr><td colspan='"+activeCams+"' align='center'>");
//document.write("<a href='/webcams/"+camURL[indx]+"/'><img src='"+ccc[indx]+"' border='1' width='"+wt+"' height='"+ht+"'></a><br />");

	document.write("<a href='/webcams/"+camURL[indx]+"/'><img src='"+ccc[indx]+"' border='1' width='"+wt+"' height='"+ht+"'></a><br>");
	
        document.write("<span class='caption'>"+camTxt[indx]+"</span></td></tr>");

        if(showText) {
   	  document.write("<tr><td class='caption'>");
	  for(var i=0; i< activeCams; i++) {
		document.write("&nbsp;<a href='/webcams/"+camURL[i]+"'>"+camQx[i]+"</a>&nbsp;<br />");
	  }
	  document.write("</td></tr>");
	}



	document.write("</table>");
	document.close();

}


function stopit() {
  	document.applets[0].stop();
}


function displayStream( pbaseURL, pFile, pCaption, pDisplayWidth, pDisplayHeight ) 
{
 var BaseURL = pbaseURL;
 var File = pFile;
 var caption = pCaption;
 var DisplayWidth = pDisplayWidth;
 var DisplayHeight = pDisplayHeight;

 var output = "";
 var axStyle = "";
 var mjStyle = "";
 var jvStyle = "";

 var loc = window.location.href;
 var qx = loc.lastIndexOf("=");
 var method = "-1";
 if(qx > 0 ) {
  method = loc.substring( loc.lastIndexOf("=")+1 );
 }

  switch(method) {
	case "1" :  // use ActiveX

		output =  "<OBJECT ID=\"CamImage\" WIDTH="
  		output += DisplayWidth;
  		output += " HEIGHT=";
  		output += DisplayHeight;
  		output += " CLASSID=CLSID:917623D1-D8E5-11D2-BE8B-00104B06BDE3 ";
  		output += "CODEBASE=\"";
  		output += BaseURL;
  		output += "activex/AxisCamControl.ocx#Version=1,0,1,42\">";
  		output += "<PARAM NAME=\"URL\" VALUE=\"";
  		output += BaseURL;
  		output += File;
  		output += "\"> <p style='background-color:#ffcccc;'><B>Axis ActiveX Camera Control</B><BR>";
  		output += "The AXIS ActiveX Camera Control, which enables you ";
  		output += "to view live image streams in Microsoft Internet";
  		output += " Explorer, could not be registered on your computer.";
  		output += "</p></OBJECT>"; 
		axStyle = "background-color:#ffcc99;"
		break;

	case "2" :  // use MJPEG
		output = "<IMG SRC=\"";
  		output += BaseURL;
  		output += File;
  		output += "&dummy=garb\" HEIGHT=\"";
  		// The above dummy cgi-parameter helps some versions of NS
  		output += DisplayHeight;
  		output += "\" WIDTH=\"";
  		output += DisplayWidth;
  		output += "\" ALT=\"Moving Image Stream\">";
		mjStyle = "background-color:#ffcc99;"
		break;

	default :  // use Java		
		output =  "<APPLET ARCHIVE=AxisCamApplet.zip CODEBASE=\"";
  		output += BaseURL;
  		output += "java/\"";
  		output += " CODE=AxisCamApplet.class HEIGHT=";
  		output += DisplayHeight;
  		output += " WIDTH=";
  		output += DisplayWidth;
  		output += " alt='Your browser does not support Java'>Your browser does not support Java";
  		output += "<PARAM NAME=\"StreamLocation\" VALUE=\"";
  		output += "/"; //BaseURL;
  		output += File;
  		output += "&showlength=1\">";
  		output += "</APPLET>";

  		document.onstop=stopit;
		jvStyle = "background-color:#ffcc99;"
		break;
	}

document.open();
document.write(output);
document.write( "<br /> <span class='caption'>"+caption+"</span>");
document.write("<p><a style='"+jvStyle+"' href='camstream.shtml'>Java</a> |");
document.write("<a style='"+axStyle+"' href='camstream.shtml?m=1'>ActiveX</a> |");
document.write("<a style='"+mjStyle+"'href='camstream.shtml?m=2'>MJPEG</a></p></center>");
document.close();

}
