// JavaScript Document
function CreateXmlDom()
{
    if(window.ActiveXObject)
    {
        var arrSignatures=["MSXML2.DOMDocument.5.0","MSXML2.DOMDocument.4.0","MSXML2.DOMDocument.3.0","MSXML2.DOMDocument","Microsoft.XmlDom"];
        for(var i=0;i<arrSignatures.length;i++)
        {
            try
            {
                var oXmlDom=new ActiveXObject(arrSignatures[i]);
                oXmlDom.async=false;
                oXmlDom.validateOnParse=false;
                return oXmlDom;
            }
            catch(oError)
            {}
        }
        
        throw new Error("你的浏览器没有安装xml支持组件！");
    }
    else if(document.implementation && document.implementation.createDocument)
    {
        var oXmlDom=document.implementation.createDocument("","",null);
        
        oXmlDom.parseError={
            valueOf:function(){return this.errorCode;},
            toString:function(){return this.errorCode.toString()}
        };
        
        oXmlDom.__initError__;
        
        oXmlDom.addEventListener("load",function(){
            this.__checkForErrors__();
            this.__changeReadyState__(4);
        },false);
        
        oXmlDom.async=false;
        oXmlDom.validateOnParse=false;
        
        return oXmlDom;
    }
    else
    {
        throw new Error("你的浏览器不支持Xml对象！");
    }
}

var isMoz=false;

var agt=navigator.userAgent.toLowerCase();

if (agt.indexOf("firefox") != -1)
{
    isMoz=true;
}

if(isMoz)
{
    Document.prototype.readyState=0;
    Document.prototype.onreadystatechange=null;
    
    Document.prototype.__changeReadyState__=function(iReadyState){
        this.readyState=iReadyState;
        
        if(typeof this.onreadystatechange=="function"){
            this.onreadystatechange()
        }
    };
    
    Document.prototype.__initError__=function(){
        this.parseError.errorCode=0;
        this.parseError.filepos=-1;
        this.parseError.line=-1;
        this.parseError.linepos=-1;
        this.parseError.reason=null;
        this.parseError.srcText=null;
        this.parseError.url=null;
    };
    
    Document.prototype.__checkForErrors__=function(){
        if(this.documentElement.tagName=="parsererror")
        {
            var reError=/>([\s\S]*?)Location:([\s\S]*?)Line Number (\d+),Column (\d+):<sourcetext>([\s\S]*?)(?:\-*\^)/;
            
            reError.test(this.xml);
            
            this.parseError.errorCode=-999999;
            this.parseError.line=parseInt(RegExp.$3);
            this.parseError.linepos=parseInt(RegExp.$4);
            this.parseError.reason=RegExp.$1;
            this.parseError.srcText=RegExp.$5;
            this.parseError.url=RegExp.$2;
        }
    };
    
    Document.prototype.loadXML=function(sXml){
        this.__initError__();
        this.__changeReadyState__(1);
        
        var oParser=new DOMParser();
        var oXmlDom=oParser.parseFromString(sXml,"text/xml");
        
        while(this.firstChild)
        {
            this.removeChild(this.firstChild);
        }
        
        for(var i=0;i<oXmlDom.childNodes.length;i++)
        {
            var oNewNode=this.importNode(oXmlDom.childNodes[i],true);
            this.appendChild(oNewNode);
        }
        
        this.__checkForErrors__();
        
        this.__changeReadyState__(4);
    };
    
    Document.prototype.__load__=Document.prototype.load;
    
    Document.prototype.load=function(sURL){
        this.__initError__();
        this.__changeReadySate__(1);
        this.__load__(sURL);
    };
    
    Node.prototype.__defineGetter__("xml",function(){
        var oSerializer=new XMLSerializer();
        return oSerializer.serializeToString(this,"text/xml");
    });
    
    Node.prototype.__defineGetter__("text",function(){
        var oSerializer=new XMLSerializer();
        var str=oSerializer.serializeToString(this,"text/xml");
        str=str.substring(str.indexOf('>')+1,str.length);
        var text=str.substring(0,str.indexOf("</"));
        return text;
    });
    
    Element.prototype.selectNodes=function(sXPath){
        var oEvaluator=new XPathEvaluator();
        var oResult=oEvaluator.evaluate(sXPath,this,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);
        
        var aNodes=new Array;
        
        if(oResult!=null)
        {
            var oElement=oResult.iterateNext();
            while(oElement)
            {
                aNodes.push(oElement);
                oElement=oResult.iterateNext();
            }
        }
        
        return aNodes;
    };
    
    Element.prototype.selectSingleNode=function(sXPath){
        var oEvaluator=new XPathEvaluator();
        var oResult=oEvaluator.evaluate(sXPath,this,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null);
        
        if(oResult!=null)
        {
            return oResult.singleNodeValue;
        }
        else
        {
            return null;
        }
    };
}

function vod_openlist(tag)
{
	tag=tag.parentNode;
	if(tag.style.height=='auto')
		tag.style.height='23px';
	else
		tag.style.height='auto';
	
}
function bak_news_focus(pics,links,texts)
{
	var interval_time=4; 
	var focus_width=240;
	var focus_height=180;
	var text_height=24;
	var text_align="center" 
	var swf_height=focus_height+text_height; 
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">');
	document.write('<param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="flash/focus.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#F0F0F0">');
	document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
	document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">');
	document.write('<embed src="flash/focus.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#F0F0F0" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}
///////////////最新动态的显示
function news_focus(pics,links,texts)
{
	var interval_time=4;
	var focus_width=240;
	var focus_height=180;
	var text_height=24;
	var text_align="center";
	var swf_height=focus_height+text_height;
	var htmlStr='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">'
		+'<param name="allowScriptAccess" value="ameDomain" /><param name="movie" value="flash/focus.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#F0F0F0">'
		+'<param name="menu" value="false"><param name=wmode value="opaque">'
		+'<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">'
		+'<embed src="flash/focus.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#F0F0F0" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
		+'</object>';
	document.getElementById("news_focus").innerHTML=htmlStr;
}

function styleOnload()
{
	 var c = readCookie('gztv_video_style');
     if (c) switchStylestyle(c);
     
     if(isMoz)
     {
         $("#playToolbar").html("");
         $("#playWnd").html("");
         
         if(CheckMozVersion()==false)
         {
             document.getElementById("the_fdiv").style.top=200 + "px";
         }
     }
     //else if(CheckBanaComVersion() == false) {//用户未安装客户端，或不满足版本要求,则停止执行
     //else if(CheckBanaComVersion() == false){
	     //document.getElementById("the_fdiv").style.top=200 + "px";
//}
}
function switchStylestyle(num)
{
    var nnn=document.getElementsByTagName("link");
	for(var i=1;i<4;i++)
	{
         nnn[i].disabled = true;
         if (i==num) nnn[i].disabled = false;
    }
     createCookie('gztv_video_style', num, 365);
}


function createCookie(name,value,days)
{
     if (days)
     {
         var date = new Date();
         date.setTime(date.getTime()+(days*24*60*60*1000));
         var expires = "; expires="+date.toGMTString();
     }
     else var expires = "";
     document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
     var nameEQ = name + "=";
     var ca = document.cookie.split(';');
     for(var i=0;i < ca.length;i++)
     {
         var c = ca[i];
         while (c.charAt(0)==' ') c = c.substring(1,c.length);
         if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
     }
     return null;
}
function eraseCookie(name)
{
     createCookie(name,"",-1);
}
var PL=0;
function linemove(tag,num)
{
	tag=tag.parentNode.parentNode;
	var i=0;
	for(i=0;i<tag.childNodes.length;i++)
	{
		if(tag.childNodes[i].className=="b")
		{
			PL+=num;
			if(PL>0)
				PL=0;
			tag.childNodes[i].childNodes[0].style.marginLeft=PL+"px";
		}
	}
}
var padInterval=null;
var padW=470;
function padOpen()
{
	if(padInterval==null)
	{		
		document.getElementById("playWnd").style.paddingTop="345px";
		document.getElementById("playWnd").style.height="0px";
		setTimeout("padInterval=setInterval(\"padOpen()\",20);",2000);
	}
	else
	{
		padW-=10;
		document.getElementById("PADL").style.width=padW+"px";
		document.getElementById("PADR").style.width=padW+"px";
		if(padW<=240)
		{
			document.getElementById("PADL").style.backgroundImage="url("+document.getElementById("pad1src").value+")";
			document.getElementById("PADR").style.backgroundImage="url("+document.getElementById("pad2src").value+")";
			document.getElementById("playWnd").style.paddingTop="0px";
			document.getElementById("playWnd").style.height="345px";
			setTimeout("prbShow();",1000);
			clearInterval(padInterval);		
			showPlayer();
		}
	}
}
var prbInterval=null;
var prbA=0;
var prbO=true;
function prbShow()
{
	if(prbInterval==null)
		prbInterval=setInterval("prbShow()",50);
	prbA+=5;
	document.getElementById("PRB").style.filter=" Alpha(Opacity="+prbA+")";
	document.getElementById("PRB").style.opacity=prbA/100.0;
	
	if(document.getElementById("leftMore")!=null)
	{
	document.getElementById("leftMore").style.filter=" Alpha(Opacity="+prbA+")";
	document.getElementById("leftMore").style.opacity=prbA/100.0;
	}
	
	if(prbA>=90)
	{
		clearInterval(prbInterval);
	}	
}

function prbOpen()
{
	if(prbO)
	{
		document.getElementById("PRB").style.width="21px";
		document.getElementById("PRB").style.height="76px";
		document.getElementById("PLL").src="img/pll1.jpg";
		prbO=false;
	}
	else
	{
		document.getElementById("PRB").style.width="225px";
		document.getElementById("PRB").style.height="428px";
		document.getElementById("PLL").src="img/pll2.jpg";
		prbO=true;
	}
}

function fdiv_close()
{
	document.body.removeChild(document.getElementById("the_fdiv"));
	document.body.removeChild(document.getElementById("the_fdiv_Mask"));
	document.onmousemove=null;
	document.onmouseup=null;
}
var fdiv_X=0;
var fdiv_Y=0;
function fdiv_open()
{
	fdiv_X=(document.body.clientWidth - 400)/2;
	fdiv_Y=300;
	document.getElementById("the_fdiv").style.left=fdiv_X + "px";
	document.getElementById("the_fdiv").style.top=fdiv_Y + "px";
	fdiv_Y=200;
}
var isMoving=false;
var fdiv_beginX=0;
var fdiv_beginY=0;
function fdiv_startmove()
{
	isMoving=true;
	fdiv_beginX=event.clientX;
	fdiv_beginY=event.clientY;
}
function fdiv_stopmove()
{
	isMoving=false;
}
function fdiv_move()
{
	if(!isMoving)
		return;
	var X= event.clientX;
	var Y= event.clientY;
	fdiv_X+=X-fdiv_beginX;
	fdiv_Y+=Y-fdiv_beginY;
	document.getElementById("the_fdiv").style.left=fdiv_X + "px";
	document.getElementById("the_fdiv").style.top=fdiv_Y + "px";
	fdiv_beginX=event.clientX;
	fdiv_beginY=event.clientY;
}
document.onmousemove=fdiv_move;
document.onmouseup=fdiv_stopmove;

function AddDlgDomObj(){
	var sWidth,sHeight;
	sWidth=document.body.offsetWidth;
	sHeight=document.body.scrollHeight;

	var bgObj=document.createElement("div");
	bgObj.setAttribute('id','the_fdiv_Mask');
	bgObj.style.position="absolute";
	bgObj.style.top="0";
	bgObj.style.background="#ccc";
	bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
	bgObj.style.opacity="0.5";
	bgObj.style.left="0";
    bgObj.style.width=sWidth+"px";
	bgObj.style.height=sHeight+"px";
	bgObj.style.zIndex = "10000";
	document.body.appendChild(bgObj);	

	var strHtml="<div class=\"fdiv\" id=\"the_fdiv\">";
	strHtml+="<div class=\"fdiv_t\" onmousedown=\"fdiv_startmove();\" >";
    strHtml+="<div class=\"fdiv_tb\"><strong id=\"fdiv_title\"> 软件下载</strong><a class=\"fdiv_close\" href=\"javascript:fdiv_close();\"><img style=\"margin-top:3px;\" src=\"img/fdiv_close.gif\" alt=\"\" /></a></div>";
    strHtml+="</div>";
	strHtml+="<div class=\"fdiv_c\">";
    strHtml+="<div class=\"fdiv_bk\">";
    strHtml+="<div id=\"fdiv_text\">";
    strHtml+="<h4><font color=\"#FF6204\" style=\"font-size:18px; font-weight:normal;  font-family:'黑体';\">下载提示：</font></h4>";
    strHtml+=" <p style=\"font-size:14px;\">　　您尚未安装<strong>Banacast</strong>播放软件或您的版本过低，请立即下载安装或升级。</p>";
    strHtml+=" </div>";
    strHtml+="<div id=\"fdiv_btns\" class=\"fdiv_b\">";
    strHtml+="<div onclick=\"window.location.href='Download/Banacast.exe';window.setTimeout('SetDlgtoWaitStat()',2000);\" class=\"fdiv_btn\"></div>";
    strHtml+="</div>";
    strHtml+=" </div>";
    strHtml+="</div>";
	strHtml+="</div>";

	document.body.insertAdjacentHTML("beforeEnd",strHtml);
}
/****************************************************
                   firefox下的出错提示
****************************************************/
function AddDlgDomObj_Moz(index)
{
    var sWidth,sHeight;
	sWidth=document.body.offsetWidth;
	sHeight=document.body.offsetHeight;

	var bgObj=document.createElement("div");
	bgObj.setAttribute('id','the_fdiv_Mask');
	bgObj.style.position="absolute";
	bgObj.style.top="0";
	bgObj.style.background="#ccc";
	bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
	bgObj.style.opacity="0.5";
	bgObj.style.left="0";
    bgObj.style.width=sWidth+"px";
	bgObj.style.height=sHeight+"px";
	bgObj.style.zIndex = "10000";
	document.body.appendChild(bgObj);	

	var strHtml="<div class=\"fdiv\" id=\"the_fdiv\">";
	strHtml+="<div class=\"fdiv_t\" onmousedown=\"fdiv_startmove();\" >";
    strHtml+="<div class=\"fdiv_tb\"><strong id=\"fdiv_title\"> 软件下载</strong><a class=\"fdiv_close\" href=\"javascript:fdiv_close();\"><img style=\"margin-top:3px;\" src=\"img/fdiv_close.gif\" alt=\"\" /></a></div>";
    strHtml+="</div>";
	strHtml+="<div class=\"fdiv_c\">";
    strHtml+="<div class=\"fdiv_bk\">";
    strHtml+="<div id=\"fdiv_text\">";
    strHtml+="<h4><font color=\"#FF6204\" style=\"font-size:18px; font-weight:normal;  font-family:'黑体';\">下载提示：</font></h4>";
    if(index==1)
    {
        strHtml+=" <p style=\"font-size:14px;\">　　您尚未安装<strong>Banacast</strong>播放软件或版本过低，请立即下载安装或升级。</p>";
    }
    else
    {
        strHtml+=" <center><p style=\"font-size:14px;\">　　您尚未安装<strong>Banacast</strong>在<strong>Firefox</strong>下的插件</strong><br/>请下载后将下载的文件放在<br/><font color=\"blue\">系统盘的Program Files/Mozilla Firefox/plugins目录下面，然后重启firefox</font></p></center>";
    }
    strHtml+=" </div>";
    strHtml+="<div id=\"fdiv_btns\" class=\"fdiv_b\">";
    if(index==1)
    {
        strHtml+="<div onclick=\"window.location.href='Download/Banacast.exe';window.setTimeout('SetDlgtoWaitStat_Moz(1)',2000);\" class=\"fdiv_btn\"></div>";
    }
    else
    {
        strHtml+="<div onclick=\"window.location.href='Download/npBanaPlugin.dll';window.setTimeout('SetDlgtoWaitStat_Moz(0)',2000);\" class=\"fdiv_btn\"></div>";
    }
    strHtml+="</div>";
    strHtml+=" </div>";
    strHtml+="</div>";
	strHtml+="</div>";

	//document.body.insertAdjacentHTML("beforeEnd",strHtml);
	insertHtml("beforeEnd", document.body, strHtml)
}


var my_showed=false;
function my_showPlayer(plyH)
{
	if(plyH==0)
		window.location="#mm_player";
	if(my_showed)
		return;
		
	if(plyH<420)
	{
		var temp=((420-plyH)/4);
		if(temp<8)
			temp=8;
		plyH+=temp;
		document.getElementById("my_player").style.height=plyH+"px";
		setTimeout("my_showPlayer("+plyH+");",50);
	}
	else
	{
		my_showed=true;
		document.getElementById("showhiddenbar").style.filter="Alpha(Opacity=100)";
		document.getElementById("showhiddenbar").style.opacity=0;
	}
}
function insertHtml(where, el, html){    
        where = where.toLowerCase();    
        if(el.insertAdjacentHTML){    
            switch(where){    
                case "beforebegin":    
                    el.insertAdjacentHTML('BeforeBegin', html);    
                    return el.previousSibling;    
                case "afterbegin":    
                    el.insertAdjacentHTML('AfterBegin', html);    
                    return el.firstChild;    
                case "beforeend":    
                    el.insertAdjacentHTML('BeforeEnd', html);    
                    return el.lastChild;    
                case "afterend":    
                    el.insertAdjacentHTML('AfterEnd', html);    
                    return el.nextSibling;    
            }    
            throw 'Illegal insertion point -> "' + where + '"';    
        }    
        var range = el.ownerDocument.createRange();    
        var frag;    
        switch(where){    
             case "beforebegin":    
                range.setStartBefore(el);    
                frag = range.createContextualFragment(html);    
                el.parentNode.insertBefore(frag, el);    
                return el.previousSibling;    
             case "afterbegin":    
                if(el.firstChild){    
                    range.setStartBefore(el.firstChild);    
                    frag = range.createContextualFragment(html);    
                    el.insertBefore(frag, el.firstChild);    
                    return el.firstChild;    
                }else{    
                    el.innerHTML = html;    
                    return el.firstChild;    
                }    
            case "beforeend":    
                if(el.lastChild){    
                    range.setStartAfter(el.lastChild);    
                    frag = range.createContextualFragment(html);    
                    el.appendChild(frag);    
                    return el.lastChild;    
                }else{    
                    el.innerHTML = html;    
                    return el.lastChild;    
                }    
            case "afterend":    
                range.setStartAfter(el);    
                frag = range.createContextualFragment(html);    
                el.parentNode.insertBefore(frag, el.nextSibling);    
                return el.nextSibling;    
            }    
            throw 'Illegal insertion point -> "' + where + '"';    
    }    
function shownews(num)
{
	var sidebar=document.getElementById("menuBar_focus");
	var bigbar=document.getElementById("focus_tab");
	for(var i=0;i<3;i++)
	{
		if(i!=num)
		{
			sidebar.childNodes[i].className="";
			bigbar.childNodes[i].className="normal";
		}
		else
		{
			sidebar.childNodes[i].className="on";
			bigbar.childNodes[i].className="normal on";
		}
	}
}

var fh_marginLeft=0;
var fh_run=false;
function fh_stop()
{
	fh_run=false;
}
function fh_start()
{
	if(fh_run)
		return;
	fh_run=true;
	if(fh_marginLeft==0)
		fh_main(0,-1);
	else
		fh_main(0,1);
	//alert(fh_marginLeft);
}
function fh_main(num,ds)
{
	var speed=150;
	if(num>50)
	{
		
		speed-=(num-50)*20;
		fh_marginLeft+=speed*ds;
		document.getElementById("float_inner").style.marginLeft=fh_marginLeft;
		if(fh_marginLeft==-480 || fh_marginLeft==0)
		{
			ds=-ds;
			num=0;
			if(!fh_run)
				return;
		}
		
		
		

		
	}else if(!fh_run)
	{
		return;
	}
	setTimeout("fh_main("+(num+1)+","+ds+")",100);
}	
