function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  //alert('Query Variable ' + variable + ' not found');
}

//showPlayer('/newyears/ts/streaming','streaming','streaming',streamingPath,'TS','-5','55');
function showPlayer(xml_link,cam_type,img_name,streamingName,camLoc,cID,showArchives)
{
//local time information to be passed into the swf
//time and location config
var theDate = new Date(); //create a new date object
var unixtimestampMilliseconds = theDate.getTime(); //get the unixtimestamp (which is in ms)
var unixtimestamp = Math.ceil(unixtimestampMilliseconds/1000); //get the timestamp in seconds

//alert(unixtimestamp);
//alert(BrowserDetect.browser+" | forceReload: "+forceReload+" | tz_adjusted: "+tz_adjusted+" | xml_link: "+xml_link+" | cam_type: "+cam_type+" | "+streamingName);

if(cam_type == "streaming") {
	//if we're displaying a streaming cam, write out the media player as well as the left and right flash panels
	var mediaPlayerCode = 
		"<!-- <div style=\"margin:0px 2px 0px 2px; width:352px; height:300px; text-align:left;\"> -->" +
			"<!-- <p style=\"height:15px; font-size:1px;\">&nbsp;</p> -->" +
			"<object classid=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" " +
					"codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715\" " +
					"type=\"application/x-oleobject\" width=\"320\" height=\"280\" border=\"0\" " +
					"standby=\"Loading Microsoft Windows Media Player components...\" id=\"MediaPlayer\"> " +
			     "<param name=\"FileName\" VALUE=\""+streamingName+"\">" +
			     "<param name=\"AnimationatStart\" VALUE=\"true\">" +
			     "<param name=\"TransparentatStart\" VALUE=\"true\">" +
			     "<param name=\"AutoStart\" VALUE=\"true\">" +
				"<param name=\"ShowControls\" VALUE=\"1\">" +
				"<param name=\"ShowStatusBar\" value=\"False\">" +
			     "<embed type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=Media&sba=Plugin&\" " +
			     "src=\""+streamingName+"\" Name=\"MediaPlayer\" ShowControls=\"1\" showstatusbar=\"0\" width=\"320\" height=\"280\"></embed></object>" +
			
			"<!-- <div style=\"height:15px;\"><p id=\"vid_load\" style=\"text-align:center; color:#FFFFFF; margin:5px 0px 5px 0px; font-size:11px;\">Video may take a minute to load.</p></div> -->" +  
			"<!-- <iframe src=\"/swf/cam_player/load_copy.html\" frameborder=\"0\" width=\"352\" height=\"15\" scrolling=\"no\" style=\"margin-top:15px; background-color:#000000;\"></iframe> --></div>\n";
		"</div>";
	
	/*
			"<param name=\"ShowControls\" VALUE=\"1\">" +
			"<param name=\"ShowStatusBar\" value=\"True\">" +
	*/
	
	
	//write the above html to the ecnetworkcam div tag
	document.getElementById('ecnetworkcam').innerHTML = "";
	document.getElementById('ecnetworkcam').innerHTML = mediaPlayerCode;
		
	currentType = "streaming";
	//startClock();
} else { //the camera is not streaming, display the ec network flash player
	var doReload = false;
	//if( firstLoad==true || (currentLocation == "TS" && camLoc != "TS") || (currentLocation != "TS" && camLoc == "TS") || camLoc != "TS" ) {
	if( firstLoad==true || currentType=="multiview") {
		doReload = true;
		firstLoad = false;
	}
	
	//figure out if we need to reload the flash player, based on what state we're currently in
	// - if we're coming from the streaming media plugin or the multiview player, we need to reload the flash player
	// - multiview player will just force a reload of the player
	

	if (cam_type=="multiview") {
		var playerName = "/swf/multiview_player/rotating_loader-r2.swf?/ts2008/xml/rotation_list,"+unixtimestamp;
		var so = new SWFObject(playerName, "movie", "320", "265", "8", "#000000");
		so.write("ecnetworkcam");
		currentType = "multiview";
		currentFlashSize = "small";
	} else if ( (cam_type=="flash" && currentType=="streaming") || forceReload == 1 || doReload == true ) { //redraw the ec network flash player
		//alert("reloading the network player components");
	
		// reoutput the flash area
		//320 x 265
		// example: .swf?/cams/newyork/timessquare/fridays,-5,1165433218,55,
		
		//alert("alert 1");
		if (showArchives==true) {
			var playerName = "/swf/event_player/dotcom_archive_loader.swf?"+xml_link+",'-5',"+unixtimestamp;
			var so = new SWFObject(playerName, "movie", "322", "281", "8", "#000000");
		} else {
			//alert("alert 2");
			//the yes parameter is for telling the player to use .xml.xmlz files instead of .xml as it
			//	will normally do.
			var playerName = "/swf/event_player/event_loader_xml.swf?"+xml_link+","+unixtimestamp+",yes";
			//var playerName = "/swf/event_player/event_loader_xml.swf?"+xml_link+","+unixtimestamp;
			var so = new SWFObject(playerName, "movie", "320", "265", "8", "#000000");
		}
		
		var browser=navigator.appName; var b_version=navigator.appVersion; var version=parseFloat(b_version);
		if (browser=="Microsoft Internet Explorer") {
			//MediaPlayer.stop();
		}
		
		document.getElementById('ecnetworkcam').innerHTML = "";
		so.write("ecnetworkcam");
		currentType = "flash";
		currentFlashSize = "small";
	} else { //just do the normal instant switching
		//insta-switch
		//alert("alert 3");
		document.getElementById('movie').switchCamera(xml_link);
	}
}


currentName = img_name;
currentLocation = camLoc;
//alert(doReload+" | currentLocation: "+currentLocation+" | camLoc passed: "+camLoc);
document.getElementById('descriptionArea').innerHTML = camDesc[img_name];   

}//end function

function changeHighlight(num,wcs_link,isThisWorldCam)
{
	//alert("changing highlight "+num);
	//if (isThisWorldCam == 'yes') { alert("world cam is yes"); }
	var totalCams = numCamsVar + numWorldCamsVar;
	
	//cycle through the regular thumbnail cams
	var i = 1;
	//for (i=1; i<=totalCams; i++) {
	for (x in tsCamArray) { //this is like a php foreach loop
		var thumbtext = "thumbtext" + tsCamArray[x];
		var img = "img" + tsCamArray[x];
		var imgExists = eval(document.getElementById(img));
		
		if (tsCamArray[x]==num) {//current x matches the id number sent, turn it "on"
			if (i > numCamsVar) {
				document.getElementById(thumbtext).className = "worldCamLinkHover";
			} else {
				document.getElementById(thumbtext).style.color = "#FF0000";
			}
			
			if (imgExists) {document.getElementById(img).className = "camThumbOver";}
			currentCam = num;
		} else { //turn highlight off
			if (i > numCamsVar) {
				document.getElementById(thumbtext).className = "worldCamLink";
			} else {
				document.getElementById(thumbtext).style.color = "#000000";
			}
			
			if (imgExists) {document.getElementById(img).className = "camThumb";}			
		}
		//alert (numCamsVar + " | " + i);
		i++;
	}//end for loop
	
	if (num=="streaming") {
		document.getElementById("tsqliveBar").className = "navBarHover";
		document.getElementById("livecamsBar").className = "navBarOff";
	} else {
		document.getElementById("tsqliveBar").className = "navBarOff";
		document.getElementById("livecamsBar").className = "navBarHover";
	}

	
	//document.getElementById('wcsLink').href = "http://www.webcamstore.com/professional/product.php?systemid=" + wcs_link;
}

function hoverThumb(num,classText) {
	var thumbtext = "thumbtext" + num;
	if (num != currentCam) {
		document.getElementById("img" + num).className = classText;
	}
}

function statusMsg(msg) { window.status=msg; return true; }


//unused function, probably should be rewritten at some point
function navLinks(currentName,gotoPane) {
	if (currentType == "streaming") {
		changeHighlight('fridays','115','no');
		showPlayer('/newyears/ts/fridays','flash','fridays','','TS','-5','55',gotoPane);	
	} else {
		document.getElementById('movie').switchTabPage(gotoPane);
	}
}