// Create a lat/lon object
var myPoint = new YGeoPoint(53.530564, -113.501172);
// Set up map type in the constructor
//var map = new YMap(document.getElementById('mapContainer'),YAHOO_MAP_SAT);
var map = new YMap(document.getElementById('mapContainer'));
// Add a pan control 
map.addPanControl();
// Add a slider zoom control 
map.addZoomLong();
// Display the map centered on a lattitude and longitude
map.drawZoomAndCenter(myPoint, 7);

//var streamosURI = 'http://boss.streamos.com/wmedia-live/coe';
var streamosURI = 'http://coe.edgeboss.net/wmedia-live/coe';


var geoPoints = new Array(
	new YGeoPoint(53.533931, -113.501129), // 97 Ave - 105 St (cam 1)
	new YGeoPoint(53.537221, -113.508468), // 99 Ave - 109 St (cam 2)
	new YGeoPoint(53.539644, -113.490057), // McDougall Hill (cam 3)
	new YGeoPoint(53.530564, -113.501172), // River Valley Rd - 105 St (cam 4)
	new YGeoPoint(53.537604, -113.44285),  // 98 Ave - 75 St (cam 5)
	new YGeoPoint(53.599483, -113.491945), // 137 Ave - 97 St (cam 6)
	new YGeoPoint(53.555759, -113.438902), // Capilano Bridge (cam 7)
	new YGeoPoint(53.507039, -113.567047), // Quesnell Bridge (cam 8)
	new YGeoPoint(53.611553, -113.591166), // St Albert Tr. - 156 St (cam 9)
	new YGeoPoint(53.523931, -113.511858), // Walterdale Hill - 109 St (cam 10)
	new YGeoPoint(53.581194, -113.557177),  // Yellowhead Tr - St Albert Tr (cam 11)
	new YGeoPoint(53.453765, -113.492546), // 23 Ave - Gateway Blvd (cam 12)
	new YGeoPoint(53.490407, -113.572004), // 53 Ave - Whitemud Dr (cam 13)
	new YGeoPoint(53.486922, -113.393669), // Whitemud Dr - 34 St (cam 14)
	new YGeoPoint(53.480436, -113.495808), // Whitemud Dr - Calgary Tr (cam 15)
	new YGeoPoint(53.480385, -113.491859), // Whitemud Dr - Gateway Blvd (cam 16)
	new YGeoPoint(53.579258, -113.590565), // Yellowhead Tr - 156 St (cam 17)
// added November 28, 2007
	new YGeoPoint(53.5122, -113.6152), // Whitemud Dr - 170 St (cam 18)
	new YGeoPoint(53.5165, -113.5258), // University Ave - 114 St (cam 19)

	new YGeoPoint(53.541148, -113.614772), // Stony Plain Rd - 170 St (cam 20)
	new YGeoPoint(53.511453, -113.630694), // Whitemud Dr - 178 St (cam 21)
	new YGeoPoint(53.511708, -113.597134), // Whitemud Dr - 159 St (cam 22)
	new YGeoPoint(53.513086, -113.579796), // Whitemud Dr - 149 St (cam 23)
	new YGeoPoint(53.502800, -113.558596), // Whitemud Dr - Fox Dr (cam 24)
	new YGeoPoint(53.481124, -113.571128), // Whitemud Dr - Terwillegar Dr (cam 25)
	new YGeoPoint(53.482707, -113.541816), // Whitemud Dr - 122 Street (cam 26)
	new YGeoPoint(53.483141, -113.517140), // Whitemud Dr - 111 Street (cam 27)
	new YGeoPoint(53.480230, -113.486713), // Whitemud Dr - 99 Street (cam 28)
	new YGeoPoint(53.483218, -113.467616), // Whitemud Dr - 91 Street (cam 29)
	new YGeoPoint(-53.485695, 113.442682), // Whitemud Dr - 75 Street (cam 30) // THIS CAM IS ON THE OTHER SIDE OF THE WORLD FOR NOW so I don't have to monkey with indexes all over the place.
	new YGeoPoint(53.487891, -113.418220), // Whitemud Dr - 50 Street (cam 31)
	new YGeoPoint(53.573918, -113.615717), // Yellowhead Trail - 170 Street (cam 32)
	new YGeoPoint(53.581161, -113.492335), // Yellowhead Trail - 97 Street (cam 33)
	new YGeoPoint(53.582143, -113.418785), // Yellowhead Trail - 50 Street (cam 34)
	new YGeoPoint(53.582013, -113.467500), // Yellowhead Trail - 82 Street (cam 35)
// added February 3, 2010
	new YGeoPoint(53.578380, -113.436995), //Yellowhead Tr - 62 St (cam 36)
	new YGeoPoint(53.578246, -113.443038), //Yellowhead Tr - 66 St (cam 37)
	new YGeoPoint(53.581309, -113.505247), //Yellowhead Tr - 107 St (cam 38)
	new YGeoPoint(53.580707, -113.525618), //Yellowhead Tr - 121 St (cam 39)
	new YGeoPoint(53.580777, -113.541143), //Yellowhead Tr - 127 St (cam 40)
	new YGeoPoint(53.572429, -113.639402), //Yellowhead Tr - 184 St (cam 41)
	new YGeoPoint(53.580557, -113.452957), //Yellowhead Tr - Fort Rd (cam 42)
	new YGeoPoint(53.574900, -113.383541), //Yellowhead Tr - Victoria Tr (cam 43)
	new YGeoPoint(53.512264, -113.525763), //76 Ave - 114 St (cam 44)
	new YGeoPoint(53.485249, -113.442914)  //Whitemud Dr - 75 St (cam 45)

);

var videos = new Array(
	'/16533/46_coe-cameraone_070201.asx?endtime=3600000',
	'/16534/46_coe-cameratwo_070201.asx?endtime=3600000',
	'/16535/46_coe-camerathree_070201.asx?endtime=3600000',
	'/16536/46_coe-camerafour_070201.asx?endtime=3600000',
	'/16538/46_coe-camerafive_070201.asx?endtime=3600000',
	'/16539/46_coe-camerasix_070201.asx?endtime=3600000',
	'/16540/46_coe-cameraseven_070201.asx?endtime=3600000',
	'/16541/46_coe-cameraeight_070201.asx?endtime=3600000',
	'/16542/46_coe-cameranine_070201.asx?endtime=3600000',
	'/16544/46_coe-cameraten_070201.asx?endtime=3600000',
	'/16543/46_coe-cameraeleven_070201.asx?endtime=3600000',
	'/16545/46_coe-cameratwelve_070201.asx?endtime=3600000',
	'/16546/46_coe-camerathirteen_070201.asx?endtime=3600000',
	'/16547/46_coe-camerafourteen_070201.asx?endtime=3600000',
	'/16548/46_coe-camerafifteen_070201.asx?endtime=3600000',
	'/16549/46_coe-camerasixteen_070201.asx?endtime=3600000',
	'/16550/46_coe-cameraseventeen_070201.asx?endtime=3600000',
	'/26483/46_coe-cameraeighteen_071031.asx?endtime=3600000',
	'/26484/46_coe-cameranineteen_071031.asx?endtime=3600000',
	'/48985/46_coe-stonyplain170st_081211.asx?endtime=3600000',
	'/48987/46_coe-whitemud178st_081211.asx?endtime=3600000',
	'/48988/46_coe-whitemud159st_081211.asx?endtime=3600000',
	'/48989/46_coe-whitemud149st_081211.asx?endtime=3600000',
	'/48990/46_coe-whitemudfox_081211.asx?endtime=3600000',
	'/48991/46_coe-whitemudterwillegar_081211.asx?endtime=3600000',
	'/48992/46_coe-whitemud122st_081211.asx?endtime=3600000',
	'/48993/46_coe-whitemud111st_081211.asx?endtime=3600000',
	'/48994/46_coe-whitemud99st_081211.asx?endtime=3600000',
	'/48995/46_coe-whitemud91st_081211.asx?endtime=3600000',
	'/48996/46_coe-whitemud75st_081211.asx?endtime=3600000',
	'/48997/46_coe-whitemud50st_081211.asx?endtime=3600000',
	'/48998/46_coe-yellowhead170st_081211.asx?endtime=3600000',
	'/48999/46_coe-yellowhead97st_081211.asx?endtime=3600000',
	'/49001/46_coe-yellowhead50st_081211.asx?endtime=3600000',
	'/49000/46_coe-yellowhead82st_081211.asx?endtime=3600000',
// added February 3, 2010
	'/59769/46_coe-yellowhead62st_100127.asx',
	'/59771/46_coe-yellowhead66st_100127.asx',
	'/59773/46_coe-yellowhead107st_100127.asx',
	'/59775/46_coe-yellowhead121st_100127.asx',
	'/59777/46_coe-yellowhead127st_100127.asx',
	'/59779/46_coe-yellowhead184st_100127.asx',
	'/59781/46_coe-yellowheadfort_100127.asx',
	'/59783/46_coe-yellowheadvictoria_100127.asx',
	'/59767/46_coe-76ave114st_100127.asx',
	'/48996/46_coe-whitemud75st_081211.asx'

);

var titles = new Array(
	'97 Ave - 105 St',
	'99 Ave - 109 St',
	'McDougall Hill',
	'River Valley Rd - 105 St',
	'98 Ave - 75 St',
	'137 Ave - 97 St',
	'Capilano Bridge',
	'Quesnell Bridge',
	'St Albert Tr. - 156 St',
	'Walterdale Hill - 109 St',
	'Yellowhead Tr - St Albert Tr',
	'23 Ave - Gateway Blvd',
	'53 Ave - Whitemud Dr',
	'Whitemud Dr - 34 St',
	'Whitemud Dr - Calgary Tr',
	'Whitemud Dr - Gateway Blvd',
	'Yellowhead Tr - 156 St',
	'Whitemud Dr - 170 St',
	'University Ave - 114 St',
	'Stony Plain Rd - 170 St',
	'Whitemud Dr - 178 St',
	'Whitemud Dr - 159 St',
	'Whitemud Dr - 149 St',
	'Whitemud Dr - Fox Dr',
	'Whitemud Dr - Terwillegar Dr',
	'Whitemud Dr - 122 St',
	'Whitemud Dr - 111 St',
	'Whitemud Dr - 99 St',
	'Whitemud Dr - 91 St',
	'Whitemud Dr - 75 St',
	'Whitemud Dr - 50 St',
	'Yellowhead Tr - 170 St',
	'Yellowhead Tr - 97 St',
	'Yellowhead Tr - 50 St',
	'Yellowhead Tr - 82 St',
// added February 3, 2010
	'Yellowhead Tr - 62 St',
	'Yellowhead Tr - 66 St',
	'Yellowhead Tr - 107 St',
	'Yellowhead Tr - 121 St',
	'Yellowhead Tr - 127 St',
	'Yellowhead Tr - 184 St',
	'Yellowhead Tr - Fort Rd',
	'Yellowhead Tr - Victoria Tr',
	'76 Ave - 114 St',
	'Whitemud Dr - 75 St'

 );

var directories = new Array(
	'97Ave105St',
	'99Ave109St',
	'McDougallHill',
	'RiverRd105St',
	'98Ave75St',
	'137Ave97St',
	'CapilanoBridge',
	'QuesnellBridge',
	'StAlbertTr156St',
	'WalterdaleHill109S',
	'YellowheadTrStAlbertTr',
	'23AveGateway',
	'53AveWhitemudDr',
	'WhitemudDr34St',
	'WhitemudDrCalgaryTr',
	'WhitemudDrGatewayBlvd',
	'YellowheadTr156St',
	'WhitemudDr170st',
	'UniversityAve114st',
	'StonyPlainRd170St',
	'WhitemudDr178St',
	'WhitemudDr159St',
	'WhitemudDr149St',
	'WhitemudDrFoxDr',
	'WhitemudDrTerwillegarDr',
	'WhitemudDr122St',
	'WhitemudDr111St',
	'WhitemudDr99St',
	'WhitemudDr91St',
	'WhitemudDr75St',
	'WhitemudDr50St',
	'YellowheadTr170St',
	'YellowheadTr97St',
	'YellowheadTr50St',
	'YellowheadTr82St',

// added February 3, 2010
	'YellowheadTr62St',
	'YellowheadTr66St',
	'YellowheadTr107St',
	'YellowheadTr121St',
	'YellowheadTr127St',
	'YellowheadTr184St',
	'YellowheadTrFortRd',
	'YellowheadTrVictoriaTr',
	'76Ave114St',
	'WhitemudDr75St'

	);

var directions = new Array(
	'e,w',					//'97Ave105St',
	'n,s',					//'99Ave109St',
	'n,sw,s',				//'McDougallHill',
	'sw,s',					//'RiverRd105St',
	'n,e,s,w',				//'98Ave75St',
	'n,e,s,w',				//'137Ave97St',
	's',					//'CapilanoBridge',
	's',					//'QuesnellBridge',
	'nw,se',				//'StAlbertTr156St',
	'nw,e,s',				//'WalterdaleHill109S',
	'n,e,s,w',				//'YellowheadTrStAlbertTr',
	'n,e,s,w',				//'23AveGateway',
	'n,s',					//'53AveWhitemudDr',
	'e,s,w',				//'WhitemudDr34St',
	'n,s,w',				//'WhitemudDrCalgaryTr',
	'n,s',					//'WhitemudDrGatewayBlvd',
	'n,e,s,w',				//'YellowheadTr156St',
	'n,e,w',				//'WhitemudDr170st',
	'n,se,sw,w',			//'UniversityAve114st',
	'n,e,s,w',				//'StonyPlainRd170St',
	'n,e,s,w',				//'WhitemudDr178St',
	'n,e,w',				//'WhitemudDr159St',
	'se,sw',				//'WhitemudDr149St',
	'e,w',					//'WhitemudDrFoxDr',
	'n,e,s',				//'WhitemudDrTerwillegarDr',
	'n,e,w',				//'WhitemudDr122St',
	'e,w',					//'WhitemudDr111St',
	'n,e,s,w',				//'WhitemudDr99St',
	'n,e,s,w',				//'WhitemudDr91St',
	'n',					//'WhitemudDr75St',  ????????????
	'n,e,s,w',				//'WhitemudDr50St',
	'n,e,s,w',				//'YellowheadTr170St',
	'n,e,s,w',				//'YellowheadTr97St',
	'n,e,s,w',				//'YellowheadTr50St',
	'n,e,s,w',				//'YellowheadTr82St'

// added February 3, 2010
	'e,w',					// YellowheadTr62St',
	'n,e,s,w',				// YellowheadTr66St',
	'e,s,w',				// YellowheadTr107St',
	'e,s,w',				// YellowheadTr121St',
	'n,e,s,w',				// YellowheadTr127St',
	'n,e,s,w',				// YellowheadTr184St',
	'n,e,s,w',				// YellowheadTrFortRd',
	'n,e,s,w',				// YellowheadTrVictoriaTr',
	'n,e,s',				// 76Ave114St',
	'n,e,s,w'				// WhitemudDr75St'

	);

for (var i = 0; i < geoPoints.length; i++) {
	var marker = createYahooMarker(geoPoints[i], i);
	map.addOverlay(marker);
}

var directionNames = {
	n: 'North',
	s: 'South',
	e: 'East',
	w: 'West',
	sw: 'South West',
	ne: 'North East',
	se: 'South East',
	nw: 'North West'
};

function createYahooMarker(geopoint, num) {
	var myImage = new YImage();
	myImage.src = 'images/camera.gif';
	myImage.size = new YSize(22, 27);
	myImage.offsetSmartWindow = new YCoordPoint(0, 0);
	var marker = new YMarker(geopoint, myImage);
	var swtext = titles[num];
	YEvent.Capture(marker, EventsList.MouseClick,
	function() {
		showCameraNum(num);
		marker.openSmartWindow(swtext)
	});
	return marker;
}

function showCameraNum(idx) {
	var legend = document.getElementById('legend');
	legend.innerHTML = getThumbNailHTML(idx);
	var video = document.getElementById('videoContainer');
	if (is_ie) {
		try {
			var player = null;
			if (window.ActiveXObject) {
				player = new ActiveXObject("WMPlayer.OCX.7");
			}
		}
		catch (e) {
			//alert('error creating wmp');
		}

		if (player) {
			//alert('player version = ' + player.versionInfo);
			var test = parseInt(player.versionInfo);
			if (test >= 9) {
				video.innerHTML = getVideoHTML(idx);
			}
			else if (test <= 8) {
				video.innerHTML = '<div id="videoFeedBad"><p>Edmonton Traffic Cameras are viewable using Windows Media Player version 9 or higher.  Please <a href="http://www.microsoft.com/windows/windowsmedia/download/" target="_blank">click here</a> to download the latest version.<p></div>';
			}
		}
	}
	else {
		video.innerHTML = getVideoHTML(idx);
	}
}

function getThumbNailHTML(idx) {
	var dir = directories[idx];
	var viewDirections = directions[idx];
	if (viewDirections && viewDirections.length > 0) {
		var views = viewDirections.split(',');
		var html = '<h3 style="text-align: left;">Typical Views Facing:</h3>' + "\n" + '<table>' + "\n" + '<tr>' + "\n";
		for (var i = 0; i < views.length; i++) {
			var direction = directionNames[views[i]];
			var last = (i + 1 == views.length ? ' class="last"' : '');
			html += '<td' + last + '><img src="images/thumbs/' + currentSeason + dir + '/' + views[i] + '.jpg"';
			html += ' alt="' + direction + '" width="74" height="48" /></td>' + "\n";
		}
		html += '</tr>' + "\n" + '</table>' + "\n" + '<table id="camera">' + "\n" + '<tr>' + "\n";
		for (var i = 0; i < views.length; i++) {
			var direction = directionNames[views[i]];
			var last = (i + 1 == views.length ? ' class="last"' : '');
			html += '<td' + last + '>' + direction + '</td>' + "\n";
		}
		html += '</tr>' + "\n" + '</table>';
		return html;
	}
	return '';
}

function getVideoHTML(idx) {
	var url = streamosURI + videos[idx];
	var html = '<div id="videoTitle">' + titles[idx] + '</div>';
	html += '<div id="videoFeed">' + "\n";
	html += '<object>' + "\n";
	html += ' <param name="AudioStream" value="-1">' + "\n";
	html += ' <param name="AutoSize" value="-1">' + "\n";
	html += ' <param name="AutoStart" value="-1">' + "\n";
	html += ' <param name="AnimationAtStart" value="-1">' + "\n";
	html += ' <param name="AllowScan" value="-1">' + "\n";
	html += ' <param name="AllowChangeDisplaySize" value="-1">' + "\n";
	html += ' <param name="AutoRewind" value="0">' + "\n";
	html += ' <param name="Balance" value="0">' + "\n";
	html += ' <param name="BaseURL" value>' + "\n";
	html += ' <param name="BufferingTime" value="5">' + "\n";
	html += ' <param name="CaptioningID" value>' + "\n";
	html += ' <param name="ClickToPlay" value="-1">' + "\n";
	html += ' <param name="CursorType" value="0">' + "\n";
	html += ' <param name="CurrentPosition" value="-1">' + "\n";
	html += ' <param name="CurrentMarker" value="0">' + "\n";
	html += ' <param name="DefaultFrame" value>' + "\n";
	html += ' <param name="DisplayBackColor" value="0">' + "\n";
	html += ' <param name="DisplayForeColor" value="16777215">' + "\n";
	html += ' <param name="DisplayMode" value="0">' + "\n";
	html += ' <param name="DisplaySize" value="0">' + "\n";
	html += ' <param name="Enabled" value="-1">' + "\n";
	html += ' <param name="EnableContextMenu" value="-1">' + "\n";
	html += ' <param name="EnablePositionControls" value="-1">' + "\n";
	html += ' <param name="EnableFullScreenControls" value="0">' + "\n";
	html += ' <param name="EnableTracker" value="-1">' + "\n";
	html += ' <param name="Filename" value="' + url + '">' + "\n";
	html += ' <param name="InvokeURLs" value="-1">' + "\n";
	html += ' <param name="Language" value="-1">' + "\n";
	html += ' <param name="Mute" value="0">' + "\n";
	html += ' <param name="PlayCount" value="1">' + "\n";
	html += ' <param name="PreviewMode" value="0">' + "\n";
	html += ' <param name="Rate" value="1">' + "\n";
	html += ' <param name="SAMILang" value>' + "\n";
	html += ' <param name="SAMIStyle" value>' + "\n";
	html += ' <param name="SAMIFileName" value>' + "\n";
	html += ' <param name="SelectionStart" value="-1">' + "\n";
	html += ' <param name="SelectionEnd" value="-1">' + "\n";
	html += ' <param name="SendOpenStateChangeEvents" value="-1">' + "\n";
	html += ' <param name="SendWarningEvents" value="-1">' + "\n";
	html += ' <param name="SendErrorEvents" value="-1">' + "\n";
	html += ' <param name="SendKeyboardEvents" value="0">' + "\n";
	html += ' <param name="SendMouseClickEvents" value="0">' + "\n";
	html += ' <param name="SendMouseMoveEvents" value="0">' + "\n";
	html += ' <param name="SendPlayStateChangeEvents" value="-1">' + "\n";
	html += ' <param name="ShowCaptioning" value="0">' + "\n";
	html += ' <param name="ShowControls" value="1">' + "\n";
	html += ' <param name="ShowAudioControls" value="0">' + "\n";
	html += ' <param name="ShowDisplay" value="0">' + "\n";
	html += ' <param name="ShowGotoBar" value="0">' + "\n";
	html += ' <param name="ShowPositionControls" value="1">' + "\n";
	html += ' <param name="ShowStatusBar" value="0">' + "\n";
	html += ' <param name="ShowTracker" value="1">' + "\n";
	html += ' <param name="TransparentAtStart" value="0">' + "\n";
	html += ' <param name="VideoBorderWidth" value="0">' + "\n";
	html += ' <param name="VideoBorderColor" value="0">' + "\n";
	html += ' <param name="VideoBorder3D" value="0">' + "\n";
	html += ' <param name="Volume" value="-230">' + "\n";
	html += ' <param name="WindowlessVideo" value="0">' + "\n";
	html += ' <embed type="application/x-mplayer2" src="' + url + '" name="MediaPlayer" width="320" height="257" pluginspage="http://www.microsoft.com/isapi/redir.dll?prd=windows&amp;sbp=mediaplayer&amp;ar=media&amp;sba=plugin&amp;" autosize="0" autostart="1" showcontrols="0" showdisplay="0" showstatusbar="1" scale="ASPECT">' + "\n";
	html += ' </embed>' + "\n";
	html += '</object>' + "\n";
	html += '</div>' + "\n";

	return html;
}

function showMapView() {
	var mapView = document.getElementById('mapContainer');
	var listView = document.getElementById('listContainer');
	var mapLink = document.getElementById('mapContainerLink');
	var listLink = document.getElementById('listContainerLink');
	listView.style.display = 'none';
	mapView.style.display = 'block';
	listLink.className = '';
	mapLink.className = 'current';
}

function showListView() {
	var mapView = document.getElementById('mapContainer');
	var listView = document.getElementById('listContainer');
	var mapLink = document.getElementById('mapContainerLink');
	var listLink = document.getElementById('listContainerLink');
	mapView.style.display = 'none';
	listView.style.display = 'block';
	mapLink.className = '';
	listLink.className = 'current';
}