﻿// JScript 文件
var mpUndefined= 0;
var mpStopped= 1;
var mpPaused= 2;
var mpPlaying= 3;
var mpScanForword= 4;
var mpScanReverse= 5;
var mpBuffering= 6;
var mpWaiting= 7;
var mpMediaEnded= 8;
var mpTransitioning= 9;
var mpReady = 10;
var mpReconnection= 11;
var PlayerOldSongID="";
var intErrCnt=1;
var tid;
	var a8playlist=new Array();
	var curIndex=0;
		//拖动播放
		var bDraging=false;
		var oldState;
		var LastWidth=350;
		var xPos;
		var mmsplayuerURL ; //播放的MUSIC
		var menudomain="http://"+ location.hostname +"/";
		function getQueryString(s)
		{
				    
					var theurl=window.location.href;
					theurl=theurl.toLowerCase();
					var index1=theurl.indexOf(s+"=");
					if(index1==-1) return "0";	    
					if(theurl.indexOf(menudomain)==-1 ||  theurl.indexOf("style=")>-1) return "0";
					var index2=theurl.indexOf("&",index1);
					if(index2==-1) index2=theurl.length;
					if(theurl.substring(index1+s.length+1,index2)==null || theurl.substring(index1+s.length+1,index2)=="")
					return "0";
					else
					return theurl.substring(index1+s.length+1,index2);

		}
		function StartDrag()
		{
		  // alert(event.srcElement.name);
			if(event.button!=1) return;
		   var mmszhibo=document.all("mmszhibo"); 
			if (!mmszhibo)
			   return false	;
		
			if(event.srcElement.name != "drag")
				return;
			oldState=mmszhibo.PlayState;
			
			if(3!=oldState&&2!=oldState&&1!=oldState) return;
			if(3==oldState && mmszhibo.controls.isAvailable('pause'))
				mmszhibo.controls.Pause();
			xPos=event.x;
			bDraging=true;
			
		}
		function EndDrag()
		{
			var mmszhibo=document.all("mmszhibo"); 
			if (!mmszhibo)
			  return false	;
			if(!bDraging) return;
			bDraging=false;
			mmszhibo.controls.currentPosition=mmszhibo.currentMedia.duration*document.all.past.width/LastWidth;
			if(3==oldState && mmszhibo.controls.isAvailable('play'))
				mmszhibo.controls.Play();
		}
		function Draging()
		{
		 	var mmszhibo=document.all("mmszhibo"); 
			if (!mmszhibo)
			  return false	;
			if(bDraging && event.button==1)
			{
				var progress=new Number(event.x-xPos);
				var tmp=new Number(document.all.past.width);
				progress=tmp + progress;
				if(progress<=0)
					progress=1;
				else if(progress>LastWidth)
					progress=LastWidth;
				xPos = event.x;
				document.all.past.width=progress;
		
				event.returnValue = false
					event.cancelBubble = true
			}
		}
		  function   init()   {   
          window.document.onmousemove   =   Draging   
          //window.document.onmousedown   =   StartDrag   
          window.document.onmouseup   =   EndDrag   
          window.document.ondragstart   =   StartDrag   
  }   
  		init();
		function DoStop()
		{ 
		    var mmszhibo=document.all("mmszhibo"); 
			if (!mmszhibo)
			  return false		  
		   mmszhibo.controls.stop();  
		  document.all.past.width=1;	
		}
		function doMute(s){
		    var mmszhibo=document.all("mmszhibo"); 
			if (!mmszhibo)
			  return false		    
		     mmszhibo.settings.mute = s;
		     if(s){
		      	document.getElementById("soundon").style.display="none";
		      	document.getElementById("soundoff").style.display="block";
		     }else{
		      	document.getElementById("soundon").style.display="block";
		      	document.getElementById("soundoff").style.display="none";		     
		     }
		}
		function DoPause()
		{ 
		   var mmszhibo=document.all("mmszhibo");	
			if (!mmszhibo)
			  return false		  
		   mmszhibo.controls.pause();  
  			//document.getElementById("play").style.display="block";	
			//document.getElementById("pause").style.display="none";	
		}
		/*播放*/
		function DoPlay()
		{
			var mmszhibo=document.all("mmszhibo");	
			if (!mmszhibo)
			  return false		  
		    mmszhibo.controls.play();  
		}
		function PlayID(id)
		{
			var mmszhibo=document.all("mmszhibo");	
			DoStop();
			curIndex=id;
			mmszhibo.url = document.all("music_"+a8playlist[curIndex]).value;//alert(mmszhibo.url);
			setTimeout('DoPlay()', 500);
			document.all.curmusicname.title=document.all("name_"+id).value	;
			document.all.curmusicname.innerHTML= document.all("name_"+id).value.substring(0,10)	;
		}
		function PlayNext()
		{
			if(a8playlist.length>1 && curIndex+1<a8playlist.length)
			{
				curIndex=curIndex+1;
				PlayID(curIndex);
				
			}
		}
		function PlayerMute()
		{
			var mmszhibo=document.all("mmszhibo");
			if (!mmszhibo)
			  return false	
			  
			 if (mmszhibo.settings.mute == true) {
				mmszhibo.settings.mute= false;
				//document.all.mutesrc.src="http://main.a8-img.com/www/img/playflash_21.gif";
			}
			else {
				mmszhibo.settings.mute= true;
				//document.all.mutesrc.src="http://main.a8-img.com/www/img/playflash_2.gif";				
			}
			
		
		}
		function ShowTime()
		{
		    try{
				if(!bDraging)//如果不是拖动状态，按时间滚动
				{
					var move=Math.floor(document.all.mmszhibo.controls.currentPosition/document.all.mmszhibo.currentMedia.duration*LastWidth);
					if(move<=0) move=1;
					if(move != document.all.past.width)
					{
						
						document.all.past.width=move;
						document.all.curtime.innerHTML=document.all.mmszhibo.controls.currentPositionString ;
						document.all.curalltime.innerHTML=document.all.mmszhibo.currentMedia.durationString ;
					}
				}
			}catch(err){
					document.all.past.width=1;
					window.clearTimeout(idTimeTmr);
					return ;
			}/**/
		}
		  function swapdiv()
			{
			    //debugger;
			    if(document.getElementById("play").style.display=="block")
			    {
				
				    document.getElementById("play").style.display="none";
				    document.getElementById("pause").style.display="block";
                }
                else
                {
				 document.getElementById("play").style.display="block";
				 document.getElementById("pause").style.display="none";
                }
			}
	var fff=false;
	var ff=false;
    function CRPlayerNewState(NewState)
    {	
		 switch (NewState) 
		{
			case mpPlaying:
				   idTimeTmr = window.setInterval("ShowTime()",1000);
		          break;
			case mpPaused:			
				break; 
			case mpBuffering:			
				break;
			case mpStopped:
				break;
			case mpReconnection:
				break;
			case mpMediaEnded:						
				break;
			case mpTransitioning:
				return;
			case mpReady:		
				break;    
			}


    }

    function evtOSChg(NewState)
    {	
            switch (NewState) 
			{
	
				case 0:

                     DoStop();	
	                 document.all.past.width=1;
		           break;
				 case 8:

				 	break;

				}


    }
	function evtWmpError()
	{
		window.clearTimeout(idTimeTmr);
		intErrCnt++;
		document.all.mmszhibo.Error.clearErrorQueue();
		if(intErrCnt<3)
		{
			PlayID(curIndex);	
		}
		
	}
    document.write("<script language=\"JScript\" event=\"openStateChange(lNewState)\" for=\"mmszhibo\">");
 	document.write("evtOSChg(lNewState); ");  
	document.write("</script>");	
	document.write("<script language=\"JScript\" event=\"error()\" for=\"mmszhibo\">");
 	document.write("evtWmpError();");
 	document.write("</script>");
	
	
	
	
	
	

