var CurrentPlayImage = null;
var CurrentPauseImage = null;
var bVideo = null;
var bWasBuffering = false;
var wmpocx = null;

function StopPlayer()
{

    wmpocx.controls.stop();
    wmpocx.close();
    if (CurrentPlayImage != null)
    {
        CurrentPlayImage.src = "xlib/com/enpassant/tennis/images/audio/bt_play.gif";
        CurrentPlayImage = null;
    }

    if (CurrentPauseImage != null)
    {
        CurrentPauseImage.src = "xlib/com/enpassant/tennis/images/audio/bt_pause.gif";
         CurrentPauseImage = null;
    }
    bWasBufferring = false;
}

function ClipPlayState(NewState)
{
    switch(NewState)
    {
    case 1:    // stopped

	if (bWasBuffering)
	{
        	bWasBufferring = false;
	        if (CurrentPlayImage != null)
        	{
	            CurrentPlayImage.src = "xlib/com/enpassant/tennis/images/audio/bt_play.gif";
        	}
	}
        break;

    case 6:    // buffering

        bWasBufferring = true;
        if (CurrentPlayImage != null)
        {
            CurrentPlayImage.src = "xlib/com/enpassant/tennis/images/audio/bt_load.gif";
        }
        break;

    case 9:    // transitioning
    case 11:   // reconnecting

        bWasBufferring = false;
        break;

    case 3:    // playing

        if (bWasBufferring)
        {
            if (CurrentPlayImage != null)
            {
                CurrentPlayImage.src = "xlib/com/enpassant/tennis/images/audio/bt_stop.gif";
            }

    	    if (bVideo)
            {
                wmpocx.fullScreen = true;
            }
        }
        break;

    default:
    }
}

function PlayClip(url, imgId, imgPauseId, video)
{
    var img = document.getElementById(imgId);

    CurrentPauseImage = document.getElementById(imgPauseId);

    if(wmpocx == null)
        wmpocx = document.getElementById("wmpocx");

     if (wmpocx.playState == 2)
     {

        PauseClip();
        return;
     }

    if (wmpocx.playState == 3 && bVideo != null && bVideo != video)
    {
        return;
    }

    bVideo = video;
    //CurrentPlayImage = img;
    if (wmpocx.playState == 3)
    {

        StopPlayer();
        CurrentPlayImage = img;
    }
    else
    {
        CurrentPlayImage = img;
        if (CurrentPlayImage != null)
        {
            CurrentPlayImage.src = "xlib/com/enpassant/tennis/images/audio/bt_load.gif";
        }
        wmpocx.URL = url;
    }
}

function PauseClip(objId)
{
    var img = document.getElementById(objId);

    if(wmpocx.playState == 3)
    {
        if(CurrentPauseImage.id != img.id)
        {

            StopPlayer();
        }
    }

    if(img != null)
        CurrentPauseImage = img;

    if (wmpocx.playState == 3)
    {
        CurrentPlayImage.src = "xlib/com/enpassant/tennis/images/audio/bt_load_pause.gif";
        CurrentPauseImage.src = "xlib/com/enpassant/tennis/images/audio/bt_pause_active.gif";
        wmpocx.controls.pause();
        return;
    }
    if (wmpocx.playState == 2)
    {
        CurrentPlayImage.src = "xlib/com/enpassant/tennis/images/audio/bt_load.gif";
        CurrentPauseImage.src = "xlib/com/enpassant/tennis/images/audio/bt_pause.gif";
        wmpocx.controls.play();
        return;
    }

}
function PlayButtonOver(img)
{

   img.src = "xlib/com/enpassant/tennis/images/audio/bt_over.gif";
}

function PlayButtonOut(img)
{
    //alert(img.id);
    if(CurrentPlayImage == null || CurrentPlayImage.id != img.id) {
        img.src = "xlib/com/enpassant/tennis/images/audio/bt_play.gif";
        return;
    }

    if (wmpocx.playState == 3 || wmpocx.playState == 6 ||   wmpocx.playState == 9 || wmpocx.playState == 11) {
        CurrentPlayImage.src = "xlib/com/enpassant/tennis/images/audio/bt_load.gif";
    }
    else if(wmpocx.playState == 2) {
        CurrentPlayImage.src = "xlib/com/enpassant/tennis/images/audio/bt_load_pause.gif";
    } else {
        CurrentPlayImage.src = "xlib/com/enpassant/tennis/images/audio/bt_play.gif";
    }
}

function PauseButtonOver(img)
{

   //if(CurrentPauseImage == null || CurrentPauseImage.ID != img.ID)
     img.src = "xlib/com/enpassant/tennis/images/audio/bt_pause_active.gif";

}

function PauseButtonOut(img)
{
    if(CurrentPauseImage != null && CurrentPauseImage.id == img.id)
    {
       if (wmpocx.playState != 2 )
        {
            img.src = "xlib/com/enpassant/tennis/images/audio/bt_pause.gif";
        }
    }
    else
         img.src = "xlib/com/enpassant/tennis/images/audio/bt_pause.gif";


}

