// Variables
var xlink="";
var xoption=0;
var bRunUpdate=false;
var sCamId="none";
var sUpdatingCamId="none";
var iUpdateSpeed="2000";

function loadPARAM() {
	xlink = document.location.search
	xlink = xlink.substring(xlink.indexOf("?")+1);
	document.getElementById("p1").className = "gray";
	document.getElementById("r1").className = "gray";
	if (xlink != "" ) {
		checkARRAY(xlink);
		selCAM = xoption;
		setParameters(selCAM);
	}
}

function cameraStructure (idNUMBER, mapPAGE, idLOCATION) {
	this.idNUMBER = idNUMBER;
	this.mapPAGE = mapPAGE;
	this.idLOCATION = idLOCATION ;
}

cameraLOCATIONS = new Array(112)
cameraLOCATIONS[0] = new cameraStructure("200167","7","Canal Rd  NW & Chain Bridge Rd  NW");
cameraLOCATIONS[1] = new cameraStructure("200123","7","Macarthur Blvd  NW & Arizona Ave  N W");
cameraLOCATIONS[2] = new cameraStructure("200117","7","Wisconsin Ave  NW & Western Ave  N W");
cameraLOCATIONS[3] = new cameraStructure("200054","7","Macarthur Blvd. & Loughboro St. NW");
cameraLOCATIONS[4] = new cameraStructure("200149","9","16th St NW & Alaska Ave  NW");
cameraLOCATIONS[5] = new cameraStructure("200141","9","Connecticut Ave  NW & Cathedral N W");
cameraLOCATIONS[6] = new cameraStructure("200139","9","Georgia Ave  NW & Arkansas Ave  N W");
cameraLOCATIONS[7] = new cameraStructure("200124","9","16th St  NW & North  Portal St  N W");
cameraLOCATIONS[8] = new cameraStructure("200122","9","Connecticut Ave NW & Van Ness St NW");
cameraLOCATIONS[9] = new cameraStructure("200121","9","Wisconsin Ave NW & Calvert St  N W");
cameraLOCATIONS[10] = new cameraStructure("200120","9","Wisc Ave NW  & Tenley Circle/Nebraska Ave  N W");
cameraLOCATIONS[11] = new cameraStructure("200119","9","Connecticut Ave  NW & Nebraska Ave  N W");
cameraLOCATIONS[12] = new cameraStructure("200118","9","Connecticut Ave  NW & Oliver St NW");
cameraLOCATIONS[13] = new cameraStructure("200110","9","16th St  NW & Military Rd/Missouri Ave  NW");
cameraLOCATIONS[14] = new cameraStructure("200109","9","16th St  NW & Upshur St  N W");
cameraLOCATIONS[15] = new cameraStructure("200108","9","Georgia Ave  NW & Missouri Ave  NW");
cameraLOCATIONS[16] = new cameraStructure("200091","9","Rhode Island Ave. & 18th St. NE (20th)");
cameraLOCATIONS[17] = new cameraStructure("200058","9","16th St. & Colorado Ave. NW");
cameraLOCATIONS[18] = new cameraStructure("200048","9","Connecticut Ave. & Macomb St. NW");
cameraLOCATIONS[19] = new cameraStructure("200042","9","Wisconsin Ave. & Massachusetts Ave. NW");
cameraLOCATIONS[20] = new cameraStructure("200032","9","Rhode Island Ave. & S. Dakota Ave. NE");
cameraLOCATIONS[21] = new cameraStructure("200030","9","Connecticut Ave. & Calvert  St. NW");
cameraLOCATIONS[22] = new cameraStructure("200018","9","Georgia Ave. & Kansas Ave. NW");
cameraLOCATIONS[23] = new cameraStructure("200016","9","16th St. & Irving St. NW");
cameraLOCATIONS[24] = new cameraStructure("200015","9","Georgia Ave. & Eastern Ave. NW");
cameraLOCATIONS[25] = new cameraStructure("200014","9","16th St. & Harvard St. & Mount Pleasant NW");
cameraLOCATIONS[26] = new cameraStructure("200012","9","Georgia Ave. & Irving St. NW");
cameraLOCATIONS[27] = new cameraStructure("200011","15","Delaware Ave. & I St. SW");
cameraLOCATIONS[28] = new cameraStructure("200001","9","Georgia Ave. & New Hampshire Ave. NW");
cameraLOCATIONS[29] = new cameraStructure("200166","10","Massachusetts Ave NW & WhiteHaven Ave  N W");
cameraLOCATIONS[30] = new cameraStructure("200142","10","South Capitol St & Atlantic St SE");
cameraLOCATIONS[31] = new cameraStructure("200140","10","Wisconsin Ave  NW & Q St  N W");
cameraLOCATIONS[32] = new cameraStructure("200132","10","Southern Ave  & Branch Ave  S E");
cameraLOCATIONS[33] = new cameraStructure("200131","10","Alabama Ave  SE & Branch Ave  S E");
cameraLOCATIONS[34] = new cameraStructure("200127","10","Pennsylvania Ave SE & 8th St  S E");
cameraLOCATIONS[35] = new cameraStructure("200116","10","Pennsylvania Ave SE & Branch Ave  S E");
cameraLOCATIONS[36] = new cameraStructure("200115","10","South Capitol & Southern Ave");
cameraLOCATIONS[37] = new cameraStructure("200114","10","Wisconsin Ave  NW & M St  NW");
cameraLOCATIONS[38] = new cameraStructure("200089","10","N. Capitol St. & Rhode Island Ave. NW");
cameraLOCATIONS[39] = new cameraStructure("200084","10","9th St. Ramp & New York Ave. NE (Brentwood Pkwy)");
cameraLOCATIONS[40] = new cameraStructure("200081","10","36th St. & Benning Rd. (Ramp from/to Kenilworth Frwy) NE");
cameraLOCATIONS[41] = new cameraStructure("200064","10","Pennsylvania Ave. & Minnesota Ave. SE");
cameraLOCATIONS[42] = new cameraStructure("200043","10","Canal Rd. & Foxhall Rd. NW");
cameraLOCATIONS[43] = new cameraStructure("200031","10","15th St. & H St. & Benning Rd NE");
cameraLOCATIONS[44] = new cameraStructure("200021","10","New York Ave. & Bladensburg Rd. NE");
cameraLOCATIONS[45] = new cameraStructure("200020","10","SE Freeway & Sousa Bridge & Pennsylvainia Ave. SE");
cameraLOCATIONS[46] = new cameraStructure("200019","10","S. Capitol St. & Suitland Pkwy. SE");
cameraLOCATIONS[47] = new cameraStructure("200013","10","16th St. & U St. NW");
cameraLOCATIONS[48] = new cameraStructure("200003","10","Key Bridge & M St. NW");
cameraLOCATIONS[49] = new cameraStructure("200128","12","Pennsylvania Ave SE & Alabama Ave  SE");
cameraLOCATIONS[50] = new cameraStructure("200083","12","E. Capitol & 58th St.");
cameraLOCATIONS[51] = new cameraStructure("200037","12","E. Capitol & Southern Ave.");
cameraLOCATIONS[52] = new cameraStructure("200035","12","Benning Rd. & Minnesota NE");
cameraLOCATIONS[53] = new cameraStructure("200034","12","Benning Rd. & East Capitol NE");
cameraLOCATIONS[54] = new cameraStructure("200006","12","Kenilworth & Eastern Ave NE");
cameraLOCATIONS[55] = new cameraStructure("200165","15","15th St NW & Pennsylvania Ave/Lower E St NW");
cameraLOCATIONS[56] = new cameraStructure("200164","15","15th St NW & K St NW");
cameraLOCATIONS[57] = new cameraStructure("200163","15","13th St NW & K St NW");
cameraLOCATIONS[58] = new cameraStructure("200162","15","13th St & H St NW & New York Ave NW");
cameraLOCATIONS[59] = new cameraStructure("200161","15","16th St NW & I St NW");
cameraLOCATIONS[60] = new cameraStructure("200160","15","17th St NW & I St NW");
cameraLOCATIONS[61] = new cameraStructure("200159","15","18th St NW & I St NW");
cameraLOCATIONS[62] = new cameraStructure("200158","15","13th St NW & I St NW");
cameraLOCATIONS[63] = new cameraStructure("200157","15","14th St NW & I St NW");
cameraLOCATIONS[64] = new cameraStructure("200156","15","15th St/New York Avenue/Pennsylvania Ave/G St NW");
cameraLOCATIONS[65] = new cameraStructure("200155","15","H Street NW & Vermont Avenue & Madison Ave NW");
cameraLOCATIONS[66] = new cameraStructure("200154","15","H St NW & Connecticut Avenue & Jackson Place NW");
cameraLOCATIONS[67] = new cameraStructure("200153","15","21st St NW & Pennsylvania Avenue & I St  NW");
cameraLOCATIONS[68] = new cameraStructure("200152","15","19th St NW & Pennsylvania Avenue & H St  NW");
cameraLOCATIONS[69] = new cameraStructure("200151","15","17th St NW & Pennsylvania Avenue NW");
cameraLOCATIONS[70] = new cameraStructure("200150","15","17th St NW & Lower E St NW");
cameraLOCATIONS[71] = new cameraStructure("200148","15","14th St NW & New York Avenue NW");
cameraLOCATIONS[72] = new cameraStructure("200147","15","14th St NW & Pennsylvania Ave  NW");
cameraLOCATIONS[73] = new cameraStructure("200146","15","14th St SW  & Independence N W");
cameraLOCATIONS[74] = new cameraStructure("200145","15","20th St  NW & Constitution Ave  N W");
cameraLOCATIONS[75] = new cameraStructure("200144","15","3rd St  NW & Constitution Ave  N W");
cameraLOCATIONS[76] = new cameraStructure("200143","15","7th St & Frontage Road SW");
cameraLOCATIONS[77] = new cameraStructure("200138","15","23rd St NW& Constitution Ave NW");
cameraLOCATIONS[78] = new cameraStructure("200137","15","17th St  NW & Constitution Ave  N W");
cameraLOCATIONS[79] = new cameraStructure("200136","15","New Jersey Ave  NW & New York Ave  N W");
cameraLOCATIONS[80] = new cameraStructure("200135","15","2nd St NW & H St NW");
cameraLOCATIONS[81] = new cameraStructure("200134","15","3rd St & H St & Mass Ave N W");
cameraLOCATIONS[82] = new cameraStructure("200133","15","21st St  NW & K St N W");
cameraLOCATIONS[83] = new cameraStructure("200130","15","Pennsylvania Ave NW & 28th St  N W");
cameraLOCATIONS[84] = new cameraStructure("200129","15","Pennsylvania Ave  NW & 9th St  N W");
cameraLOCATIONS[85] = new cameraStructure("200126","15","15th St  NW & Constitution N W");
cameraLOCATIONS[86] = new cameraStructure("200125","15","16th St  NW & K St  N W");
cameraLOCATIONS[87] = new cameraStructure("200113","15","Independence Ave  SW & Washington Ave  S W");
cameraLOCATIONS[88] = new cameraStructure("200112","15","9th St NW & Constitution Ave  NW");
cameraLOCATIONS[89] = new cameraStructure("200111","15","12th St  NW & Constitution Ave  NW");
cameraLOCATIONS[90] = new cameraStructure("200107","15","16th St. & Scott Circle NW");
cameraLOCATIONS[91] = new cameraStructure("200106","15","Virginia Ave & E St. NW");
cameraLOCATIONS[92] = new cameraStructure("200105","15","14th St. & Pennsylvania Ave. NW");
cameraLOCATIONS[93] = new cameraStructure("200102","15","3rd St. & Constitution Ave. NW");
cameraLOCATIONS[94] = new cameraStructure("200088","15","7th St. & Rhode Island Ave. NW");
cameraLOCATIONS[95] = new cameraStructure("200087","15","7th St. & New York Ave. NW");
cameraLOCATIONS[96] = new cameraStructure("200085","15","N. Capitol St. & New York Ave. NE");
cameraLOCATIONS[97] = new cameraStructure("200080","15","7th St. & H St. NW");
cameraLOCATIONS[98] = new cameraStructure("200078","15","3rd St. & H St. NE");
cameraLOCATIONS[99] = new cameraStructure("200073","15","24th St. & K St. & Penn Ave NW");
cameraLOCATIONS[100] = new cameraStructure("200072","15","19th St. & K St. NW");
cameraLOCATIONS[101] = new cameraStructure("200062","15","Pennsylvania Ave. & 2nd St. SE");
cameraLOCATIONS[102] = new cameraStructure("200049","15","Connecticut Ave. & Florida Ave. NW");
cameraLOCATIONS[103] = new cameraStructure("200041","15","27th St. & Whitehurst Freeway & K St. NW");
cameraLOCATIONS[104] = new cameraStructure("200039","15","Dupont Circle NW");
cameraLOCATIONS[105] = new cameraStructure("200036","15","7th St. & Pennsylvania Ave. NW");
cameraLOCATIONS[106] = new cameraStructure("200023","15","7th St. & Independence Ave. SW");
cameraLOCATIONS[107] = new cameraStructure("200009","15","14th St. Bridge SW");
cameraLOCATIONS[108] = new cameraStructure("200007","15","4th St. & New York Ave. NE");
cameraLOCATIONS[109] = new cameraStructure("200005","15","Florida Ave & New York Ave NE");
cameraLOCATIONS[110] = new cameraStructure("200004","15","S. Capitol & M St.");
cameraLOCATIONS[111] = new cameraStructure("200002","15","Connecticut Ave. & K St. & 17th St. NW");

function checkARRAY(keyword) {
	var rx = new RegExp(keyword, 'i');
	var myIterator = 0;
    for (i = 0; i < cameraLOCATIONS.length; i++) {
		var rec = cameraLOCATIONS[i];
		for (x in rec) {
			if (rx.test(rec[x]) == true) {
				xoption = i;
				myIterator++;
				break;
            }
        }
    }
}

function setParameters(selCAM){
	sCamId = cameraLOCATIONS[selCAM].idNUMBER;
	sLocation = cameraLOCATIONS[selCAM].idLOCATION;
	viewCamera(sCamId,sLocation);
	document.getElementById("p1").className = "red";
	document.getElementById("r1").className = "red";
}

function setParameters2(selCAM2){
	checkARRAY(selCAM2);
	selCAM2 = xoption;
	sCamId = cameraLOCATIONS[selCAM2].idNUMBER;
	sLocation = cameraLOCATIONS[selCAM2].idLOCATION;
	viewCamera(sCamId,sLocation);
	document.getElementById("p1").className = "red";
	document.getElementById("r1").className = "red";
}

function runOnLoad(){
	if(bRunUpdate){
    	document.images['cameraWindow'].src = 'http://web007.dc.gov/camera/'+sUpdatingCamId+'/live.jpg?'+ Math.random();
  	}
   	timerRef = setTimeout('runOnLoad()',iUpdateSpeed);
}

function viewCamera(sCamId,sLocation){
	window.document.cameraLocationForm.cameraLocationText.value= sLocation;
	bRunUpdate=true;
	sUpdatingCamId = sCamId;
}

function stopUpdate(){
	if(sCamId != "720") {
		bRunUpdate=false;
	} //else { alert ("Pause Disabled");}
}

function restartUpdate(){
	if(sCamId != "720") {
		bRunUpdate=true;
	} //else { alert ("Restart Disabled");}
}

function updateSpeed(sSpeed){
	switch (sSpeed){
	    case "dialup":
	      iUpdateSpeed=4000;
	    break
	    case "broadband":
	      iUpdateSpeed=2000;
	    break
  	}
}
