
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, "");
}

function wgid(id)
{
	return self.document.getElementById(id);
}
function redirect(url)
{
	document.location.href= url;
}
function menuControl(show , numID , id)
{
	showImg(show , id);
	try{
		if(show==1)
			showMenu("menu_"+numID);
		else
			hideMenu(wgid("menu_"+numID));
	}
	catch(error)
	{

	}
}
function chooseDefault()
{
	try{
		var o = wgid(_choose);
		o.src = 'core/images/head/nav-'+_choose.replace('nav' , '')+'-over.jpg';
	}
	catch(e){}
}
function showImg(show , objID)
{
	try{
		var o = wgid(objID);
		if(show==1)
			o.src = 'core/images/head/nav-'+objID.replace('nav' , '')+'-over.jpg';
		else
		{
			if(_choose != objID)
				o.src = 'core/images/head/nav-'+objID.replace('nav' , '')+'.jpg';
		}
		}catch(e){}
}

function displayMenu(obj , nbottom)
{
	try{
		var speed = 1;
		obj.style.clip="rect(0 100% "+nbottom+"% 0)";
		nbottom += 1;
		if(nbottom <= 100)
		{
			timerID = setTimeout("displayMenu("+obj.id+" , "+nbottom+"),100");
		}
		else
		clearTimeout(timerID);
	}
	catch(e){}
}
function showMenu(obj)
{
	wgid('default').style.display = 'none';
	wgid(obj).style.display="block";
	wgid(obj).style.clip="rect(0 0 0 0)";
	nbottom = 20;
	displayMenu(wgid(obj) , nbottom);
}

function hideMenu(obj)
{
	nbottom=0;
	wgid('default').style.display = 'block';
	obj.style.display="none";
}

function keepMenu(obj)
{
	wgid('default').style.display = 'none';
	obj.style.display="block";
}

function subsearch() {
	if(frmsearch.key.value=='') 
	{
		alert('请填写搜索关键字');
		return false;
	}
	frmsearch.submit();
}

function WOpenV(ruls){
	var rul=ruls;
	var Xl=(screen.width -627)/2;
	var Yl=(screen.height-480)/2;
	window.open('play.html?vid='+rul+'&m=a', 'newwindow', 'height=480, width=627, toolbar=no, menubar=no, scrollbars=no, resizable=yes,location=no, status=no');
	return false;
}

function WOpenF(ruls)
{
	var rul=ruls;
	var Xl=(screen.width  - 627)/2;
	var Yl=(screen.height - 480)/2;
	window.open('play.html?id='+rul+'&m=a', 'newwindow', 'height=480, width=627, top='+Yl+', left='+Xl+', toolbar=no, menubar=no, scrollbars=no, resizable=yes,location=no, status=no');
	return false;
}

function WOpenVV(vid , width , height)
{
	var clip = GetClip(width , height);
	window.open('play.html?vid='+vid, 'newwindow', 'height='+clip.h+', width='+clip.w+', top='+clip.y+', left='+clip.x+', toolbar=no, menubar=no, scrollbars=no, resizable=yes,location=no, status=no');
	return false;
}
function GetClip(width , height)
{
	height = height + 160;
	width = width + 120;	
	if(width<702)width = 702;
	if(height<580)height = 580;
	var Xl = (window.screen.width-width)/2;
	var Yl = (window.screen.height-height)/2;
	if(Xl < 0)Xl=0;
	if(Yl < 0)Yl=0;
	return {'w':width,'h':height,'x':Xl,'y':Yl};
}
function WOpenFF(id , width , height)
{
	var clip = GetClip(width , height);
	window.open('play.html?id='+id, 'newwindow', 'height='+clip.h+', width='+clip.w+', top='+clip.y+', left='+clip.x+', toolbar=no, menubar=no, scrollbars=no, resizable=yes,location=no, status=no');
	return false;
}

function OpenPlayerWindow_nsc(FileName,nscName)
{
	w = 819; 
	h = 610;
	var Xl=(screen.width -w)/2;
	var Yl=(screen.height-h)/2;
    window.open('zhibo.html?bdname='+FileName+'&nscName='+nscName,'PlayerWindow','width='+w+',height='+h+', top='+Yl+', left='+Xl+',resizable=yes,scrollbars=yes');
}


var B = BigNews = {	current:0,	next:0,	scrollInterval:0,	autoScroller:0};
BigNews.turn = function(index)
{
	clearInterval(BigNews.autoScroller);
	BigNews.scroll(index);
}
BigNews.scroll = function(index)
{
	if(!wgid('ul_big_news_item'))
	{
		clearInterval(BigNews.autoScroller);
		return;
	}
	var count=0;
	var step=282;
	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++){
		items[i].className='';
	}
	items[index].className='up';
	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()
{
	clearInterval(BigNews.autoScroller);
	BigNews.autoScroller = setInterval(function()
	{
		BigNews.scroll(BigNews.current == (toprunlength-1) ? 0 : BigNews.current + 1);
	} , 4000);
}

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 hidep;
function showAllList(obj , num )
{
	
	objf = GetOffset(obj);
	wgid('drtalch').style.left    = objf.left + 93;
	wgid('drtalch').style.top     = objf.top  - 1;
	img = wgid('drtallimg');
	if(num == 1)
	{
		clearTimeout(hidep);
		wgid('drtalch').style.display = "block";
		obj.style.width = 103;
		obj.setAttribute('src' , 'core/images/zb_02.gif');
	}
	else
	{
		hidep = setTimeout(function (){wgid('drtalch').style.display = "none";
		obj.style.width = 98;
		obj.setAttribute('src' , 'core/images/leftlitl.gif');},1000);
		 
	}
}

function ListShow( obj , num)
{
	if(num==1)
	{
		clearTimeout(hidep);
		obj.style.display='block';
		wgid('drtall').style.width = 103;
		wgid('drtall').setAttribute('src' , 'core/images/zb_02.gif');
	}
	else
	{
		hidep = setTimeout(function (){
		obj.style.display='none';
		wgid('drtall').style.width = 98;
		wgid('drtall').setAttribute('src' , 'core/images/leftlitl.gif');},500);
		
	}
}

function showMsg(nscname , bdname , unixtime , name , time , obj , type)
{
	var destine = wgid('destine');
	var outdes = wgid('outdes');
	if((outdes.style.display == 'none' || outdes.style.display == '') && (destine.style.display == 'none' || destine.style.display == ''))
	{
		if(type == 'nba')
		var vid    = type+nscname.replace('.' , '-');
		else
		{
			var vid    = nscname.replace('.' , '-');
			var img = wgid('img'+vid);
		}

		var modify = wgid(vid);
		var drt = GetOffset(wgid('drtright'));
		var nleft = 4;
		if(borwser.isIE == 1)
		{
			if(borwser.version == '7.0')
			{
				nleft = 8;
			}
		}
		if(type != 'nba')
		{
			path = img.src;
		}
		if(modify.value == 0)
		{
			oAjax.connect("ajax.php" , "POST" , "act=addnotice&nscname="+nscname.trim()+"&bdname="+bdname.trim()+"&unixtime="+unixtime.trim()+"&name="+name.trim()+"&type="+type , function(r){} ,'text');

			destine.style.left    = drt.left + nleft;
			destine.style.top     = drt.top  + 48;
			destine.style.display = "block";
			wgid('destinetext').innerHTML = '<font color="#FFCC00">'+name+'</font>';
			wgid('timetext').innerHTML    = '<font color="#FFCC00">'+time+'分钟后播出</font>';
			obj.title = '取消该节目预定';
			modify.value  = 1;
			if(type != 'nba')
			{
				shoimg = path.replace('yuding' , 'qvxiao');

				img.setAttribute('src' , shoimg);
			}

			setTimeout('closeMsg("destine")' , 4000);
		}
		else if(modify.value == 1)
		{
			oAjax.connect("ajax.php" , "POST" , "act=delnotice&nscname="+nscname.trim()+"&type="+type , function(r){

			} ,'text');
			outdes.style.left    = drt.left + nleft;
			outdes.style.top     = drt.top  + 55;
			outdes.style.display = "block";
			wgid('outdestext').innerHTML = '<font color="#FFCC00">'+name+'</font>';
			modify.value  = 0;
			obj.title = '预定该节目';
			if(type != 'nba')
			{
				shoimg = path.replace('qvxiao' , 'yuding');

				img.setAttribute('src' , shoimg);
			}
			setTimeout('closeMsg("outdes")' , 2000);
		}
	}
	

}

function closeMsg(id)
{
	wgid(id).style.display = 'none';
}

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 showPop()
{ 
	var _s = document.getElementById('snd');
	_s.src = 'core/images/sound/notify.wav';
	var obj = document.getElementById("pop"); 
	obj.style.display  = "block"; 
	obj.style.position = "absolute"; 
	obj.style.zindex   = "999"; 
	var width = 220; //弹出框的宽度 
	var height = 100; //弹出框的高度 
	obj.style.width    = width  + "px"; 
	obj.style.height   = height + "px"; 
	var Position = getPosition(); 
	leftadd = Position.width  - width  - 10; 
	topadd  = Position.height - height - 10; 
	obj.style.top  = (Position.top + topadd ) + "px"; 
	obj.style.left = (Position.left + leftadd) + "px"; 

	window.onscroll = function ()
	{ 
		var Position = getPosition(); 
		obj.style.top  =  (Position.top + topadd )   + "px"; 
		obj.style.left =  (Position.left + leftadd ) + "px"; 
	}
} 

function hidePop()
{ 
	document.getElementById("pop").style.display = "none"; 
}

function Show()
{
	oAjax.connect("ajax.php" , "POST" , "act=checknotice" , function(rlt){
	if(rlt.msg == 'true')
	{
		wgid('viewname').innerHTML = '<a href="javascript:;" ><font color="#FFCC00">'+urldecode(rlt.name)+'</font></a>';
		wgid('viewname').onclick = function ()
		{
			OpenPlayerWindow_nsc( urldecode(rlt.bdname), urldecode(rlt.nscname) );
			hidePop();
		}
		wgid('popplayers').onclick = function ()
		{
			OpenPlayerWindow_nsc( urldecode(rlt.bdname), urldecode(rlt.nscname) );
			hidePop();
		}
		showPop();
		window.focus();
	}
} ,'json');
}

