var lowerWords="BLOOMBERG TV";
var vAdId="";
var useCDN=false;

function ChangeTitle() {
	var id="divVidTitle";
	var txt='<span class="orangehd">NOW PLAYING:  </span>' + lowerWords;
	var el=(document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) {
		if (el.innerHTML != lowerWords) {
			if (typeof el.innerHTML!="undefined") {
				el.innerHTML=txt;
			} else if (document.layers) {
				el.document.write(txt);
				el.document.close();
			}
		}
	}
}

function isLiveTVClip(clip)
{
	var isLiveClip = false;
	var clipLowerCase = clip.toLowerCase();
	switch(clipLowerCase) {
		case "liveas":
		case "liveas_nb":
		case "livebtv":
		case "livebtv56":
		case "livebtv200":
		case "livejp":
		case "livejp_nb":
		case "livebr":
		case "livebr_nb":
		case "livede":
		case "livede_nb":
		case "livees":
		case "livees_nb":
		case "livefr":
		case "livefr_nb":
		case "liveit":
		case "liveit_nb":
		case "liveuk":
		case "liveuk_nb":
			isLiveClip = true;
			break;
		default:
			isLiveClip = false;
	}
	
	return isLiveClip;
}

function chooz(clip, vTitle, SRpt, AVYP, vCat, vAdId) {
	ext=".asxx";
	lowerWords=clip.match("Live") ? "BLOOMBERG TV" : "";
	var clipLowerCase = clip.toLowerCase();
	switch(clipLowerCase) {
		case "liveas":
		case "liveas_nb":
		case "livejp":
		case "livejp_nb":
			clip = "LiveAS_nb";
			lowerWords += " ASIA PACIFIC";
			break;
		case "livebr":
		case "livebr_nb":
			clip = "LiveBR_nb";
			lowerWords += " BRAZIL";
			break;
		case "livede":
		case "livede_nb":
		case "livees":
		case "livees_nb":
		case "livefr":
		case "livefr_nb":
		case "liveit":
		case "liveit_nb":
		case "liveuk":
		case "liveuk_nb":
			clip = "LiveUK_nb";
			lowerWords += " EUROPE";
			break;
		case "livebtv":
		case "livebtv56":
			clip = "LiveBTV56";
			lowerWords += " US";
			break;
		case "livebtv200":
			clip = "LiveBTV200";
			lowerWords += " US";
			break;
		case "529":
			lowerWords="Best College 529 Plans";
			clip+="_200";
			break;
		case "house":
			lowerWords="Homes: Still A Good Investment?";
			clip+="_200";
			break;
		case "inherit":
			lowerWords="Losing Your Inheritance";
			clip+="_200";
			break;
		case "give":
			lowerWords="Charity: Growing Bigger Gifts";
			clip+="_200";
			break;
		case "retire":
			lowerWords="Retiring Too Soon?";
			clip+="_200";
			break;
		case "://529":
			lowerWords="Best College 529 Plans";
			clip=clip.substring(3) + "_200";
			break;
		case "://house":
			lowerWords="Homes: Still A Good Investment?";
			clip=clip.substring(3) + "_200";
			break;
		case "://inherit":
			lowerWords="Losing Your Inheritance";
			clip=clip.substring(3) + "_200";
			break;
		case "://give":
			lowerWords="Charity: Growing Bigger Gifts";
			clip=clip.substring(3) + "_200";
			break;
		case "://retire":
			lowerWords="Retiring Too Soon?";
			clip=clip.substring(3) + "_200";
			break;
		default:
			lowerWords=vTitle.length > 1 ? vTitle : "Bloomberg News Video";
			ext=".asx";
	}

	if (clip.match(".flv")) {
		insertPlayer( clip, 0, SRpt, AVYP);
	}else if (! clip.match("://") ) {
		insertPlayer( 'http://www.bloomberg.com/streams/video/'+clip+ext+"?RND="+AD_RND_X+"&vCat="+vCat+"&A="+vAdId, 0, SRpt, AVYP);
	}else{
		var newURL=(AVYP == 5) ? clip : "http://www.bloomberg.com/avp/avp.asxx?clip="+clip+"&vCat="+vCat+"&RND="+AD_RND_X+"&A="+vAdId;
		insertPlayer(newURL, 1, SRpt, AVYP);
	}
	ChangeTitle();
	insertSelector(clip);
}

function insertPlayer( clipSRC, VOD, SRpt, AVYP) {
	var id='divVplyer';
	var height=(AVYP == 5) ? "200" : "290";
	var filler='<div style="height:90px;width:310px;background:#000000;"></div>';
	var objTxt='';

	if(clipSRC.match("FLASH") || clipSRC.match("fx_term_") || clipSRC.match("fx_app_") || clipSRC.match("fx_tech_")) {
		var prerollVars = "";
		var flashVars = "File=http://bitcast-a.bitgravity.com/bloomberg/" + clipSRC +
						"&amp;VideoFit=automatic" + 
						"&amp;Mode=ondemand" + 
						"&amp;DefaultRatio=1.537037037037037" + 
						"&amp;ForceRatio=false" + 
						"&amp;BitGravityLogo=false";
		var videoBufferSeconds = 10;
		
		if(clipSRC.match("FLASH/innovators/"))
		{
			if(clipSRC.match("FLASH/innovators/innovators_broadcast"))
			{
				videoBufferSeconds = 15;
			}
		}

		flashVars += "&amp;BufferTime=" + videoBufferSeconds;
		
		useCDN=true;
		objTxt='<object id="bg_plyr5" type="application/x-shockwave-flash" data="http://bitcast-b.bitgravity.com/player/bitgravity_player_5_w109.swf" width="417" height="290"><param name="movie" value="http://bitcast-b.bitgravity.com/player/bitgravity_player_5_w109.swf" /><param name="base" value="http://bitcast-b.bitgravity.com/player/" /><param name="allowFullScreen" value="true" /><param name="flashvars" value="' + flashVars + '" /><embed id="bg_plyr5" src="http://bitcast-b.bitgravity.com/player/bitgravity_player_5_w109.swf" FlashVars="' + flashVars + '" quality="high" wmode="window" width="417" height="290" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
	}else if(useCDN && clipSRC.match("LiveBTV")) {
		objTxt='<object id="bg_plyr5" type="application/x-shockwave-flash" data="http://bitcast-b.bitgravity.com/player/bitgravity_player_5_w109.swf" width="417" height="290"><param name="movie" value="http://bitcast-b.bitgravity.com/player/bitgravity_player_5_w109.swf" /><param name="base" value="http://bitcast-b.bitgravity.com/player/" /><param name="allowFullScreen" value="true" /><param name="flashvars" value="File=http://bglive-a.bitgravity.com/bloomberg/live/native&amp;Mode=live&amp;VideoFit=automatic&amp;DefaultRatio=1.5&amp;BitGravityLogo=false" /><embed id="bg_plyr5" src="http://bitcast-b.bitgravity.com/player/bitgravity_player_5_w109.swf" FlashVars="File=http://bglive-a.bitgravity.com/bloomberg/live/native&amp;Mode=live&amp;VideoFit=automatic&amp;DefaultRatio=1.5&amp;BitGravityLogo=false" quality="high" wmode="window" width="417" height="290" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
	}else if(clipSRC.match(".flv")) {
		objTxt='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="310" height="290" id="MediaPlayer"><param name="movie" value="/vid/playerNEW3.swf"><param name="allowScriptAccess" value="sameDomain"><param name="allowFullScreen" value="false"><param name="FlashVars" value="flvLink=' + clipSRC + '"><param name="quality" value="high"><param name="wmode" value="window"><embed id="MediaPlayer" src="/vid/playerNEW3.swf" FlashVars="flvLink=' + clipSRC + '" quality="high" wmode="window" width="310" height="290" name="flvPLAY" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
	}else{
		objTxt=((AVYP == 5) ? filler : "") + '<OBJECT ID="MediaPlayer" TYPE="video/x-ms-wmv" DATA="' + clipSRC + '" WIDTH="310" HEIGHT="' + height + '"><PARAM name="src" VALUE="' + clipSRC + '" /><PARAM name="autoStart" value="true"><PARAM name="AutoSize" value="true"><PARAM name="ShowStatusBar" value="true"><PARAM name="ShowTracker" value="false"><EMBED ID="MediaPlayer" TYPE="application/x-mplayer2" HEIGHT="' + height + '" WIDTH="310" src="' + clipSRC + '" showstatusbar="1" showtracker="1" autostart="1"></EMBED></object>';
	}

	var el=(document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (!el) return;
	if (typeof el.innerHTML!="undefined") {
		el.innerHTML=objTxt;
	} else if (document.layers) {
		el.document.write(objTxt);
		el.document.close();
	}
}

var gRSRC;
function insertSelector( clipSRC ) {
	var id='divVidSelector';
	var NL= (useCDN)? '</tr><tr>': '';
	var NL2='</tr><tr>';
	var RSRC='<table><tr><td><a href="/tvradio/tv/schedule_us.html" target="_blank">Programming Schedule</a></td>'+NL+'<td><a href="/tvradio/podcast/" target="_blank">Podcasts</a></td>'+NL2+'<td><a href="/tvradio/tv/where_us.html" target="_blank">Where To Find Us</a></td>'+NL+'<td><a href="/tvradio/mobile.html" target="_blank">Mobile</a></td>'+NL2+'<td><a href="/news/breakingnews/" target="_blank">Breaking News</a></td>'+NL+'<td><a href="/news/exclusive/" target="_blank">Exclusive News</a></td>'+NL2+'<td><a href="/news/invest.html" target="_blank">Personal Finance</a></td>'+NL+'<td><a href="/news/marketsmag/" target="_blank">Bloomberg Magazine</a></td></tr></table>';
	gRSRC = RSRC;
	if(useCDN) {
		Text='<div style="width:305px;overflow:hidden;margin:0;padding:0"><img src="http://cdn.images.bloomberg.com/r06/tvradio/tv_tab.gif" style="margin:0;padding:0;"><p class="margin"><div class="radio_contentbox" style="margin-top:10px"><div class="plyr_bar" style="width:267px"><div class="tv_roundtop"><img style="display:none" class="corner" height="4" width="4" src="http://cdn.images.bloomberg.com/r06/tvradio/tv_tl.gif"></div><p>&nbsp;Resources</p><div class="tv_roundbottom"><img style="display:none" class="corner" height="4" width="4" src="http://cdn.images.bloomberg.com/r06/tvradio/tv_bl.gif"></div></div></div>' + RSRC + '</p></div>';
		el=(document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
		if (el) {
			el.style.width='287px';
			el.style.left='420px';
		}
	}else{
		Base='/avp/avp.htm?clipSRC=';
		Text='<img src="http://cdn.images.bloomberg.com/r06/tvradio/tv_tab.gif" style="MARGIN: 0; PADDING: 0;"><p class="margin" style="margin-top: 8px;"><div class="radio_contentbox"><div class="plyr_bar" style="width: 380px;"><div class="tv_roundtop"><img style="display: none" class="corner" height="4" width="4" src="http://cdn.images.bloomberg.com/r06/tvradio/tv_tl.gif"></div><p>&nbsp;Select Channel</p><div class="tv_roundbottom"><img style="display: none" class="corner" height="4" width="4" src="http://cdn.images.bloomberg.com/r06/tvradio/tv_bl.gif"></div></div></div><table><tr><td width="40%"><a href="'+Base+'LiveAS">Asia Pacific</a></td><td width="30%"><a href="'+Base+'LiveUK">Europe</a></td><td><a href="'+Base+'LiveBTV">US</a></td></tr></table>';
		Text += '<p class="margin"><div class="radio_contentbox"><div class="plyr_bar"><div class="tv_roundtop"><img style="display: none" class="corner" height="4" width="4" src="http://cdn.images.bloomberg.com/r06/tvradio/tv_tl.gif"></div><p>&nbsp;Alerts</p><div class="tv_roundbottom"><img style="display: none" class="corner" height="4" width="4" src="http://cdn.images.bloomberg.com/r06/tvradio/tv_bl.gif"></div></div></div><p style="margin: 7px 0 12px 0;"><a href="http://bloomberg.tveyes.com/" target="_blank"><span class="alertxt">Sign-up to get free alerts when a company or subject you\'re interested in is mentioned on Bloomberg Television. </span><img src="http://cdn.images.bloomberg.com/r06/tvradio/tv/arrow-blue.gif" border="0" height="8" width="8"/></a></p></p>';
		Text += '<p class="margin"><div class="radio_contentbox"><div class="plyr_bar"><div class="tv_roundtop"><img style="display: none" class="corner" height="4" width="4" src="http://cdn.images.bloomberg.com/r06/tvradio/tv_tl.gif"></div><p>&nbsp;Resources</p><div class="tv_roundbottom"><img style="display: none" class="corner" height="4" width="4" src="http://cdn.images.bloomberg.com/r06/tvradio/tv_bl.gif"></div></div></div>' + RSRC + '</p>';
	}
	id='divOnDemand';
	el=(document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (!el) return;
	if (typeof el.innerHTML!="undefined") {
		el.innerHTML=Text;
	} else if (document.layers) {
		el.document.write(Text);
		el.document.close();
	}
}

function insertRequire() {
	var id='divVplyer';
	var Text='Windows Media Player is required to view media clips on Bloomberg.com.';
		Text += '<br/>Please click the button below to download the Microsoft Windows Media Player.';
		Text += '<br/><br/><P class="margin"><center><a href="http://www.microsoft.com/windows/windowsmedia/player/download/" target="_blank"><img alt="Get Windows Media Player" src="http://www.microsoft.com/windows/windowsmedia/cdn.images/logos/wmp10/Download_68x56_static.gif" width="68" height="56" border="0" vspace="7"></a></center></P>';
		Text += '<br/>If you have Windows Media Player installed, you may need to download the proper codecs from <a href="http://www.microsoft.com/downloads/details.aspx?familyid=06fcaab7-dcc9-466b-b0c4-04db144bb601&displaylang=en" target="_parent">Microsoft</a>.';

	var el=(document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (!el) return;
	if (typeof el.innerHTML!="undefined") {
		el.innerHTML=Text;
	} else if (document.layers) {
		el.document.write(Text);
		el.document.close();
	}
}

function FixOpera() {
	if ( navigator.userAgent.indexOf("Opera") !=-1 ) {
		var id='divVplyer';
		var myElem=(document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
		myElem.style.width='287px';
	}
}

var xmlHttp;
var cCode="";
function gCheck(){
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp == null){
		cCode="NO";
		return;
	}
	var url="/apps/cylookup";
	xmlHttp.onreadystatechange=stateChange;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null)
}

function stateChange(){
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		cCode=xmlHttp.responseText;
		if (!useCDN) useCDN=(navigator.userAgent.indexOf('Mac') != -1 && cCode.indexOf('US') != -1 ) ? 1 : 0;
	}
}

function GetXmlHttpObject(){
	var objXMLHttp=null;
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest();
	}else if(window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}

function doNxt() {
	if (clipSRC.toLowerCase().match("live") && ! useCDN) {
		clipSRC += (clipSRC.match("BTV"))? (throughput >=200)? '200': '56': "_nb";
	}
	if (hasWMP || useCDN) {
		chooz(clipSRC, vTitle, SRpt, AVYP, vCat, vAdId);
	}else{
		insertRequire();
	}
	FixOpera();
}



