//sonic编写于2012-2-7
//邮箱chshcms@qq.com
// 版权所有*禁止非法获取*违者必究------chshcms.com
var Ylmv_Player;
var rnd=Math.round(Math.random()*(list.length-1));
var rndd=false;//随机播放else顺序播放
var order=true;//循环播放else不循环
var mute=true;//静音
/////////////////////////////////////////////////////////////////////////////////////////////
function xmlac(){
var xmlHttp;
if(window.ActiveXObject){xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
else if(window.XMLHttpRequest){xmlHttp = new XMLHttpRequest();}
return xmlHttp
}
//////////////////////////////////获取地址//////////////////////////////////////////////////////////

function onplay(id){
	document.getElementById("music_title").innerHTML="";
	window.document.getElementById("music_title").innerHTML=""+list[rnd][2]+"";
	//var xmlHttp=xmlac();
	Ylmv_Player.url=id;
	//xmlHttp.open("get",true);
    //xmlHttp.send();
	//xmlHttp.onreadystatechange =function(){
		//if(xmlHttp.readystate==4){
			//Ylmv_Player.url=xmlHttp.responseText;
			//}
	   //}
	   
	}
//////////////////////////////////////决定ID///////////////////////////////////////////////////////////
function gid(id){
	if(document.getElementById("plist"+rnd+"")){document.getElementById("plist"+rnd+"").style.color="#000";}
	
	if(id!=null){onplay(list[id][1]);rnd=id}else{
		
	if(rndd){//顺序
		
		if(rnd+1>list.length){rnd=0;}else{rnd+=1}
		
		}else{//随机
		rnd=Math.round(Math.random()*(list.length-1));
		}
	if(rnd>list.length){rnd=1;}
	
	onplay(list[rnd][1]);
	}
	window.document.getElementById("music_title").innerHTML=""+document.getElementById("plist"+rnd+"").innerHTML+"";
	document.getElementById("plist"+rnd+"").style.color="#1e50c1";
	}


//////////////////////////////////////////进度条//////////////////////////////////////////////////
     var x;
	 var down=false;
     function init(obj){
		 obj.style.position="relative";
		 var ll=obj.style.left.replace("px","")*1;
		 x=event.clientX;
         down=true;
		 document.onmousemove=function(){
			if(down){
			if(event.clientX-x+ll>0){
				if((obj.id=="valume"&&event.clientX-x+ll<70)||(obj.id=="play_pr"&&event.clientX-x+ll<720)){
				obj.style.left=event.clientX-x+ll+"px";
				vandp(obj);}
			}
			 }}
		 document.onmouseup=function(){down=false;}
     }

function onpr(){
	var statu=Ylmv_Player.playState;

	switch(statu){
		case 1:
		statu="停止";
		break;
		case 2:
		statu="暂停";
		break;
		case 3:
		statu="播放";
		
	len=Ylmv_Player.currentmedia.duration;
	nowt=Ylmv_Player.controls.currentPosition;
	xs=len/nowt;
	now=Math.floor(720/xs);
	document.getElementById("play_pr").style.left=now+"px";
	document.getElementById("play_mm").style.width=now+"px";
	
	var nowtime=Ylmv_Player.controls.currentPosition;
	var lentime=Ylmv_Player.currentmedia.duration;
	if(lentime-nowtime<10){gid();}
		break;
		case 4:
		statu="";
		break;
		case 5:
		statu="寻找";
		break;
		case 6:
		statu="正在缓冲...";
		break;
		case 7:
		statu="";
		break;
		case 8:
		statu="";
		break;
		case 9:
		statu="正在连接...";
		break;
		case 10:
		statu="准备就绪";
		gid();
		break;
		case 11:
		statu="";
		break;
		}
	nowt=Ylmv_Player.controls.currentPositionString;
	document.getElementById("music_time").innerHTML=statu+"|"+nowt;
	window.status="☆→"+list[rnd][2]+"→状态:"+statu+"|"+nowt;
	st=setTimeout("onpr()",1000);
	}

///////////////////////////////////////////////按钮变换///////////////////////////////////////////////////////////
function tran(obj){
	var nowTime = new Date();
	if(obj.src.indexOf("_")<0){
		obj.src="/iimages/play/"+obj.name+"_2.gif?"+nowTime.getTime();
	}else{
		obj.src="/iimages/play/"+obj.name+".gif?"+nowTime.getTime();
	}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////
function clickk(type){
	switch(type){
		case "rnd":
		if(rndd){
			rndd=false;
			}
		break;
		case "order":
			if(order){
			order=false;
			}else{
				order=true;
			}
		break;
		case "stop":
			Ylmv_Player.controls.stop();
			document.getElementById("ss").className="btn-1";
		break;
		case "pass":
		gid(rnd-1);
		break;
		case "su":
		if(Ylmv_Player.playState==3){
				Ylmv_Player.controls.pause();
				document.getElementById("ss").className="btn-1";
			}else{
				Ylmv_Player.controls.play();
				document.getElementById("ss").className="btn-2";
			}
		break;
		case "next":
		gid(rnd+1);
		break;
		case "fav":
			var favurl = "/user/do.php?ac=fav&id="+list[rnd][0];
			window.open(favurl);
		break;
		case "down":
			var downurl = "/down.php?id="+list[rnd][0];
			window.open(downurl);
		break;

		case "mute":
		if(mute){
			Ylmv_Player.settings.mute=true;
			mute=false;
			document.getElementById("mut").className="player-sound-off";
		}else{
			Ylmv_Player.settings.mute=false;
			mute=true;
			document.getElementById("mut").className="player-sound-on";
		}
		break;
	}
}
function lhhgo(){
	document.getElementById("playlist").innerHTML=playlist;
}
//////////////////////////////////////////初始化/////////////////////////////////////////////////////////////////
function dilist(){
document.getElementById("play_mm").innerHTML="<OBJECT ID=Ylmv_Player CLASSID=CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6 width=0 height=0><param NAME=AutoStart VALUE=1><param NAME=PlayCount VALUE=1><param name=invokeURLs value=0><param name=volume value=50><param name=EnableContextMenu value=0><PARAM NAME=URL value=></OBJECT>"
var playlist="";
for (var i=0;i<list.length;i++){
	playlist+="<li onclick=\"gid("+i+");\" id=\"plist"+i+"\">"+(i+1)+"."+list[i][2]+"</li>";
}
document.getElementById("playlist").innerHTML=playlist;
Ylmv_Player=document.getElementById("Ylmv_Player");
document.getElementById("plist"+rnd+"").style.color="#1e50c1";
onplay(list[rnd][1]);
}

document.getElementById("valume").style.position="relative";
document.getElementById("play_pr").style.position="relative";

dilist();
setTimeout(function(){onpr();},800);
///////////////////////////////////////////////////////////////////////////


function vandp(obj){
	var ol=obj.style.left.replace("px","")*1;
	switch(obj.id){
	case "valume":
	//alert(volu);
	Ylmv_Player.settings.volume=ol*2;
	break;
	
	case "play_pr":
	musice=Ylmv_Player.currentYlmv_Player.duration;
	musice=musice/730;
	//alert(musice);
	//Ylmv_Player.CanSeek=true;
	Ylmv_Player.controls.currentPosition=ol*musice;
	//alert(1);
	break;
	}
	}

function gett(){
	alert(Ylmv_Player.controls.currentPosition);
	//setTimeout("gett()",1000)
	}

function CheckAll(form)
{
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
//		if (e.name != 'chkall')
			e.checked = true// form.chkall.checked;
	}
}

function CheckOthers(form)
{
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
//		if (e.name != 'chkall')
			if (e.checked==false)
			{
				e.checked = true;// form.chkall.checked;
			}
			else
			{
				e.checked = false;
			}
	}
}

function click(e) {
if (document.all) {
if (event.button==2||event.button==3) {
oncontextmenu='return false';
}
}
if (document.layers) {
if (e.which == 3) {
oncontextmenu='return false';
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
function showplaylist(s){
	if(document.getElementById(s).style.display=='none'){
		document.getElementById(s).style.display='block'; //显示层
	}else if(document.getElementById(s).style.display=='block'){		
		document.getElementById(s).style.display='none'; //隐藏层
	}
}
var pubLibs = {
	autoScrollMiniblog: function(){
		var $ul = $("#miniblog").children("ul:eq(0)");
		$ul.children("li:last").prependTo($ul);
		setTimeout('pubLibs.autoScrollMiniblog()',2500);
	}
}
pubLibs.autoScrollMiniblog();