﻿var tcast_ver_4ie = '3.8';
var tcast_ver_4ff = '';
var tcast_f_v = '1';
var tcast_cab_v = '3.0.0.8';

var slist=
[
'SSIAAKdEhUrZDFbjPXN+Hnu80iH8esEzYljsmrhR6i41',
'zBMAAOtcu1thFlJxdd7oAcVAOiEy3OZ7o/VUaNYU8z6l',
'qmEAAM3HH0lIob2I3q01JQQg/rNT/bV+ZVlJgjRyHAsK',
'DEMAABtoRO4LIiV2hkdRvpLUydCAPCNT5qif864OUEOX',
'ZGcAAMFjMsRTJOMCXyVwZ7gT6rrDpqK9vIg7KNjIDCQt',
'lWQAACspW69C9XlgYThkt1oDKWx7w3p0ls9PcHfsxda8',
'SSMAAOgQ7OvafU6KyqVJYfNaLQVs55pHD9MmU3DEMQP2',
'iSUAADS3VYMbuh/Bql5TVJ9q3mGCjpi0GftEEcTZrlhP',
'IgAAACC6OqBFFPyEnIBnq5N93OxkmBhYHZOmVWCRtzuN', 
'2SYAALjMu4+BSW4R4MjZGuM7i2bP+AjkvUZFd4Qz4mJd', 
'+DYAAOSqQ0EJPyspGW7++1TZ0iH5V1feQhlPnR/ORN3h'
];

var hlist=
[
'8XkAAOzui0hv0sxc2Z17n+VWuqqWyVLwYA==',
'D2wAAM8Ljy6wUvb4Rtp2+HQ4H3wr6Z/psQ==',
'RxsAAHLwvqYS84Cv+jxZlM1KBYd59s79pA==',
'024AAFXquxbDfKUsxAgEOGXbZLvwZ0rvjQ==',
'wToAAKA1QNQwU4n82YNatXcN5iF5jwyLuA==',
'sgQAALJTKOFBG8bVdB2KstSC2vl9EpeMUQ==',
'XVkAALwwFwoliB+xgUGNbETLtxpV6mfEXw==',
'0VAAACjbjgjrVSrl9F2KpNJ8wR2OwX7xgQ==',
'SCMAAK3UEs61BWu2813RJ2LSc0y8fKfS+w==',
'SCMAAK3UEs61BWu2813RJ2LSc0y8fKfS+w==',
'3XUAAKTCgCCa6JTaEoGNElRgYW23oChUVg=='
];

var llist=
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
3,
1
];


function reportCount()
{
	var img=document.getElementById('countimg');
	img.src='http://analytics.tom.com/live.png?'+Math.ceil(Math.random()*100000);
}

function outputTcast(ie, download)
{
	if(slist.length==0) return;
	var sl=new Array();
	var ll=0;
	sl[0]=0;
	for(i=0;i<llist.length;++i)
	{
		ll+=llist[i];
		sl[i+1]=ll;
	}
	var rd=Math.random()*ll;
	for(i=sl.length-1;i>=0;--i)
	{
		if(rd>=sl[i]) break;
	}
	
	var w=440;
	var h=395;
	var _ds='';
	var _os='';
	if(download)
	{
		_os='style="display:none" ';
		_ds='<div class="tallpic"><div class="upload"><p>如果您无法正常安装，请下载控件手动安装！</p>'+
			'<br/><br/><a href="http://nba.tom.com/video/tomliveV'+tcast_f_v+'.msi" target="_blank">'+
			'<img border="0" src="images/uploadbtn.jpg" /></a></div></div>';
	}
	else
	{
		_os='style="margin-top:22px" ';
	}

	if(ie)
	{
		document.write('<div style="width:440px;height:22px;background-color:#1f2a47">'+
		'<div style="margin-top:3px;margin-left:10px;float:left">'+
		'<IMG src="images/Fullscreen01.gif" onmouseout="this.src=\'images/Fullscreen01.gif\'" '+
			'onmouseenter="this.src=\'images/Fullscreen02.gif\'" '+
			'onmousedown="if(event.button==1)this.src=\'images/Fullscreen03.gif\'" '+
			'onmouseup="if(event.button==1){this.onmouseenter();tc.FullScreen=true;}"></div>'+
		'<div style="margin-top:3px;margin-left:10px;float:left;">'+
		'<IMG src="images/View03.gif" '+
			'onmousedown="if(event.button==1){tc.StretchToFit=!tc.StretchToFit;'+
			'if(tc.StretchToFit)this.src=\'images/View03.gif\';else this.src=\'images/View01.gif\';}" >'+
		'</div></div>'+
		'<object id="tc" style="margin-top:1px" classid="clsid:9CA74596-B5BB-4634-971C-F0224115A15F" '+
		'codebase="http://nba.tom.com/video/tcastV'+tcast_f_v+'.cab#version='+tcast_cab_v+'" width="'+w+'" height="'+h+'">'+
		'<param name="url" value="' + slist[i] + '">'+
		'<param name="directurl" value="' + hlist[i] + '">'+_ds+'</object>'+
		'<img id="countimg" src="about:blank" style="display:none"/>'+
		'<S'+'CRIPT language="JavaScript">'+
		'var buffertimer;var buffertimes=0;var _starttm=new Date().getTime();'+
		'function checkBufferTimeout(){'+
			'function $(i){return document.getElementById(i);}'+
			'buffertimer=0;'+
			'var ht=$("helptext");var hl=$("helplink");'+
			'if(!ht || !hl)return;'+
			'ht.innerHTML="出现长时间缓冲状态？尝试停止后再点击播放键";hl.href="http://nba.tom.com/help06/index.html";ht.parentNode.style.display="";'+
		'}'+
		'function OnStateChanged(s){'+
			'function $(i){return document.getElementById(i);}'+
			'if(s==2)reportCount();'+
			'var ht=$("helptext");var hl=$("helplink");'+
			'if(!ht || !hl)return;'+
			'if(s==4){ht.innerHTML="可能是您的UDP端口受限";hl.href="http://nba.tom.com/help04/index.html";ht.parentNode.style.display="";}'+
			'else if(s==7){ht.innerHTML="为什么“频道已关闭”？请再次点击播放键";hl.href="http://nba.tom.com/help05/index.html";ht.parentNode.style.display="";}'+
			'else if(s==101){if(tc&&tc.BufferingProgress&&buffertimer){window.clearTimeout(buffertimer);buffertimer=0;}}'+
			'else if(s==102){++buffertimes;if(buffertimes>5&&buffertimes*60000/(new Date().getTime()-_starttm)>1)'+
			'{ht.innerHTML="为什么播放断断续续的，不流畅？";hl.href="http://nba.tom.com/help07/index.html";ht.parentNode.style.display="";}'+
			'if(!buffertimer){buffertimer=window.setTimeout("checkBufferTimeout()",20000);}}'+
		'}'+
		'tc.attachEvent("StateChanged", OnStateChanged);'+
		'</S'+'CRIPT>');
	}
	else
	{
		document.write('<embed type="application/x-tcast-v1"'+_os+
		'pluginspage="http://nba.tom.com/video/tcastV'+tcast_f_v+'.xpi" width="'+w+'" height="'+h+'" '+
		'url="' + slist[i] + '" directurl="'+hlist[i] + '">'+_ds);
		document.write('<img src="http://analytics.tom.com/live.png" style="display:none"/>');
	}
}

function createTcast()
{
	var isie = false;
	
	if (navigator.userAgent.indexOf('MSIE') == -1) //not ie
	{
		if(navigator.userAgent.indexOf('Firefox/3') == -1 ) // not firefox 3
		{
			if(navigator.userAgent.indexOf('Firefox') == -1) //not firefox, browser not support
			{
				//show message to user
				document.write('<div class="tallpic"><div class="upload bg01">TOMLive控件不支持您的WEB浏览器</div>'+
					'<p style="color:#fff;text-align:center;margin:5px; padding:5px;font-size:14px;">'+
            				'请使用<a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=9ae91ebe-3385-447c-8a30-081805b2f90b&DisplayLang=zh-cn"'+
            				'target="_blank">Internet Explorer 6.0</a>以上版本或<a href="http://download.mozilla.org/?product=firefox-3.0.3&os=win&lang=zh-CN"'+
            				'target="_blank">Firefox3.0</a>及以上版本浏览器</p></div>');
				return false;
			}
			else //prompt user to update firfox
			{
				//show message to user
				document.write('<div class="tallpic"><div class="upload bg02">请升级浏览器到Firefox 3.0</div>'+
					'<p style="color:#fff;text-align:center;margin:5px; padding:5px;font-size:14px;">'+
					'点击下载<a href="http://download.mozilla.org/?product=firefox-3.0.3&os=win&lang=zh-CN" target="_blank">Firefox 3.0</a></p></div>');
				return false;
			}
		}
		else //firefox 3
		{
			if (navigator.mimeTypes && navigator.mimeTypes.length > 0)
			{
				for (var i=0; i < navigator.mimeTypes.length; i++ )
				{
					if(navigator.mimeTypes[i].type == 'application/x-tcast-v1' && navigator.mimeTypes[i].description == ('TCAST NP' + tcast_ver_4ff) )
					{
						outputTcast(false);
						return true;
					}
				}
			}
		}
	}
	else //ie
	{
		try
		{
			var x = new ActiveXObject('TCAST.Player.' + tcast_ver_4ie);
			outputTcast(true);
			return true;
		}
		catch(e){}
		isie = true;
	}
	outputTcast(isie, true);
	
	return false;
}
createTcast();

