var nn4;
var wmpV;
GetCaps();

function GetCaps() {
	var agt = navigator.userAgent.toLowerCase();
    var nn = ((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1)
		&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1)
		&& (agt.indexOf('webtv') == -1) && (agt.indexOf('hotjava') == -1));
	var major = parseInt(navigator.appVersion);
	nn4 = nn && (major == 4);
}

/*function GetWM() {
	var wm = 0;
	var uastr = navigator.userAgent.toLowerCase();
	var uaver = navigator.appVersion.toLowerCase();
	var iePos = uastr.indexOf("msie");
	var isIE = ((iePos != -1) && (uastr.indexOf("opera") == -1) && (uastr.indexOf("safari") == -1) && (uastr.indexOf("konqueror") == -1));
	var isWin =((uastr.indexOf("win") != -1) || (uastr.indexOf("16bit") != -1));
	if(isIE && isWin){
		var uv = parseInt(uaver.substring(iePos + 5, uaver.indexOf(';', iePos)));
		if(uv >= 5){
			document.body.insertAdjacentHTML("afterBegin", "<span id=\"cc\" style=\"behavior:url(#default#clientCaps)\"></span>");
			function GetVer(ID){
				var v;
				if(cc){
					v = cc.getComponentVersion(ID,"componentid");
					if (v) {
						v = v.replace(/,/g, ".");
					}
					else {
						v = "";
					}
				}
				else v = "";
				return v;
			}
			wm = GetVer("{6BF52A52-394A-11D3-B153-00C04F79FAA6}");
			if (!wm) {
				wm = GetVer("{22D6F312-B0F6-11D0-94AB-0080C74C7E95}");
			}
		}
		else wm = VbGetWM();
	}
	else{
		var Ps = navigator.plugins;
		var MTs = navigator.mimeTypes;
		if (Ps && MTs) {
			for(var i=0; i < Ps.length; i++) {
				var P = Ps[i];
				if (P) {
					var PN = P.name;
					var PD = P.description;
					if (PN && PD) {
						if ((PN.indexOf("Windows Media") != -1) && (PN.indexOf("Plug") != -1)) {
							wm = 1;
							var WM7 = MTs[isWin ? "application/x-drm-v2" : "application/x-ms-wmd"];
							if (WM7 && WM7.enabledPlugin) {
								wm = "7";
							}
							else if (MTs["video/x-ms-wm"] && MTs["video/x-ms-wmv"]) {
								wm = "6.4";
							}
							else if (MTs["video/x-ms-asf"]) {
								wm = "6.3";
							}
							else {
								var MP2 = MTs["application/x-mplayer2"];
								if (MP2 && MP2.enabledPlugin) {
									wm = "5.2";
								}
							}
						}
					}
				}
			}
		}
    }
    return wm;
}
*/
function OpenMeetingInfo(meeting) {
	var url = "MeetingInfo.aspx?Meeting=" + meeting;
	window.open(url, "ParliamentLiveMeetingInfo", "width=480,height=400,scrollbars=yes");
}

function OpenNotes(meeting) {
	var s = new String(meeting);
	var sLength = s.length;
	for(var i = 0; i < 8 - sLength; i++){
		s = "0" + s;
	}
	var url = "notes/" + s + ".pdf";
	window.open(url, "ParliamentLiveNotes", "width=700,height=550,resizable=yes");
}

var baseTime = null;
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
function InitClock(time) {
	if ((arguments.length > 0) && (time != null)) {
		baseTime = new Date(time);
	}
	else {
		window.setInterval("UpdateClock()", 30000);
	}
	UpdateClock();
}
function UpdateClock() {
	var content = "";
	var time = baseTime;
	if (time == null) {
		time = new Date();
		var hrs = time.getHours();
		var ampm = "am";
		if (hrs > 11) {
			if (hrs > 12) {
				hrs = hrs - 12;
			}
			ampm = "pm";
		}
		var mins = new String(time.getMinutes());
		if (mins.length < 2) {
			mins = "0" + mins;
		}
		content = "&nbsp;&nbsp;" + hrs + ":" + mins + ampm;
	}
	content = days[time.getDay()] + " " + time.getDate() + " " +  months[time.getMonth()] + " " + time.getFullYear() + content + "&nbsp;&nbsp;";
	SetSpan("clockSpan", content);
}

function StyleDisplay(id, d) {
	HtmlObject(id).style.display = d ? "inline" : "none";
}
function HtmlObject(id) {
	var obj = null;
	if (document.getElementById) {
		obj = document.getElementById(id);
	}
	else if (document.all) {
		obj = document.all[id];
	}
	return obj;
}

function SetSpan(id, content) {
	var span = HtmlObject(id);
	if (span != null)
	{
		span.innerHTML = content;
	}
}
	
function GetSpan(id) {
	var span = HtmlObject(id);
	if (span != null)
	{
		return span.innerHTML;
	}
}
function StyleDisplay(id, d) {
	HtmlObject(id).style.display = d ? "inline" : "none";
}	
function GetUpdateURL() {
	var s = "UpdatePage.aspx";
	alert(s);
	return s;
	}


//Console functions
function ConsoleUrl(encoding, startAt) {
	var url = "Console.aspx?Encoding=" + encoding;
	if ((arguments.length > 1) && (typeof(startAt) != "undefined") && (startAt != null)) {
		url = url + "&StartAt=" + startAt;
	}
	return url;
}
function OpenConsole(encoding, startAt) {
	window.open(ConsoleUrl(encoding, startAt), "ParliamentLiveConsole", "width=800,height=600");
}
function SwitchConsole(encoding) {
	var consoleWindow = null;
	switch (channelsType) {
		case "Popup":
			consoleWindow = window.opener;
			break;
		case "Embed":
			consoleWindow = window.parent;
			break;
	}
	if (consoleWindow != null) {
		consoleWindow.document.location.href = ConsoleUrl(encoding);
	}
}
var feed = null;
var controlsHeight = -1;
var playerHeight = -1;
function ConsoleLoad(t, f, cH, pH) {
	feed = f;
	controlsHeight = cH;
	playerHeight = pH;
	if (nn4) {
		document.appObs.setByProxyDSScriptCommandObserver(document.wmpEmbed, true);   
	}
	InitClock(t);
}
function Animate(a) {
	if ((controlsHeight != -1) && (playerHeight != -1)) { 
		if (feed == "Audio") {
			StyleDisplay("audioScreen", !a);
		}
		else {
			HtmlObject("wmp").height = a ? controlsHeight : playerHeight;
		}
		StyleDisplay("swf", a);
	}
}
function OnScript(t, p) {
	if (t == "CAPTION") {
		if (nn4) {
			p = new String(p);
		}
		p = p.replace(/\n/g,"<br>");
	}
	
		if(t=="MODSlide") {
		var scArr = p.split(",");
		// add prevailing zeros if the string is less than 3 chars long
		if(scArr[1].length==1){scArr[1]="00"+scArr[1]};
		if(scArr[1].length==2){scArr[1]="0"+scArr[1]};
		document.images["imgSlide"].src = "slides/" + scArr[0] + "/slide" + scArr[1] + ".jpg";
	}
	else if(t=="MODCaption") {
		SetSpan("caption", p);
	}
	else if(t=="MOD_Test") {
		alert(p);
	}

}
var channelsWindow = null;
var channelsType = nn4 ? "Popup" : "Embed";
function OpenChannels() {
	var url = "Channels.aspx?Type=" + channelsType;
	if (channelsType == "Popup") {
		channelsWindow = window.open(url, "Channels", "width=192,height=144");
	}
	else {
		var channels = HtmlObject("channelsFrame");
		var f = (channels.style.display == "none");
		StyleDisplay("captionsSpan", !f);
		StyleDisplay("channelsFrame", f);
		channels.src = f ? url : "";
	}
}
function ConsoleUnload() {
	if ((channelsWindow != null) && (!channelsWindow.closed)) {
		channelsWindow.close();
	}
}
