function Media_Play(){
	document.MediaPlayer.play();
}

function Media_Stop(){
	document.MediaPlayer.stop();
}

function Media_Pause(){
	document.MediaPlayer.pause();
}

function Media_Vol_Stop(){
	document.MediaPlayer.Mute = true;
}

function Media_Vol_Play(){
	document.MediaPlayer.Mute = false;
}

function strRight(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

var flvFlag = false;	 //Flv 파일 일때

function MediaWrite( strFile ){
	
	var iW = 320;
	var iH = 238;
	var objTag = "";	// Flv 파일일때
	objTag += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width='344' height='306' id=MediaPlayer>";
	objTag += "<param name=wmode value='transparent' />";
	objTag += "<param name=quality value=high />";
	objTag += "<param name='movie' value='/flash/MediaPlayer.swf?strFile=" + strFile + "'>";
	objTag += "<embed src='/flash/MediaPlayer.swf?strFile=" + strFile + "' quality=high wmode='transparent' type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash\" width='344' height='306'>";
	objTag += "</embed>";
	objTag += "</object>";
	
	var _object_ = "";
	_object_= '<OBJECT ID="MediaPlayer" Name="MediaPlayer" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject" width="' + iW + '" Height="' + iH + '" VIEWASTEXT>';
	_object_ += '<param name="AutoSize" value="0">';
	_object_ += '<param name="AutoResize" value="-1">';
	_object_ += '<param name="AutoStart" value="true">';
	_object_ += '<param name="EnableContextMenu" value="false">';
	_object_ += '<param name="ShowControls" value="0">';
	_object_ += '<param name="Volume" value="0">';
	_object_ += '<param name="FileName" value="' + strFile + '">';
	_object_ += '</OBJECT>';
	
	var strObj = "";
	if( strRight(strFile, 3).toLowerCase() == "flv" ){
		document.write(objTag);
		return false;
	}else{
		strObj = _object_;
		flvFlag = true;
	}
	 
	 var _strTable = "";
	_strTable = '<table width="344" height="306" border="0" cellpadding="0" cellspacing="0">';
	_strTable += '  <tr>';
	_strTable += '    <td align="center" valign="top" background="/media_skin/meda_bg.gif"><table width="320" border="0" cellpadding="0" cellspacing="0">';
	_strTable += '      <tr>';
	_strTable += '        <td height="13" valign="top"></td>';
	_strTable += '      </tr>';
	_strTable += '      <tr>';
	_strTable += '        <td height="238" align="center" valign="middle" bgcolor="#CCCCCC">' + strObj + '</td>';
	_strTable += '      </tr>';
	_strTable += '      <tr>';
	_strTable += '        <td height="45" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" style="position:absolute">';
	_strTable += '          <tr>';
	_strTable += '            <td height="22"><DIV id="progressBar" style="Z-INDEX: 6; POSITION: relative;" LANGUAGE="javascript" onmousedown="return progressBar_onmousedown()" onmouseover="this.style.cursor=\"hand\"><DIV style="Z-INDEX: 5; POSITION: relative;"><img src="/media_skin/loding_iocn.gif" width="10" height="6" name="position_bg"></div></div></td>';
	_strTable += '          </tr>';
	_strTable += '          <tr>';
	_strTable += '            <td><table width="320" border="0" cellspacing="0" cellpadding="0"  style="position:absolute">';
	_strTable += '              <tr>';
	_strTable += '                <td width="20"><img src="/media_skin/play_on.gif" style="cursor:hand" onclick="Media_Pause();" width="20" height="20"></td>';
	_strTable += '                <td width="5">&nbsp;</td>';
	_strTable += '                <td width="20"><img src="/media_skin/play.gif" style="cursor:hand" onclick="Media_Play();" width="20" height="20"></td>';
	_strTable += '                <td width="5">&nbsp;</td>';
	_strTable += '                <td width="20"><img src="/media_skin/stop.gif" width="20" style="cursor:hand" onclick="Media_Stop();" height="20"></td>';
	_strTable += '                <td width="205" align="right"><img src="/media_skin/sp_off.gif" style="cursor:hand" onClick="Media_Vol_Stop();" width="11" height="7"><img src="/media_skin/sp_on.gif" style="cursor:hand" onClick="Media_Vol_Play();" width="11" height="7" hspace="5"></td>';
	_strTable += '                <td width="45"><div id="VolumeBar" style="Z-INDEX: 2; POSITION: relative; height: 1px;" language="javascript" onMouseDown="VolumeBar_onmousedown()" onMouseOver="this.style.cursor=\"hand\"><div style="Z-INDEX: 1; POSITION: relative;"><img src="/media_skin/loding_iocn.gif" border="0" width="10" height="6" name="vol_position_bg"></div></div></td>';
	_strTable += '              </tr>';
	_strTable += '            </table></td>';
	_strTable += '          </tr>';
	_strTable += '        </table></td>';
	_strTable += '      </tr>';
	_strTable += '    </table></td>';
	_strTable += '  </tr>';
	_strTable += '</table>';
	 
	 document.write(_strTable);
}

// 동영상 제어 스크립트...

var oldPos = 0;          //클릭시 마우스좌표
var oldPixel = 0;        //클릭시 슬라이더 좌표
var bDrag = false;       //움직임
var bPlay = true;        //플레이중

/********************************************************************
재생 관련
********************************************************************/
var progressBar_StartPixel =0;        //플레이바 시작위치
var progressBar_Size = 310;        //플레이바 크기
function progressBar_onmousedown() {
    if (!bPlay)
        return false;
        
    if (MediaPlayer.CurrentPosition == -1 )        //Player.FileName이 설정되어 있지 않으면 걍 리턴해 버린다.
        return false;

    oldPos = event.clientX;
    bDrag  = true;
    TrackBar = event.srcElement.parentElement;
    oldPixel = progressBar.style.pixelLeft; 
    document.onmousemove = PlayMoveSlider;
    if(document.all)
    {
        document.onmouseup = PlayStopSlider;
    }
}

function PlayMoveSlider() {
    if (bDrag) {
        var XPos = oldPixel + (event.clientX - oldPos);    //최초 마우스다운일때 좌표에서 mousemove한 좌표값
        if((progressBar_StartPixel <= XPos  ) && (XPos <= progressBar_StartPixel + (progressBar_Size  ) ) )    
        {
        
            //프로그래스바 이동
            document.all.progressBar.style.pixelLeft = XPos;
                
        }//if((XPos >= startVolPos) &&....
        return false;
    }
    
}


function PlayStopSlider() {

    bDrag = false;
        
    MediaPlayer.currentPosition  = Pixel2Pos(progressBar.style.pixelLeft - progressBar_StartPixel)
    if (MediaPlayer.PlayState == 1)    //일시 중지 일때, 즉 스라이더 움직임에 의해 중단되었을 때만, 다시 실행
        MediaPlayer.Play();        
       
    document.onmousemove = null;
    if(document.all);
        document.onmouseup = null;
}    

function Pixel2Pos(nPixel)
{
        return parseInt((nPixel) * MediaPlayer.Duration / progressBar_Size);
}


var volumeMin = -3000;
var volumeMax = 0;
var volumeValue = 0;
var oldVolume = 0;
var VolumeBar_StartPixel = 0;
var VolumeBar_Size = 38;    //볼륨바 크기

function VolumeBar_onmousedown() {
    if (!bPlay)
        return false;
        
    oldPos = event.clientX;                            //최초 마우스다운일때 좌표
    oldPixel = VolumeBar.style.pixelLeft;                //최초 마우스다운 일때 슬라이더좌표
    oldVolume = MediaPlayer.Volume;
    bDrag = true;
    document.onmousemove = VolumeMoveSlider;            //onmousemove캡쳐
    if (document.all)
        document.onmouseup=VolumeStopSlider;        //onmousemove 해제
}

function VolumeMoveSlider() {
    if (bDrag) {
        var XPos = oldPixel + event.clientX - oldPos;    //최초 마우스다운일때 좌표에서 mousemove한 좌표값
        
        if((VolumeBar_StartPixel <= XPos  )
            && (XPos <= VolumeBar_StartPixel + VolumeBar_Size ) )    
        {
            
            VolumeBar.style.pixelLeft = XPos;    //마우스 이동한 만큼 슬라이더 이동
            vol_position_bg.style.pixelLeft = VolumeBar.style.pixelLeft - VolumeBar_StartPixel;
            var mouseMove = XPos - oldPixel;    //마우스이동값
            var currentVolumeValue = oldVolume - parseInt(mouseMove * volumeMin / VolumeBar_Size );
            
            if( currentVolumeValue <= -4929) 
                MediaPlayer.Volume = volumeMin;
            else if(currentVolumeValue >= volumeMax)
                MediaPlayer.Volume = volumeMax;
            else 
                MediaPlayer.Volume = currentVolumeValue;    
    

        }
        return false;
    }//if (bDrag)
}

function VolumeStopSlider() {
    bDrag = false;
}

function VolumeInit() {

    //볼륨초기화
    VolumeBar.style.pixelLeft = VolumeBar_StartPixel + VolumeBar_Size /2  ;
    vol_position_bg.style.pixelLeft = VolumeBar.style.pixelLeft - VolumeBar_StartPixel;
    MediaPlayer.Volume =  volumeMin / 2;
}


function ScrollBarState() {

    //CurrentPosition.innerHTML = TimeFormat(MediaPlayer.CurrentPosition);
    //Duration.innerHTML = TimeFormat(MediaPlayer.duration);
    if( document.MediaPlayer == null || !flvFlag )
    	return false;
    
    if(bDrag == false)
    {
        progressBar.style.pixelLeft = progressBar_StartPixel + parseInt(MediaPlayer.CurrentPosition*progressBar_Size/MediaPlayer.duration);
    }
        position_bg.pixelLeft =parseInt(MediaPlayer.CurrentPosition*progressBar_Size/MediaPlayer.duration);
    
}


function TimeFormat(totalsecond)
{
    
    var second = parseInt(totalsecond) % 60;
    var minute = parseInt(totalsecond / 60);    
    return ((minute < 10)?"0":"")+minute+":" + ((second < 10)?"0":"")+second;
}

window.setInterval("ScrollBarState();",500);

// 동영상 시작시 제어해주기

