document.execCommand("BackgroundImageCache", false, true);

var borwser   = new Object;
var userAgent = navigator.userAgent.toLowerCase();
borwser.isMozilla 	= (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined');
borwser.isIE 		= window.ActiveXObject ? true : false;
borwser.isFirefox 	= (userAgent.indexOf("firefox") != - 1);
borwser.isSafari 	= (userAgent.indexOf("safari") != - 1);
borwser.isOpera 	= (userAgent.indexOf("opera") != - 1);
borwser.version 	= (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1];

String.prototype.trim = function()
{
	return this.replace(/(^[\s]*)|([\s]*$)/g, "");
}

String.prototype.GetCount = function(str,mode)
{ 
	return eval("this.match(/("+str+")/g"+(mode?"i":"")+").length"); 
}

var setInnerHTML = function (el, htmlCode) {
	var ua = navigator.userAgent.toLowerCase();
	if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0) {
		//htmlCode = '<div style="display:none">for IE</div>' + htmlCode;
		htmlCode = htmlCode.replace(/<script([^>]*)>/gi,
		'<script$1 defer>');
		el.innerHTML = htmlCode;
		//el.removeChild(el.firstChild);
	} else {
		var el_next = el.nextSibling;
		var el_parent = el.parentNode;
		el_parent.removeChild(el);
		el.innerHTML = htmlCode;
		if (el_next) {
			el_parent.insertBefore(el, el_next)
		} else {
			el_parent.appendChild(el);
		}
	}
}

function dynamic_javascript_load(jsurl)
{
    var footer = document.getElementById('footer');
    var script = document.createElement('script');
    script.src = jsurl;
    script.type = 'text/javascript';
    footer.appendChild(script);
}

function wgid(id)
{
	return self.document.getElementById(id);
}

function callsvod(svod,id)
{
	// 点击率统计
	if(wgid("hitscript")){
		wgid("hitscript").src = "index.php?module=main&action=inchitcount&id="+id;
	}else{
		var hitscript = document.createElement('script');
		hitscript.id = "hitscript";
		hitscript.src = "index.php?module=main&action=inchitcount&id="+id;
		hitscript.type = 'text/javascript';
		document.body.appendChild(hitscript);
	}

	// 调出播放器
	var obj;
	try 
	{
		obj = new ActiveXObject("SvodInvoker.Invoker");
	} 
	catch (e)
	{
		// 未正确安装控件
		obj = null;
	}

	if (obj != null)
	{
		obj.InvokePlayer(svod);
	}
	else
	{
		var iframeId = "svodplayerinvokeriframe";
		var iframe = document.getElementById(iframeId);
		if (!iframe)
		{
			iframe = document.createElement('iframe');
			iframe.id = iframeId;
		}
		iframe.src = svod;
		iframe.scrolling = "No";
		iframe.height = 1;
		iframe.width = 1;
		iframe.frameborder = "No";
		iframe.border = 0;
		iframe.framespacing = 0;
		document.body.appendChild(iframe);
	}
}

function addFavorite(sURL, sTitle){
	try{ window.external.addFavorite(sURL, sTitle);}
		catch (e){
			try{window.sidebar.addPanel(sTitle, sURL, "");}
			catch (e)
				{alert("加入收藏失败，请使用Ctrl+D进行添加");}
		}
}

function setHome(obj,vrl,url){
    try{obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
	this.style.behavior='url(#default#homepage)';this.setHomePage(url);}
        catch(e){
            if(window.netscape){
                try{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");}  
                   catch (e){alert("此操作被浏览器拒绝！请手动设置");}
                   var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                   prefs.setCharPref('browser.startup.homepage',vrl);
             }
      }
}

function redirect(url)
{
	document.location.href= url;
}

function getPosition() 
{ 
	var top    = document.documentElement.scrollTop; 
	var left   = document.documentElement.scrollLeft; 
	var height = document.documentElement.clientHeight; 
	var width  = document.documentElement.clientWidth; 
	return {top:top,left:left,height:height,width:width}; 
}
	
function showwin(obj)
{ 
	var infobox;
	var cp = GetOffset(obj);
	if(wgid("lxwin")){
		infobox = wgid("lxwin");
	}else{
		infobox=document.createElement("DIV");
		infobox.id = "lxwin";
		infobox.oncontextmenu = function(){return false}
		infobox.onselectstart = function(){return false}
		//creimg(maskDiv,"http://www.flashmov.com/images/layer.gif");
		document.body.appendChild(infobox);
		
	}

	infobox.innerHTML = "<ul style=\"text-align:left; line-height:20px;font-size:12px;color:#fff;padding-left:10px;\"><li style=\"text-align:right;padding-top:4px;padding-right:10px;height:15px; line-height:15px;\"><a href=\"#?\" onclick=\"wgid('lxwin').style.display='none';\"><b style=\"color:#000\">×</b></a></li><li style=\"text-align:left;font-size:15px;color:#fff;line-height:20px;\">抱歉，你的直播频道尚未开通或已过期。</li></ul>";
	infobox.style.cssText="border:2px solid #000;background:#666;width:200px;position:absolute;top:"+(cp.top+50)+"px;left:"+(cp.left-50)+"px;z-index:200;display:block;opacity:.3;";
} 

function urldecode(str){
	var i,temp;
	var result="";
	for(i=0;i<str.length;i++){
		if(str.charAt(i)=="%"){
			if(str.charAt(++i)=="u"){
				temp=str.charAt(i++) + str.charAt(i++) + str.charAt(i++) + str.charAt(i++) + str.charAt(i);
				result += unescape("%" + temp);
			}else{
				temp = str.charAt(i++) + str.charAt(i);
				if(eval("0x"+temp)<=160){
					result += unescape("%" + temp);
				}else{
					temp += str.charAt(++i) + str.charAt(++i) + str.charAt(++i);
					result += Decode_unit("%" + temp);
				}
			}
		}else{
			result += str.charAt(i);
		}
	}
	return result;
}

function Decode_unit(str)
{
	var p,q = "";
	if(str.GetCount("%")!=2) return str;
	p=eval("0x" + str.split("%")[1]);
	q=eval("0x" + str.split("%")[2]);
	if(p<160 || q<160) return unescape(str);
	str=str.replace(/%/g,"");
	execScript("temp=&H"+str, "vbscript");
	execScript("result=chr("+temp+")", "vbscript");
	return result;
}

function GetOffset(e)
{
    var x = e.offsetLeft , y = e.offsetTop;   
    while(e = e.offsetParent) 
    { 
       x+=e.offsetLeft;   
       y+=e.offsetTop;
    } 
    return {left:x,top:y}
}



var B = BigNews = {	current:0, step:268, next:0, scrollInterval:0,	autoScroller:0};
var toprunlength;
BigNews.turn = function(index)
{
	clearInterval(BigNews.autoScroller);
	BigNews.autoScroller = setTimeout(function(){BigNews.scroll(index)},500);
}
BigNews.scroll = function(index)
{
	if(!wgid('ul_big_news_item'))
	{
		clearInterval(BigNews.autoScroller);
		return;
	}
	var count=0;
	var step=BigNews.step;
	var duration=16;
	var b=BigNews;
	b.next=index;
	if(index!=b.current&&count>duration/8){ return; }

	clearInterval(b.scrollInterval);
	//var items=wgid('ul_big_news_item').getElementsByTagName('li');
	for(var i=0;i<toprunlength;i++){
		wgid('curdiv'+i).className='banner_m_r_list';
	}
	wgid('curdiv'+index).className +=' banner_list_bac';
	var span=index-b.current;
	var begin_value=wgid('div_big_news_img').scrollTop;
	var chang_in_value=span*step+(b.current*step-begin_value);
	b.scrollInterval = setInterval(function(){doit(begin_value,chang_in_value)},10);
	function doit(b,c){
		wgid('div_big_news_img').scrollTop=cpu(count,b,c,duration);
		count++;
		if(count==duration){
			clearInterval(BigNews.scrollInterval);
			scrollInterval=0;
			count=0;
			wgid('div_big_news_img').scrollTop=b+c;
			BigNews.current=index;
		}
	}
	function cpu(t,b,c,d) {return c*((t=t/d-1)*t*t+1)+b;};
}
BigNews.auto=function()
{
    toprunlength = wgid('div_big_news_img').getElementsByTagName('img').length;
	clearInterval(BigNews.autoScroller);
	BigNews.autoScroller = setInterval(function()
	{
		BigNews.scroll(BigNews.current == (toprunlength-1) ? 0 : BigNews.current + 1);
	} , 4000);
}

// 热播大片slide
function Aotuplay(showid,showimgid,curimg,defimg){
	this.current=0; 
	this.step=5000;
	this.num=4;
	this.autoScroller=0;
	this.showid= showid;
	this.showimgid=showimgid;
	this.curImg= curimg!=undefined?curimg:URL_ROOT_PATH+'images/a_56.gif';
	this.defImg= defimg!=undefined?defimg:URL_ROOT_PATH+'images/a_58x.gif';
}
Aotuplay.prototype.start =function(){
	clearInterval(this.autoScroller);
	var selfobj = this;
	this.autoScroller = setInterval(function()
	{
		selfobj.play(selfobj.current == selfobj.num ? 1 : selfobj.current + 1);
	} , selfobj.step);
}
Aotuplay.prototype.play=function(index)
{
	if(this.current){
		wgid(this.showid+this.current).style.display='none';
		wgid(this.showimgid+this.current).src=this.defImg;
	}
	this.current = index;
	wgid(this.showid+index).style.display='block';
	wgid(this.showimgid+index).src=this.curImg;
}
Aotuplay.prototype.next=function()
{
	clearInterval(this.autoScroller);
	var index = this.current == this.num ? 1 : this.current + 1;
	this.play(index);
	var selfobj = this;
	setTimeout(function(){selfobj.start();},selfobj.step);
}
Aotuplay.prototype.prev=function()
{
	clearInterval(this.autoScroller);
	var index = this.current == 1 ? 4 : this.current - 1;
	this.play(index);
	var selfobj = this;
	setTimeout(function(){selfobj.start();},selfobj.step);
}
