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)
{
	// don't reload the player if still on the same camera
	/*
	if (currentName == img_name && firstLoad == false)
		return(1);
	*/

	//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
	
	
/*
	var localTimeOffset = 60 * theDate.getTimezoneOffset(); //get local computer time's offset in seconds
	var GMTtime = unixtimestamp + localTimeOffset;  //create true GMT time
	NJ_GMTtime = GMTtime -  (60*60*5); //convert time into local NJ/Eastern time
	//unixtimestamp = NJ_GMTtime;
	unixtimestamp = GMTtime;
*/
	
	
	//alert(Date(unixtimestamp));
	
	//xml_link = xml_link + ".xml";
	//alert(" | forceReload: "+forceReload+" | 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
		// loading the media player in an iframe since innerHTML is borked under IE with mediaplayer.  the instance
		//  does not deallocate, but rather stays.  It's messed up right?
		var mediaPlayerCode = '<iframe width="320" height="280" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="player_frame.html?streamingName='+streamingName+'"></iframe>';
		
		
		//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
		
		//alert(unixtimestamp);
		
	
		if (cam_type=="multiview") {
			var playerName = "/swf/multiview_player/rotating_loader-r2.swf?/ts2009/xml/rotation_list,"+unixtimestamp+",yes";
			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.
				// second yes/no param is for showing ads
				var playerName = "/swf/event_player/event_loader_xml.swf?"+xml_link+","+unixtimestamp+",no,yes";				
				//var playerName = "/swf/event_player/event_loader_xml_1.swf?"+xml_link+","+unixtimestamp+",yes,yes";
				
				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";
		document.getElementById("multicambar").className = "navBarOff";
	}
	else if (num=="multiview")
	{
		document.getElementById("tsqliveBar").className = "navBarOff";
		document.getElementById("livecamsBar").className = "navBarOff";
		document.getElementById("multicambar").className = "navBarHover";
	}
	else
	{
		document.getElementById("tsqliveBar").className = "navBarOff";
		document.getElementById("livecamsBar").className = "navBarHover";
		document.getElementById("multicambar").className = "navBarOff";
	}

	
	//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);
	}
}