function initWPM(){    
    if(navigator.userAgent.indexOf("Firefox/")!=-1) isFirefox=true;
    if(!isFirefox){
        if (navigator.userAgent.indexOf("Windows NT 5.1") != -1) {
            clsid = "6BF52A52-394A-11D3-B153-00C04F79FAA6";
            wpapi = 7;
        } else {
            var cv = null;
            document.write("<IE:clientCaps ID=\"oClientCaps\" style=\"{behavior:url(#default#clientcaps)}\" />");
            cc=oClientCaps;
            cv= cc.getComponentVersion("{6BF52A52-394A-11D3-B153-00C04F79FAA6}", "componentid");
            if (cv == null || cv == "") {
                clsid = "22D6F312-B0F6-11D0-94AB-0080C74C7E95";
                wpapi = 6;
            } else {
                clsid = "6BF52A52-394A-11D3-B153-00C04F79FAA6";
                wpapi = 7;
            }
        }
    }
    else{
        wpapi=6;
    }
    wp_init=true;
}


function writeBgPlayer(objName){
    var vmstr="";
    if(wpapi==7){
       vmstr="<object id='"+objName+"' width=0 height=0 classid='CLSID:"+clsid+"' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715' align='baseline' border='0' type='application/x-oleobject'>"
              +"<param name='URL' value=''>"
              +"<param name='rate' value='1'>"
              +"<param name='currentPosition' value='0'>"
              +"<param name='playCount' value='1'>"
              +"<param name='autoStart' value='0'>"
              +"<param name='uiMode' value='invisible'>"
              +"<param name='stretchToFit' value='false'>"
              +"<param name='enableContextMenu' value='0'>"
               +"</object>";
    }
    else{
         vmstr="<object id='"+objName+"' classid='CLSID:"+clsid+"' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715' align='baseline' border='0' type='application/x-oleobject'>"
              +"<param name='fileName' value=''>"
              +"<param name='rate' value='1'>"
              +"<param name='currentPosition' value='0'>"
              +"<param name='playCount' value='1'>"
              +"<param name='autoStart' value='0'>"
              +"<param name='stretchToFit' value='false'>"
              +"<param name='enableContextMenu' value='0'>"
              +"<param name='showControls' value='0'>"
              +"<embed name='"+objName+"' src='' align='baseline' border='0'type='application/x-mplayer2' pluginspage='http://www.microsoft.com/isapi/redir.dll?prd=windows&amp;sbp=mediaplayer&amp;ar=media&amp;sba=plugin&amp;' rate='1' showControls='0'  currentPosition='0' playCount='1' autoStart='0'  stretchToFit='false' enableContextMenu='-1'> "
              +"</embed>"
               +"</object>";
    }
    document.writeln(vmstr);
 }

function writeMVPlayer(name,width,height,divname){
    var vmstr="";
    if(wpapi==7){
       vmstr="<object id='"+name+"' width='"+width+"' height='"+height+"' classid='CLSID:"+clsid+"' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715' align='baseline' border='0' type='application/x-oleobject'>"
              +"<param name='URL' value=''>"
              +"<param name='rate' value='1'>"
              +"<param name='currentPosition' value='0'>"
              +"<param name='playCount' value='1'>"
              +"<param name='autoStart' value='0'>"
              +"<param name='uiMode' value='none'>"
              +"<param name='stretchToFit' value='false'>"
              +"<param name='enableContextMenu' value='-1'>"
               +"</object>";
    }
    else{
         vmstr="<object id='"+name+"' width='"+width+"' height='"+height+"' classid='CLSID:"+clsid+"' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715' align='baseline' border='0' type='application/x-oleobject'>"
              +"<param name='fileName' value=''>"
              +"<param name='rate' value='1'>"
              +"<param name='currentPosition' value='0'>"
              +"<param name='playCount' value='1'>"
              +"<param name='autoStart' value='0'>"
              +"<param name='stretchToFit' value='false'>"
              +"<param name='enableContextMenu' value='-1'>"
              +"<param name='showControls' value='0'>"
              +"<embed name='"+name+"' src='' align='baseline' border='0' width='"+width+"' height='"+height+"' type='application/x-mplayer2' pluginspage='http://www.microsoft.com/isapi/redir.dll?prd=windows&amp;sbp=mediaplayer&amp;ar=media&amp;sba=plugin&amp;' rate='1' showControls='0'  currentPosition='0' playCount='1' autoStart='1'  stretchToFit='false' enableContextMenu='-1'> "
              +"</embed>"
               +"</object>";
    }
    document.getElementById(divname).innerHTML=vmstr;
 };

MopMusicPlayer=function (){
}

MopMusicPlayer.prototype= {
    playerObj:null,

    musicList:null,

    playingPos: 0,

    isPlaying:false,

    isPause:false,

    timeid:null,

    objInstance:"MopMusicPlayer",

    init:function(player){
      this.playerObj=player;
      this.musicList=new Array();
    },

    setObjInstance:function (objName){
        this.objInstance=objName;
    },

    play:function(){
        if (wpapi == 7)
                this.playerObj.controls.play();
        else{
            this.playerObj.Play();
         }
         this.isPlaying=true;
         this.isPause=false;
         this.showRePlayingMusicInfo();
    },

    pause:function (){
        if(this.isPlaying)
        {
            if (wpapi == 7){
                this.playerObj.controls.pause();
            }
            else {
                this.playerObj.Pause();
             }
            this.isPlaying=false;
            this.isPause=true;
            this.pausePlayingMusicInfo();
        }
    },

    stop: function(){
        if(this.isPlaying)
       {
        if (wpapi == 7)
            this.playerObj.controls.stop();
        else
            this.playerObj.Stop();
        this.isPlaying=false;
        this.isPause=false;
      }
    },

    muteAction: function(){
        this.playerObj.settings.mute=!this.playerObj.settings.mute;
    },

    setMax: function(){
        this.playerObj.fullScreen=!(this.playerObj.fullScreen);
    },

    playURL: function(url){
        //window.status=url;
        this.playerObj.URL=url;
        this.play();
    },

    playAction: function (){
       try{
           if(this.timeid!=null) {
               clearTimeout(this.timeid)
               this.timeid=null;
           }
       }catch(exp){
           alert("playAction1:"+playAction);
       }
       try{
           if(this.musicList.length>0){
                //alert("11");
                media= this.musicList[this.playingPos];
                //alert("222");
                info="playAction["+this.playingPos+"]url["+media.url+"]";
                //window.status=info;
               //alert("333");
                this.playURL(media.url);
               //alert("444");
               this.showPlayingMusicInfo(media);
                //showMsBgMusicInfo(media);
           }
       }
       catch(ex){
           alert("playAction:"+ex)
       }
    },

    resumePlay:function(){
       if(this.isPause){
           this.play();
       }
       else{
           this.playAction();
       }
    },

    showPlayingMusicInfo:function(media){
    },

    pausePlayingMusicInfo:function(){
    },

    showRePlayingMusicInfo:function(){
    },

    dbClickPlay: function(mid){
        var i=0;
        for(i=0;i<this.musicList.length;i++){
            if(this.musicList[i].id==mid){
               this.playingPos=i;
               break;
            }
        }
        this.playAction();
    },

    addMusic: function(mediaItem) {
       this.musicList.push(mediaItem);
       if(this.musicList.length==1){
          //playURL(mediaItem.url);
          this.playAction();
       }
    },

    playNext:function(){
       if(this.musicList.length>0){
           this.playingPos++;
           if(this.playingPos>=this.musicList.length) this.playingPos=0;
           this.timeid=setTimeout(this.objInstance+".playAction()",5);
       }
    },

    playNextAction:function(){
       if(this.musicList.length>0){
           this.playNext();
       }
    },

    playPre:function(){
       //info+="playing forward";
       //window.status=info;
       this.playingPos--;
       if(this.playingPos<0) this.playingPos=this.musicList.length-1;
       if(this.playingPos>-1) {
            this.timeid=setTimeout(this.objInstance+".playAction()",5);
       }
    },

    playPos:function (pos){
        if(pos<0) pos=0;
        if(pos<this.musicList.length){
            if(this.musicList.length>0){
                this.playingPos=pos;
                this.timeid=setTimeout(this.objInstance+".playAction()",5);
            }
        }
    },

    playerSetVolume:function(v) {
      if (wpapi == 7)
        this.playerObj.Settings.volume = 100 * v;
      else
        this.playerObj.Volume = 10000 * v - 10000;
       return v;
    },


     reset:function(){
         this.musicList=null;
         this.musicList = new Array();
         this.playingPos=0;
         this.isPlaying=false;
         this.timeid=null;
         this.isPause=false;
     }

}

MopChanelPlayerPlayer=function(){
}

MopChanelPlayerPlayer.prototype= new MopMusicPlayer();

MopChanelPlayerPlayer.prototype.timeshow=false;

MopChanelPlayerPlayer.prototype.updateTimeTimeid=null;

MopChanelPlayerPlayer.prototype.endPlay=function (){
}

MopChanelPlayerPlayer.prototype.changeState=function (state){
    try {
        switch (state) {
            case 0:
            //alert("Undefined Windows Media Player is in an undefined state. ");
                break;
            case 1:
            //alert(" Stopped Playback of the current media item is stopped. ");
               this.timeshow = false;
               this.endPlay();
                break;
            case 2:
            //alert(" Paused Playback of the current media item is paused. When a media item is paused, resuming playback begins from the same location. ");
                break;
            case 3:
            //alert(" Playing The current media item is playing. ");
                try{
                    this.timeshow = true;
                    this.updatetime();
                }
                catch(exx){
                    //alert("case3:"+exx);
                }
                //this.updateBite();
                break;
            case 4:
            //alert(" ScanForward The current media item is fast forwarding. ");
                break;
            case 5:
            //alert(" ScanReverse The current media item is fast rewinding. ");
                break;
            case 6:
            //alert(" Buffering The current media item is getting additional data from the server. ");
                break;
            case 7:
            //alert(" Waiting Connection is established, but the server is not sending data. Waiting for session to begin. ");
                break;
            case 8:
            //alert(" MediaEnded Media item has completed playback.  ");
            //this.playNext();
                break;
            case 9:
            //alert(" Transitioning Preparing new media item. ");
                break;
            case 10:
            //alert(" Ready Ready to begin playing. ");
                break;
            case 11:
            //alert(" Reconnecting Reconnecting to stream. ");
                break;
            default:
                break;
        }
    } catch(ex) {
        alert("changeState:"+ex)
    }
 }


MopChanelPlayerPlayer.prototype.updatetime=function() {
    try{
        if (this.timeshow) {
            try {
                var ss = "",ss1="";
                var curtime=0;
                if (wpapi == 7){
                    ss = this.playerObj.controls.currentPositionString;
                    curtime=this.playerObj.controls.currentPosition;
                 }
                else{
                    ss = this.playerObj.currentPositionString;
                    curtime=this.playerObj.currentPosition;
                 }
                ss1=this.playerObj.currentMedia.durationString;
                document.getElementById('PlayTimeInfo').innerHTML = ss+"|"+ss1;
                this.updateTimeTimeid = setTimeout(this.objInstance + ".updatetime()", 1000);
                var totaltime= this.playerObj.currentMedia.duration;
                var poslen=(curtime/totaltime)*time_td_len;
                document.getElementById("time1_info").width=poslen;
                document.getElementById("time2_info").width=(time_td_len-poslen);
            } catch(ex) {
                //alert("updatetime:"+ex);
            }
        }
        else{
        }
    }
    catch(eee){
        alert(eee);
    }
}

MopChanelPlayerPlayer.prototype.updateBite=function() {
    var bitrate= this.playerObj.currentMedia.getItemInfo("Bitrate");
    document.getElementById('BitRateDiv').innerHTML = (Math.round(bitrate / 1000)) + "k";
}

try {
   chPlayer=new MopChanelPlayerPlayer();
   chPlayer.setObjInstance("chPlayer");
}
catch(ex) {
    alert("new chPlayer :"+ex)
}

function murl(url){
	url=url.replace("//","/");
    var pos=url.indexOf("mop.com");
    var s=url.substring(pos+8);
    var pos1=s.indexOf("/");
    return url.substring(0,pos+8)+mroot+s.substring(pos1);

}
function movie_play(){
    document.getElementById("pic_div").style.display="none";
    document.getElementById("mv_div").style.display="block";
    try {
        chPlayer.reset();
        var mvmi=new MediaItem(1,murl(hpurl),"","",0);
        chPlayer.addMusic(mvmi);
    } catch(ex) {
    }
}

function mv_pl(url){
    document.getElementById("pic_div").style.display="none";
    document.getElementById("mv_div").style.display="block";
    time_td_len=196;
    try {
        chPlayer.reset();
        var mvmi=new MediaItem(1,murl(url),"","",0);
        chPlayer.addMusic(mvmi);
    } catch(ex) {
    }
}

function movie_pause(){
   try {
        chPlayer.pause();
    } catch(ex) {
    }
}

function movie_mute(){
   try {
        chPlayer.muteAction();
    } catch(ex) {
    }
}

function movie_setMax(){
   try {
        chPlayer.setMax();
    } catch(ex) {
       alert("setMax:"+ex);
    }
}

function move_back(){

}

function move_forward(){

}

function ChPlayStateChange(lOldState, lNewState){
    try {
        if (wpapi == 7)
            try {
                chPlayer.changeState(lOldState);
            } catch(ex) {
                //alert("chPlayer"+ex)
            }
        else
            chPlayer.changeState(lNewState);
    } catch(ex) {
        //alert("chPlayer:"+lOldState+","+ex);
    }
}

var dragapproved = false;

    function initializedragie(){
        iex = window.event.clientX
        iey = window.event.clientY
        dragapproved = true
        document.getElementById("volimg").onmousemove = drag_dropie
        if (document.all)
        {
            document.onmouseup = new Function('dragapproved=false')
        }
    }

    function drag_dropie(){
        if (dragapproved == true){
            var mov = event.clientX - iex
            //alert("mov="+mov)
            if (mov >-20 && mov < 30)
            {
                try{
                    v1=17+mov;
                    if(v1<0) v1=0;
                    if(v1>57) v1=57;
                    document.getElementById("vol1_info").width=v1;
                    document.getElementById("vol2_info").width=(57-v1);
                    var loudness = (v1+20) * 100 / 50 ;
                    if (loudness > 0 && loudness < 100)
                    {
                        chPlayer.playerSetVolume(loudness / 100);
                    }
                }
                catch(exp){}
            }
            return false
        }
    }


