function SohuVideoPlayer(){
}

SohuVideoPlayer.prototype={
objectName:null,
//播放器初始图片
playerpic:null,
//播放地址
playUrl:null,
volumeBPic:null,
volumeFPic:null,
//播放器初始化提示文字
playdisp : "搜狐体育播报",
//播放按钮
playbtnstr:null,
//暂停按钮
pausebtnstr:null,
//初始化音量，0至100的10的倍数
volumeNum :50,
volumeBarLen :10,
volumeBarHeight :5,
isInstall : false,
player:null,
bak_vNum:null,

//-------------------<逻辑变量>-------------------//
mLen:108,					//进度条（背景图）长度
timeObj : null,				//计时器对象
mediaLen : 0,				//素材时长

isAfterPause : false,
isPlaying : false,
isItself : false,
moveOver : false,
moving : false,

itemindex : -1,
medianame : "",

advindex:0,

volumeobj:null,
playorpause:null,
vmask:null,
wmplayer:null,
mblock:null,
timeObj:null,
debug:true,
recomment:'',

setPlayFile:function(){
	this.setVolume(this.volumeNum );
    var appname = navigator.appName;
    var pvs = "";
    if( userPlayerVersion != null && userPlayerVersion.length > 0 ) {
		pvs = userPlayerVersion.substring( 0, userPlayerVersion.indexOf( "." ) );
    }
    if(Math.round( pvs ) < 9 ) {
		var tmps ="";
		if(Math.floor(pvs)<9){
			tmps = '<a href="http://yule.sohu.com/20060619/n243815034.shtml" target="_blank"><font color="#FFFFF">请用Windows Media Player 9 播放器观看视频</font></a>　<a href="http://go.microsoft.com/fwlink/?LinkId=34682" target="_blank"><font color="#FFFFFF">点击下载</font></a>';
        }else{
            tmps = '<a href="http://yule.sohu.com/20060619/n243815034.shtml#w01" target="_blank"><font  size=4 color="#FFFFF">请安装搜狐PXP流媒体加速引擎</font></a><br><a href="http://p3p.sogou.com/dl/sogou_pxp.exe" target="_blank"><font size=4 color="#0000FF">点击下载</font></a><br><font  size=4 color="#FFFFF">安装完成后您需要刷新本页才可以正常播放</font>';
        } 
				
			  var errorstr = '';
        errorstr += '<table width=175 height=131 border=0 cellpadding=0 cellspacing=0>';
        errorstr += '<tr><td bgcolor="black" align="center">' + tmps + '</td></tr>';
        errorstr += '</table>';

        this.vmask.innerHTML = errorstr;
        this.isItself = true;         
    }

    if( appname == "Microsoft Internet Explorer" ) {
		this.wmplayer.URL = this.playurl;
		this.play();
    } else {
    		this.playorpause.innerHTML = "";
    	  this.vmask.style.display = "none";
				this.wmplayer.style.display = "none";
				this.controlsss.style.display = "none";				
//        var tmps = "对不起，本视频需要在以IE为核心的浏览器上观看！";
//        var errorstr = '';
//  			errorstr += '<table width=360 height=270 border=0 cellpadding=0 cellspacing=0>';
//        errorstr += '<tr><td bgcolor="black" align="center"><font color="white">' + tmps + '</font></td></tr>';
//        errorstr += '</table>';
//        this.vmask.innerHTML = errorstr;
//        this.isItself = true;
   }
},
//num为0-100的整数，这里只使用10的倍数
setVolume:function(num){
	this.volumeNum = num;
	var volumeHeight = Math.round(num / 10);
	var volumeStr = '';
	var width = Math.floor(this.volumeBarLen/ 10);

	if( this.isPlaying ) {
		this.wmplayer.settings.volume = this.volumeNum;
	}

	for( var i = 2; i <= 5; i ++ ) {
		var volumePic = null;
		if( i <= volumeHeight ) {
			volumePic = this.volumeFPic;
		}else{			
			volumePic = this.volumeBPic;
		}
		if(i == 5){
			width = this.volumeBarLen - (i-1)*width;
		}
		volumeStr += '<img src=" ' + volumePic + '" width="3" height="' + i + '" style="cursor:hand" onClick="javascript:'+this.objectName+'.setVolume(\'' + (i-1)*10 + '\')" alt="视频新闻">';

	}	
	this.volumeobj.innerHTML = volumeStr;
},

stopV:function(){
	var num = this.volumeNum;
	if(num == 0) {
		this.setVolume(this.bak_vNum);
	} else {
		this.bak_vNum = this.volumeNum;
		this.setVolume(0);
	}
},
//设定进度条长度
setProsLength:function( splen ) {
	this.mLen = splen;
},

doDragStart:function(){ 
	event.returnValue = false; 
},

//清除计时器对象
clrTime:function () {
	if( this.timeObj != null ) {
		clearTimeout( this.timeObj );
		this.timeObj = null;
	}
},

//创建新的计时器
openTime:function() {
	this.clrTime();	
	this.timeObj = setTimeout( this.objectName+".showPros()", 500 );
},

setMbPos:function( pos ) {
	try {
		this.mblock.style.left = pos;
	} catch( e ) {
		if(this.debug){
			//alert("Sorry,error:"+e.message);
		}
	}

	return false;
},

setPosition:function( pos ) {
	try {
		this.wmplayer.controls.currentPosition = pos;
	} catch( e ) {		
	}

	return false;
},

moveok:function() {
	try {
		if( this.isPlaying && this.moveOver ) {
			this.moving = false;
			this.moveOver = false;
			this.wmplayer.controls.play();
			if( event.x < this.mLen && this.mediaLen > 0 ) {
					this.setPosition( Math.floor( event.x * this.mediaLen / this.mLen ) );
			}
		}
	} catch( e ) {
		if(this.debug){
			//alert("moveok:"+e.message);
		}
	}

	return false;
},

play:function() {
	try {
		if( !this.isItself  && this.objectName=="sohuPlayer") {			
			this.vmask.style.display = "none";
			this.wmplayer.style.display = "block";
			
			if( this.isAfterPause ) {
				this.wmplayer.controls.play();
			} else {
				this.wmplayer.URL = this.playurl;
                this.setPosition( 0 );
				this.wmplayer.controls.play();
			}

			this.isAfterPause = false;
			this.isPlaying = true;
			this.isItself = true;

			this.setVolume(this.volumeNum );
			this.playorpause.innerHTML = this.pausebtnstr;
			this.openTime();
		} 
	} catch( e ) {		
		try{
			setTimeout( this.objectName+".play()", 1000 );
		}catch(e2){			
		}	
	}
	return false;
},

pause:function() {
	try {
		if( this.isPlaying && this.wmplayer.PlayState == 3 ) {
			this.isAfterPause = true;
			this.isPlaying = false;
			this.isItself = false;

			this.playorpause.innerHTML = this.playbtnstr;

			this.wmplayer.controls.pause();
			this.clrTime();
		}
	} catch( e ) {}

	return false;
},

stop:function() {
	try {
		if( this.isPlaying || this.isAfterPause ) {
			this.windowpic.src = this.playerpic;
			if(this.recomment!=''){
				vmask.innerHTML = this.recomment;
			}
			this.isAfterPause = false;
			this.isItself = false;
			this.isPlaying = false;

			this.wmplayer.controls.stop();

			this.setMbPos( 0 );
			this.setPosition( 0 );
			this.playorpause.innerHTML = this.playbtnstr;
			this.wmplayer.style.display = "none";
		  this.vmask.style.display = "block";
			this.clrTime();
			this.timesec = 0;
			this.playsign = 0;
			this.advindex = 0;			
		}
	} catch( e ) {
		//alert(e.message);
		}

	return false;
},

movego:function() {
	try {
		if( this.isPlaying && this.moveOver ) {
			if( event.x < this.mLen && event.x > -1 ) {
				this.moving = true;
				this.setMbPos( event.x );
			}
		}
	} catch( e ) {
		if(this.debug){
			//alert("movego:"+e.message);
		}
	}

	return false;
},

reachTo:function() {
	try {
		if( this.isPlaying ) {
			this.moveOver = true;
			this.wmplayer.controls.pause();

			if( event.x < this.mLen && event.x > -1 ) {
				this.moving = true;
				this.setMbPos( event.x );
			}
		}
	} catch( e ) {
		if(this.debug){
			//alert("reachTo:"+e.message);
		}
	}

	return false;
},


moves:function () {
	try {
		if( this.isPlaying ) {
			this.moveOver = true;
			this.wmplayer.controls.pause();
		}
	} catch( e ) {
		if(this.debug){
			//alert("moves:"+e.message);
		}
	}

	return false;
},

showFullscreen:function() {
	try {
		this.wmplayer.fullScreen = 'true';
	} catch( e ) {}

	return false;
},

showPros:function() {
	try {
		if( this.isPlaying ) {
			if(  this.wmplayer.PlayState == 1 ||  this.wmplayer.PlayState == 10 ) {
				 this.windowpic.src = this.playerpic;
				 if(this.recomment!=''){
				 	vmask.innerHTML = this.recomment;
				 }
				 this.isAfterPause = false;
				 this.isItself = false;
				 this.isPlaying = false;

				 this.setMbPos( 0 );
				 this.setPosition( 0 );

				this.playorpause.innerHTML =this.playbtnstr;
				this.wmplayer.style.display = "none";
				this.vmask.style.display = "block";
				this.timesec = 0;
				this.playsign = 0;
				this.advindex = 0;
				this.clrTime();
			} else if(this. wmplayer.PlayState != 0 ) {
				var curpos = this.wmplayer.controls.currentPosition;
				this.mediaLen = this.wmplayer.currentMedia.duration;
				if( this.mediaLen == 0 ) {
					this.setMbPos( 0 );
				} else {
					if( !this.moving ) {
						this.setMbPos( Math.floor( ( curpos / this.mediaLen ) * this.mLen ) );
					}
				}

				this.openTime();
			}
		}
	} catch( e ) {
		if(this.debug){
			//alert("showPros:"+e.message);
		}
	}

	return false;
},

addLoad:function (loadFunc) {
  var oldonload = window.onload;
  if(typeof window.onload != 'function'){
    window.onload = loadFunc;
  }else{
    window.onload = function(){
      if (oldonload) {
        oldonload();
      }
      loadFunc();
    }
  }
},
init:function(){
	document.ondragstart = this.doDragStart;
	document.onmouseup = this.moveok;
}
};
