//<script>
var Node_Types = {Broadcast:"broadcast", Interval:"interval",Message:"message",Function:"function", Status:"status"};
var Co_Live_Broadcast = {UpdateInterval:60, PlayerWidth:448, PlayerHeight: 385,ArticleId:Request.Querystring("aid"), Feed:{aid:Request.Querystring("aid"), title:Request.Querystring("Jewish").replace(/-/gi, " "), text_status:"LIVE", media_type:"fl", live_status:true }, Notification_Text: "", UpdateInterval_Manager:new Co_Interval_Manager(), Countdown_Manager:null, Use_Countdown:false, Status:"", Status_Time: "", Status_Time_Diff:0, cachedState:"", EventHandlers:{}};
Co_Live_Broadcast.Init = function()
{
	if (typeof(default_mediaplayer_aid)!="undefined")
	{
		this.ArticleId = default_mediaplayer_aid;
		this.Feed.aid = this.ArticleId;
	}
	if (typeof(mediaplayer_width) != "undefined") this.PlayerWidth = mediaplayer_width;
	if (typeof(mediaplayer_height) != "undefined") this.PlayerHeight = mediaplayer_height;

	this.UpdateInterval_Manager.AddEventListener("interval", this.Begin_Get_Update, this);
	this.OnLoadComplete();
	this.AddEventListener("afterUpdate", this.OnAfterInitialLoad, this, []);
	if (!this.Begin_Get_Update()) this.Begin_Load_Media();
};
Co_Live_Broadcast.AddEventListener=function(evName, func, target_obj, paramsArray){var obj=this.EventHandlers[evName.toLowerCase()];if (typeof(obj)!="object")obj=[];if (typeof(obj.length)=="undefined") obj=[];obj.push({func:func,obj:target_obj,params:paramsArray});this.EventHandlers[evName.toLowerCase()]=obj;};
Co_Live_Broadcast.RemoveListeners=function(evName) {this.EventHandlers[evName.toLowerCase()]=[];};
Co_Live_Broadcast.FireEvent=function(evName){var obj=this.EventHandlers[evName.toLowerCase()];if (typeof(obj)!="object") return;if (typeof(obj.length)=="undefined") return;for (var i=0;i<obj.length;i++){this.RunEventHandler(obj[i].func, obj[i].obj, obj[i].params);}};
Co_Live_Broadcast.RunEventHandler=function(f,o,p){try {if(p)f.apply(o,[].concat(p));else f.apply(o);} catch (e){}};
Co_Live_Broadcast.OnLoadComplete = function()
{
	this.UpdateInterval_Manager.Start(this.UpdateInterval * 1000);
	//Co_Interval.Start(1000);
};
Co_Live_Broadcast.OnBeforeUnload = function()
{
	this.UpdateInterval_Manager.End();
	if (this.Countdown_Manager != null)
	{
		this.Countdown_Manager.End();
	}
};

Co_Live_Broadcast.Stop_Interval = function()
{
	this.UpdateInterval_Manager.End();
	if (this.Countdown_Manager != null)
	{
		this.Countdown_Manager.End();
	}
};
Co_Live_Broadcast.Begin_Get_Update = function()
{
	this.UpdateInterval_Manager.Pause();
	var args={func:this.End_Get_Update, obj:this,uri:"/multimedia/mediaplayer/co_live_broadcast.xml",method:"get"};
	ajax.disable_page=false;
	ajax.allow_multiple = false;
	return ajax.request(args);
};

Co_Live_Broadcast.End_Get_Update = function(obj)
{
	var xml=obj.responseXML;
	var root_node = xml.lastChild;
	this.Update_Data(root_node);
	this.FireEvent("afterUpdate");
	this.UpdateInterval_Manager.Resume();
};
Co_Live_Broadcast.Update_Data = function(xml)
{
	if (xml == null) return;
	this.Xml = xml;
	var node;
	for (var i=0;i<xml.childNodes.length;i++)
	{
		node=xml.childNodes[i];
		if (node.nodeType==3 || node.nodeType == 8) continue;
		switch (node.nodeName.toLowerCase())
		{
			case Node_Types.Broadcast :
				if (this.ArticleId == node.getAttribute("aid"))
				{
					this.Update_Feed(node);
				}
			break;
			case Node_Types.Interval :
				this.UpdateInterval_Manager.Milliseconds = (this.UpdateInterval = node.firstChild.nodeValue) * 1000;
			break;
			case Node_Types.Function :
				this.Run_Function(node);
			break;
			case Node_Types.Message :
				this.Notification_Text=this.Xml_to_Html(node);
				Co_Tools.RunFunction(this.ShowNotification, this, [], window);
			break;
			default:
				this[node.nodeName.toLowerCase()] = this.Xml_to_Html(node);
			break;
		}
	}
};
Co_Live_Broadcast.Set_Status = function(node)
{
	var info = node.getAttribute("status_info");
	this.Status = node.firstChild.nodeValue.toLowerCase();
	switch (this.Status)
	{
		case "broadcasting" :
			if (this.Countdown_Manager != null)
			{
				this.Countdown_Manager.End();
			}
			if (this.cachedState != this.Status)
			{
				this.Load_Media();
			}
		break;
		case "will begin" : 
			this.Unload_Player();
			if (typeof(this.StartInterval) == "undefined")
			{
				this.StartInterval = new Co_Interval_Manager();
				this.StartInterval.AddEventListener("interval", this.Begin_Get_Update, this);
			}
			
			var cur_time, start_time, diff, ms;
			if (node.getAttribute("status_time"))
			{
				this.Status_Time = node.getAttribute("status_time");

				cur_time = UTCTime.GetUTCMilliseconds();
				start_time = Date.parse(node.getAttribute("status_time"));
				this.Status_Time_Diff = diff = UTCTime.GetDateDifference(cur_time, start_time);
			}
			else
			{
				this.Status_Time = null;
			}
			if (!isNaN(diff) && diff > 0)
				ms = diff;
			else
				ms = node.getAttribute("status_info") * 1000;
			
			this.StartInterval.Loops = 1;
			this.StartInterval.Start(ms);
		break;
		case "finished" :
			this.Stop_Interval();
			this.Unload_Player();
			Co_Tools.RunFunction(this.ShowNotification, this, [], window);
		break;
	}
	
	if (this.cachedState != this.Status)
	{
		this.cachedState = this.Status;
		this.FireEvent("statusUpdated");
	}
};
Co_Live_Broadcast.Update_Feed = function(node)
{
	node=node.firstChild;
	while (node)
	{
		if (node.nodeType==3 || node.nodeType == 8)
		{
			node=node.nextSibling;
			continue;
		}
		switch (node.nodeName.toLowerCase())
		{
			case Node_Types.Interval :
				this.UpdateInterval_Manager.Milliseconds = (this.UpdateInterval = node.firstChild.nodeValue) * 1000;
			break;
			case Node_Types.Function :
				this.Run_Function(node);
			break;
			case Node_Types.Message :
				if (node.childNodes.length == 0)
				{
					this.Notification_Text = "";
				}
				else
				{
					switch (node.firstChild.nodeName.toLowerCase())
					{
						case "finished_message" : case "startup_message" : case "will_begin_message" :
							this.Notification_Text=this.Get_Node_Value(this.Xml, node.firstChild.nodeName);
						break;
						default:
							this.Notification_Text=this.Xml_to_Html(node);
						break;
					}
				}
				this.ShowNotification(this.Notification_Text);
			break;
			case Node_Types.Status :
				this.Set_Status(node);
			break;
		}
		this.Feed[node.nodeName.toLowerCase()] = this.Xml_to_Html(node, false);
		node=node.nextSibling;
	};
	
	var obj=document.getElementById('player_title');
	if (obj) obj.innerHTML=this.Feed.title;
	obj=document.getElementById('player_text_status');
	if (obj) obj.innerHTML=this.Feed.text_status;
};
Co_Live_Broadcast.Run_Function = function(node)
{
	if (node.childNodes.length == 0) return;
	var func = node.firstChild.nodeValue;
	if (func.toLowerCase() == "run_function") return;
	var params = [];
	for (var i = 0; i < node.attributes.length; i++)
	{
		params.push(node.attributes[i].value);
	}
	
	if (typeof(this[func]) == "function")
	{
		this[func].apply(this, [].concat(params));
	}
};
Co_Live_Broadcast.Begin_Load_Media = function()
{
	if (this.Status == "broadcasting") return;
	var do_reload = false;
	
	this.AddEventListener("afterUpdate", this.Load_Media, this, [true]);
	//if returns false, ajax not supported
	if (!this.Begin_Get_Update()) this.Load_Media();
};
Co_Live_Broadcast.Load_Media = function(remove_listener)
{
	if (this.Status == "broadcasting" && this.cachedState == this.Status) return;
	settings={hascookie:true,speed:300};
	container=document.getElementById('ajax_player_div');

	files.Media_Type = "Video";

	switch (this.Feed.media_type)
	{
		case "wm" :
			current = files.Windows_Media;
			files.Windows_Media.include_embed=false;
			settings.player = "wm";
			files.isFlash = false;
		break;
		case "fl" :
			current = files.Flash;
			settings.player = "flash";
			files.isFlash = true;
			current.Version=[9,0,0];
			current.FileName='/images/multimedia/mediaplayer/co_media_player.beta3.swf?v=3.0.0.4';
			current.FlashVars='aid='+this.Feed.aid+'&iid='+this.Feed.iid;
			current.allowFullScreen=true;
		break;
	}
	files.autostart=1;
	current.avail=true;
	current.FileNames.kb300.fileid=this.Feed.iid;
	current.FileNames.kb300.height = this.PlayerHeight;
	current.FileNames.kb300.width = this.PlayerWidth;
	switch (this.Feed.media_type)
	{
		case "wm" :
			files.Windows_Media = current;
		break;
		case "fl" :
			files.Flash = current;
		break;
	}
	if (current != null)
	{
		var player_obj=get_player("Player1");
		container.innerHTML="";
		load_player();
		this.cachedState = this.Status = "broadcasting";

		var obj=document.getElementById('player_title');
		if (obj) obj.innerHTML=co_feed_location.title;
		obj=document.getElementById('player_text_status');
		if (obj) obj.innerHTML=co_feed_location.text_status;
	}
	if (remove_listener)
		this.RemoveListeners("afterUpdate");
};
Co_Live_Broadcast.OnAfterInitialLoad = function()
{
	if (this.Status != "broadcasting")
	{
		this.ShowNotification(this.Notification_Text);
	}
	else
	{
		this.Load_Media(Request.Querystring("aid"));
	}
};
Co_Live_Broadcast.Xml_to_Html = function(node, to_text)
{
	var html="";
	node = node.firstChild;
	while (node)
	{
		switch (node.nodeType)
		{
			case 3 : /* text */
			case 4 : /* cdata */
				html += node.nodeValue;
				break;
			case 8 :
				break;
			default :
				switch (node.nodeName)
				{
					case "time" :
						html += this.Local_Time_From_GMT(node);
						break;
					case "countdown_message" :
						if ((this.Status_Time_Diff/1000) > 0 && this.Status == "will begin")
						{
							html += "<span id=\"co_live_countdown_message\">" + this.Xml_to_Html(node) + "</span>";
						}
						break;
					case "countdown" :	
						if ((this.Status_Time_Diff/1000) > 0 && this.Status == "will begin")
						{
							html += "<span id=\"co_live_countdown\"><<co_live_countdown>></span>";
						}
						this.Use_Countdown = true;
						break;
					default :
						if (!to_text)
						{
							html += "<" + node.nodeName;
							if (node.attributes.length > 0) {
								for (var i=0;i<node.attributes.length;i++) html += " " + node.attributes[i].name + "=\"" + node.attributes[i].value + "\"";
							}
							html += ">";
						}
						html += this.Xml_to_Html(node, to_text);
						if (!to_text)
						{
							html += "</" + node.nodeName + ">";
						}
					break;
				}
				break;
		}
		node = node.nextSibling;
	}
	return html;
};
Co_Live_Broadcast.Get_Node_Value = function (root, nodeName)
{
	var node = root.firstChild;
	while (node)
	{
		if (node.nodeType == 8 || node.nodeType == 3)
		{
			node = node.nextSibling;
			continue;
		}
		if (node.nodeName.toLowerCase() == nodeName.toLowerCase())
		{
			return (this[nodeName.toLowerCase()] = this.Xml_to_Html(node));
		}
		node = node.nextSibling;
	}
	return "";
};
Co_Live_Broadcast.Local_Time_From_GMT = function(node)
{
	var time_format="";
	if (node.attributes.length > 0) {
		for (var i=0; i < node.attributes.length; i++)
		{
			if (node.attributes[i].name == "format")
			{
				time_format = node.attributes[i].value;
				break;
			}
		}
	}
	o_date = UTCTime.GetLocalTime(node.firstChild.nodeValue);
	
	return o_date;
};
Co_Live_Broadcast.Unload_Player = function()
{
	var obj = document.getElementById("ajax_player_div");
	if (obj)
	{
		obj.innerHTML = "";
	}
};
Co_Live_Broadcast.ShowNotification = function(notificationText)
{
	if (typeof(notificationText) == "undefined") notificationText = this.Notification_Text;
	
	if (this.Use_Countdown && this.Countdown_Manager == null)
	{
			this.Countdown_Manager = new Co_Interval_Manager();
			this.Countdown_Manager.AddEventListener("interval", this.Countdown_OnInterval, this);
			this.Countdown_Manager.Loops = parseInt(this.Status_Time_Diff/1000)+1;
			this.Countdown_Manager.Start(1000);
			notificationText = notificationText.replace(/<<co_live_countdown>>/gi, this.Get_Coundown_Time(this.Countdown_Manager.Loops - this.Countdown_Manager.LoopIndex) || "");
	}
	else if (this.Use_Countdown)
	{
		this.Countdown_Manager.Loops = parseInt(this.Status_Time_Diff/1000)+1;
		this.Countdown_Manager.LoopIndex = 0;
		notificationText = notificationText.replace(/<<co_live_countdown>>/gi, this.Get_Coundown_Time(this.Countdown_Manager.Loops - this.Countdown_Manager.LoopIndex) || "");
	}
	if (this.Status != "broadcasting")
	{
		var obj = document.getElementById("co_live_notification");
		if (!obj)
		{
			obj = document.getElementById("ajax_player_div");
			var elm = document.createElement("TABLE");
			elm.width = "100%";
			elm.height = this.PlayerHeight;
			elm.border="0";
			elm.cellPadding = "0";
			elm.cellSpacing = "0";
			elm.className = "co_live_notification_area";
			var td = elm.insertRow(-1).insertCell(-1);
			td.className="co_live_notification";
			td.vAlign = "middle";
			td.innerHTML = notificationText;
			td.id = "co_live_notification";
			obj.appendChild(elm);
		}
		else
		{
			obj.innerHTML = notificationText;
		}
		obj = document.getElementById("ajax_player_notifications");
		if (obj) obj.innerHTML = "";
	}
	else
	{
		var obj = document.getElementById("ajax_player_notifications");
		if (obj)
			obj.innerHTML = notificationText;
		obj = document.getElementById("co_live_countdown_message");
		if (obj)
			obj.innerHTML = "";
	}
};
Co_Live_Broadcast.Get_Coundown_Time = function(diff)
{
	if (diff <= 0 || isNaN(diff)) return null;
	var seconds = UTCTime.fullTimeDigit(diff % 60);
	diff = (diff - seconds) / 60;
	var minutes = UTCTime.fullTimeDigit(diff % 60);
	diff = (diff - minutes) / 60;
	var hours = parseInt(diff % 24);
	var days = parseInt((diff - hours) / 24);

	var str = "";
	
	if (days > 0) str += days + " day" + (days != 1 ? "s" : "") + " ";
	if (hours > 0 || days > 0) str += parseInt(hours) + " hour" + (hours != 1 ? "s" : "") + "&nbsp; : &nbsp;";
	if (minutes > 0 || hours > 0 || days > 0) str += minutes + " minute" + (minutes != 1 ? "s" : "") + "&nbsp; : &nbsp;";
	str += seconds + " second" + (seconds != 1 ? "s" : "");
	
	if (days <= 0 && hours <= 0 && minutes <= 0 && seconds <= 0)
	{
		return null;
	}
	else
	{
		return str;
	}
};
Co_Live_Broadcast.Countdown_OnInterval = function()
{
	var str = this.Get_Coundown_Time(this.Countdown_Manager.Loops - this.Countdown_Manager.LoopIndex);
	
	var obj = document.getElementById("co_live_countdown");
	if (str == null)
	{
		obj = document.getElementById("co_live_countdown_message");
		if (obj)
			obj.innerHTML = "";
		obj = document.getElementById("co_live_countdown");
		if (obj)
			obj.innerHTML = "";
			
		this.Countdown_Manager.End();
		this.Countdown_Manager = null;
	}
	else
	{
		if (obj) obj.innerHTML = str;
	}
};
Co_Live_Broadcast.Start = function(aid)
{
/*
	var player_obj = get_player("flash1");
	if (player_obj) 
	{
		player_obj.Play_File();
	}
	else
	{
*/
		this.Load_Media(aid);
/*
	}
*/
};
Co_Live_Broadcast.Stop = function()
{
	var player_obj = get_player("flash1");
	if (player_obj) player_obj.Pause_File();
};
Co_Live_Broadcast.Load_ArticleId = function(aid)
{
	var player_obj = get_player("flash1");
	if (player_obj) Load_ArticleId(aid);
};
Co_Live_Broadcast.Load_MediaId = function(iid)
{
	var player_obj = get_player("flash1");
	if (player_obj) Load_MediaId(aid);
};

Co_Tools.AddEventListener(window, "load", Co_Live_Broadcast.Init, [], Co_Live_Broadcast);
Co_Tools.AddEventListener(window, "unload", Co_Live_Broadcast.OnBeforeUnload, [], Co_Live_Broadcast);

/* UTC TIME Conversion */
var UTCTime = {
	DayNames:['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Shabbat', 'Sunday'], 
	MonthNames:['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
	TimeZones: {
	'-12':'IDLW - International Date Line West','-11':'X - X-Ray Time','-10':'HST - Hawaii Standard','-9':'YST - Yukon Standard',
	'-8':'PST - Pacific Standard','-7':'MST - Mountain Standard','-6':'CST - Central Standard','-5':'EST - Eastern Standard','-4':'AST - Atlantic Standard',
	'-3':'P - Brazil / Argentina','-2':'AT - Azores','-1':'WAT - West Africa','+0':'London Time','+1':'CET - Paris, France','+2':'EET - Jerusalem, Israel',
	'+3':'BT - Moscow, Russia','+4':'D - Delta Time','+5':'E - Echo Time','+6':'F - Foxtrot Time','+7':'G - Golf Time','+8':'CCT - China Coast',
	'+9':'JST - Japan Standard','+10':'GST - Guam Standard','+11':'EST - Eastern Summer Time','+12':'NZST - New Zealand Standard'}
	
};

UTCTime.fullTimeDigit = function(s_val)
{
	s_val = parseInt(s_val);
	if (s_val < 10)
	{
		s_val = '0' + s_val;
	}
	return s_val;
};

UTCTime.convert_24_to_12 = function(hours, minutes)
{
	if (hours == 0)
	{
		return 12 + ':' + this.fullTimeDigit(minutes) + ' AM';
	}
	else if(hours > 12)
	{
		return (hours - 12) + ':' + this.fullTimeDigit(minutes) + ' PM';
	}
	else if (hours == 12)
	{
		return hours + ':' + this.fullTimeDigit(minutes) + ' PM';
	}
	else
	{
		return hours + ':' + this.fullTimeDigit(minutes) + ' AM';
	}
};

UTCTime.GetLocalTime = function(years, months, days, hours, minutes, seconds){
	if (isNaN(months) || typeof(months) == "undefined")
	{
		if (typeof(years) != "object") years = new Date(years);
		if (typeof(years) != "object") return "";
		months = years.getMonth();
		days = years.getDate();
		hours = years.getHours();
		minutes = years.getMinutes();
		seconds = years.getSeconds();
		years = years.getFullYear();
	}
	else
	{
		months--;
	}
	var origionalDate = new Date(years, months, days, hours, minutes , seconds);
	var programDateUTC = Date.UTC(years, months, days, hours, minutes , seconds);
	returnDate = new Date(programDateUTC);
	var tzo=(new Date().getTimezoneOffset()/60)*(-1); 

	return this.DayNames[returnDate.getDay()] + ', ' + this.MonthNames[returnDate.getMonth()] + ' ' + returnDate.getDate() + ', ' + returnDate.getFullYear() + ' at ' + 
		this.convert_24_to_12(returnDate.getHours(), returnDate.getMinutes()) + ' (GMT '  + tzo + ')';
/*	return (this.DayNames[returnDate.getDay()] + ' ' + this.convert_24_to_12(returnDate.getHours(), returnDate.getMinutes()) + ' (GMT '  + tzo + ')'); */
};
UTCTime.GetUTCTime = function(year, month, day, hour, minute, second, ms)
{
	if (typeof(year) == "undefined")
	{
		year = new Date();
		month = year.getUTCMonth();
		day = year.getUTCDate();
		hour = year.getUTCHours();
		minute = year.getUTCMinutes();
		second = year.getUTCSeconds();
		ms = year.getUTCMilliseconds();
		year = year.getUTCFullYear();
	}
	return new Date(year, month, day, hour, minute, second, ms);
};
UTCTime.GetUTCMilliseconds = function(year, month, day, hour, minute, second, ms)
{
	if (typeof(year) == "undefined" || typeof(year) == "object")
	{
		if (typeof(year) == "undefined")
			year = new Date();
		month = year.getUTCMonth();
		day = year.getUTCDate();
		hour = year.getUTCHours();
		minute = year.getUTCMinutes();
		second = year.getUTCSeconds();
		ms = year.getUTCMilliseconds();
		year = year.getUTCFullYear();
	}

	return new Date(year, month, day, hour, minute, second, ms);
};
UTCTime.GetDateDifference = function(Date1, Date2)
{
	return (Date2 - Date1)
};
//</script>