<?php
include_once "tadtools_header.php";

class JwPlayer{
	var $image;
	var $file;
	var $skin;
	var $width;
	var $height;
	var $mode;
  var $display;
  var $backcolor;
  var $frontcolor;
  var $lightcolor;
  var $screencolor;
  var $id;

	//建構函數
	function JwPlayer($id="",$file="",$image="",$width="",$height="",$skin="",$mode="",$display="",$backcolor="",$frontcolor="",$lightcolor="",$screencolor="",$other_code=""){
		$this->width=(empty($width))?480:$width;
		$this->height=(empty($height))?360:$height;
		$this->file=$file;
		$this->image=$image;
		$this->skin=(empty($skin))?TADTOOLS_URL."/mediaplayer/skin/glow.zip":$skin;
		//$this->skin=(empty($skin))?TADTOOLS_URL."/mediaplayer/skin/beelden.zip":$skin;
		$this->mode=$mode;
		$this->display=$display;
		$this->backcolor=$backcolor;
		$this->frontcolor=$frontcolor;
		$this->lightcolor=$lightcolor;
		$this->screencolor=$screencolor;
		$this->id=$id;
		$this->other_code=$other_code;
	}

	//設定自定義設寬度
	function setWidth($width=""){
		$this->width=$width;
	}

	//設定自定義設高度
	function setHeight($height=""){
		$this->height=$height;
	}
	
	//設定自定義影片檔
	function setFile($file=""){
		$this->file=$file;
	}
	
	//設定自定義縮圖
	function setImage($image=""){
		$this->image=$image;
	}

	//設定自定佈景
	function setSkin($skin=""){
		$this->skin=$skin;
	}

	//產生播放器
	function render(){
    $playlistfile="";
    if($this->mode=="playlist"){
      $file="
      playlistfile:'{$this->file}',
      playlist:'{$this->display}',
      repeat:'list',";
    }else{
      $file="file:'{$this->file}',";
    }

    $backcolor=$frontcolor=$lightcolor=$screencolor="";
    if($this->backcolor)  $backcolor="backcolor:'{$this->backcolor}',";
    if($this->frontcolor)  $frontcolor="frontcolor:'{$this->frontcolor}',";
    if($this->lightcolor)  $lightcolor="lightcolor:'{$this->lightcolor}',";
    if($this->screencolor)  $screencolor="screencolor: '{$this->screencolor}',";
    
    $wh=($this->mode=='pda')?"width:screen.width,height: pda_height, ":"
        width: {$this->width},
        height: {$this->height},";

    $player="<script type='text/javascript' src='".TADTOOLS_URL."/mediaplayer/jwplayer.js'></script>
    
    <div id='mediaspace{$this->id}'>Loading the player ...</div>

    <script type='text/javascript'>
      var pda_height=screen.width * 0.75;
      
      jwplayer('mediaspace{$this->id}').setup({
        flashplayer: '".TADTOOLS_URL."/mediaplayer/player.swf',
        $file
        image:'{$this->image}',
        $wh
        skin: '{$this->skin}',
        $backcolor
        $frontcolor
        $lightcolor
        $screencolor
        plugins: {
            viral: { onpause: 'false' ,oncomplete:'false', functions:'embed' },
            'hd-2': {state : true}
        },
        $this->other_code
	      stretching: 'fill',
	      autostart: 'false'
      });
    </script>";
    return $player;
  }

}
?>
