// player_music

    var use_loading     = 0;
    var auto_start      = 0;
    var use_timer       = 0;
    var use_sync        = 1;
    var use_band        = 0;
    var max_index       = 2;
    var def_sync        = "sf_kanban340_160.jpg";
    var sync_width      = "340";
    var sync_height     = "160";

    var index_name      = new Array();
    index_name[0]       = "S.F.STUDIO STREAMING";
    index_name[1]       = "S.F.STUDIO STREAMING";

    var index_url       = new Array();
    index_url[0]        = "http://www.sfstudio.jp/sound/4th/ccandyboy.asx";
    index_url[1]        = "http://www.sfstudio.jp/sound/4th/nnudeBB.asx";

    var index_sec       = new Array();
    index_sec[0]        = 0;
    index_sec[1]        = 0;

    var index_sync      = new Array();
    index_sync[0]       = "candyboy_kashi.jpg";
    index_sync[1]       = "nudeBB_kashi.jpg";

    var index_fsync     = new Array();
    index_fsync[0]      = "saisei.jpg";
    index_fsync[1]      = "saisei.jpg";

    var index_fsync_x   = new Array();
    index_fsync_x[0]    = 488;
    index_fsync_x[1]    = 488;

    var index_fsync_y   = new Array();
    index_fsync_y[0]    = 115;
    index_fsync_y[1]    = 243;

    var index_fsync_w   = new Array();
    index_fsync_w[0]    = 20;
    index_fsync_w[1]    = 20;

    var index_fsync_h   = new Array();
    index_fsync_h[0]    = 24;
    index_fsync_h[1]    = 24;

    var now_fsync       = "none"
    var now_fsync_x     = 0;
    var now_fsync_y     = 0;
    var now_fsync_w     = 0;
    var now_fsync_h     = 0;


    var now_index       = 0;
    var wait_buffer     = 0;
    var set_pos         = 0;
    var now_sync        = def_sync;
    var play_timer;
    var wait_timer;
    var load_timer1;
    var load_timer2;

    var char1           = new Array("1","2","3","4","5","6","7","8","9","0");
    var char2           = new Array("1","2","3","4","5","6","7","8","9","0");
    var before_band     = "　　　　　0 Kbps";

function initHtml()
{
   if(document.all)
   {
       wait_timer = setTimeout("waitTimerFunc()", 100);

       if(auto_start == 1)
       {
            execPlay();
            set_pos = index_sec[now_index];
            setPosition();
       }
       return;
   }
   if(document.layers)
   {
       document.layers.baseL.visibility = "hide";
       document.layers.dummyL.visibility = "show";

       return;
   }

   document.getElementById('baseL').style.visibility = 'hidden';
   document.getElementById('dummyL').style.visibility = 'visible';
   return;
}

function waitTimerFunc()
{
    clearTimeout(wait_timer);

    if(use_timer == 1)
    {
        dispCounter();
    }
    if(use_sync == 1)
    {
        dispSync();
    }
    if(use_band == 1)
    {
        dispBandWidth();
    }
    if(use_loading == 0)
    {
        wait_timer = setTimeout("waitTimerFunc()", 100);
        return;
    }

    l_status = document.video1.PlayState;
    l_buffer = document.video1.BufferingProgress;

    if(l_status >= 3 && l_status <= 7)
    {
        document.all.waitL.style.visibility = "visible";
        document.all.playL.style.visibility = "hidden";
    }
    else
    {
        if(l_status == 2 && l_buffer < 80)
        {
            document.all.waitL.style.visibility = "visible";
            document.all.playL.style.visibility = "hidden";
        }
        else
        {
            document.all.waitL.style.visibility = "hidden";
            document.all.playL.style.visibility = "visible";
        }
    }

    wait_timer = setTimeout("waitTimerFunc()", 100);
    return;
}

function dispBandWidth()
{
    l_status = document.video1.PlayState;
    l_buffer = Math.floor(document.video1.BufferingProgress);

    if((l_status == 2 && l_buffer < 80) || (l_status >= 3 && l_status <= 7))
    {
        if(l_buffer < 0)
        {
            l_buffer = 0;
        }
        if(l_buffer >= 100)
        {
            l_buffer = 0;
        }
        l_buffer2 = toMultiString(l_buffer ,2);

        disp_buffer = "バッファ処理中:" + l_buffer2 + "%";
    }
    else
    {
        band_use = Math.floor(document.video1.Bandwidth);
        band_use = Math.floor(band_use / 1000);

        if(l_status != 2)
        {
            band_use = 0;
        }
        if(band_use < 0)
        {
            band_use = 0;
        }
        if(band_use > 9999)
        {
            band_use = 9999;
        }
        band_use2 = toMultiString(band_use ,4);

        disp_buffer = "　　" + band_use2 + "Kbps";
    }

    if(before_band == disp_buffer)
    {
        return;
    }

    before_band = disp_buffer
    document.all.bandWidthL.innerHTML = disp_buffer;

    return;
}

function toMultiString(in_number ,fix_len)
{
    var result_str = "";
    number = "" + in_number;
    num_len = number.length ;

    for(i = num_len ;i < fix_len ;i++)
    {
        result_str = result_str + "　";
    }

    for(i = 0 ;i < num_len ;i++)
    {
        temp_str = number.charAt(i);

        for(j = 0 ;j < 10 ;j++)
        {
            if(temp_str == char2[j])
            {
                result_str = result_str + char1[j];
                break;
            }
        }
    }

    return result_str;
}

function dispSync()
{
    l_this_index = now_index;
    l_status = document.video1.PlayState;

    if(l_status != 2)
    {
        return;
    }

    l_pos = document.video1.CurrentPosition;
    l_len = document.video1.Duration;
    if(l_pos < 0)
    {
        return;
    }
    if(l_len <= l_pos)
    {
        return;
    }

    for(lop = (now_index + 1) ;lop < max_index ;lop++)
    {
        if(index_url[now_index] == index_url[lop])
        {
            if(l_pos < index_sec[lop])
            {
                break;
            }
            l_this_index = lop;
        }
        else
        {
            break;
        }
    }

    if(now_sync != index_sync[l_this_index])
    {
        if(index_sync[l_this_index] == "none")
        {
            if(def_sync != "none")
            {
                out_buf = "<IMG SRC=\"" + def_sync + "\" WIDTH=\"" + sync_width + "\" HEIGHT=\"" + sync_height + "\" BORDER=\"0\">";
            }
            else
            {
                out_buf = "";
            }
        }
        else
        {
            out_buf = "<IMG SRC=\"" + index_sync[l_this_index] + "\" WIDTH=\"" + sync_width + "\" HEIGHT=\"" + sync_height + "\" BORDER=\"0\">";
        }

        if(document.all)
        {
            document.all.syncL.innerHTML = out_buf;
        }

        now_sync = index_sync[l_this_index];

    }

    if(now_fsync != index_fsync[l_this_index]
    || now_fsync_x != index_fsync_x[l_this_index] || now_fsync_y != index_fsync_y[l_this_index]
    || now_fsync_w != index_fsync_w[l_this_index] || now_fsync_h != index_fsync_h[l_this_index])
    {
        if(index_fsync[l_this_index] == "none")
        {
            out_buf = "";
        }
        else
        {
            out_buf = "<IMG SRC=\"" + index_fsync[l_this_index] + "\" WIDTH=\"" + index_fsync_w[l_this_index] + "\" HEIGHT=\"" + index_fsync_h[l_this_index] + "\" BORDER=\"0\">";
        }

        if(document.all)
        {
            document.all.syncFreeL.innerHTML = out_buf;
            document.all.syncFreeL.style.left = index_fsync_x[l_this_index];
            document.all.syncFreeL.style.top = index_fsync_y[l_this_index];
            document.all.syncFreeL.style.width = index_fsync_w[l_this_index];
            document.all.syncFreeL.style.height = index_fsync_h[l_this_index];
        }

        now_fsync = index_fsync[l_this_index];
        now_fsync_x = index_fsync_x[l_this_index];
        now_fsync_y = index_fsync_y[l_this_index];
        now_fsync_w = index_fsync_w[l_this_index];
        now_fsync_h = index_fsync_h[l_this_index];
    }

    return;
}

function clearSync()
{
    if(use_sync != 1)
    {
        return;
    }

    if(def_sync != "none")
    {
        out_buf = "<IMG SRC=\"" + def_sync + "\" WIDTH=\"" + sync_width + "\" HEIGHT=\"" + sync_height + "\" BORDER=\"0\">";
    }
    else
    {
        out_buf = "";
    }
    if(document.all)
    {
        document.all.syncL.innerHTML = out_buf;
    }
    now_sync = def_sync;

    out_buf = "";
    if(document.all)
    {
        document.all.syncFreeL.innerHTML = out_buf;
        document.all.syncFreeL.style.left = 0;
        document.all.syncFreeL.style.top = 0;
        document.all.syncFreeL.style.width = 0;
        document.all.syncFreeL.style.height = 0;
    }

    now_fsync = "none";
    now_fsync_x = 0;
    now_fsync_y = 0;
    now_fsync_w = 0;
    now_fsync_h = 0;

    return;
}

function dispCounter()
{
   this_time = Math.floor(document.video1.CurrentPosition);
   if(this_time < 0)
   {
       this_time = 0;
   }

    this_hour = Math.floor(this_time / 3600);
    this_min = Math.floor((this_time - (this_hour * 3600)) / 60);
    this_sec = this_time - (this_hour * 3600) - (this_min * 60);
    if(this_hour > 99)
    {
        this_hour = 99;
    }

   end_time = Math.floor(document.video1.Duration);
   if(end_time < 0)
   {
       end_time = 0;
   }

    end_hour = Math.floor(end_time / 3600);
    end_min = Math.floor((end_time - (end_hour * 3600)) / 60);
    end_sec = end_time - (end_hour * 3600) - (end_min * 60);
    if(end_hour > 99)
    {
        end_hour = 99;
    }

    if(this_hour < 10)
    {
        s_t_hour = "0" + this_hour;
    }
    else
    {
        s_t_hour = this_hour;
    }

   if(this_min < 10)
   {
       s_t_min = "0" + this_min;
   }
   else
   {
       s_t_min = this_min;
   }
   if(this_sec < 10)
   {
       s_t_sec = "0" + this_sec;
   }
   else
   {
       s_t_sec = this_sec;
   }

    if(end_hour < 10)
    {
        s_e_hour = "0" + end_hour;
    }
    else
    {
        s_e_hour = end_hour;
    }

   if(end_min < 10)
   {
       s_e_min = "0" + end_min;
   }
   else
   {

       s_e_min = end_min;
   }
   if(end_sec < 10)
   {
       s_e_sec = "0" + end_sec;
   }
   else
   {
       s_e_sec = end_sec;
   }

    out_buf = s_t_hour + ":" + s_t_min + ":" + s_t_sec + "/" + s_e_hour + ":" + s_e_min + ":" + s_e_sec;

    document.all.timeL.innerHTML = out_buf;
    document.all.timeL.style.width = 1;

    return;
}

function timerFunc()
{
    clearTimeout(play_timer);
    now_status = document.video1.PlayState;

    if(now_status == 0)
    {
        for(lop = (now_index + 1) ;lop < max_index ;lop++)
        {
            if(index_url[now_index] != index_url[lop])
            {
                now_index = lop;
                break;
            }
        }
        if(lop == max_index)
        {
            now_index = 0;
            document.video1.Open(index_url[now_index]);

            set_pos = index_sec[now_index];
            setPosition();
            clearSync();

            return;
        }

        document.video1.Open(index_url[now_index]);
        execPlay();

        set_pos = index_sec[now_index];
        setPosition();
    }

    play_timer = setTimeout("timerFunc()", 1000);
    return;
}

function skipGo()
{
    for(lop = (now_index + 1) ;lop < max_index ;lop++)
    {
        if(index_url[now_index] == index_url[lop])
        {
            l_pos = document.video1.CurrentPosition;
            if(l_pos < 0)
            {
                l_pos = 0;
            }
            if(l_pos < index_sec[lop])
            {
               if(document.video1.PlayState != 2)
               {
                   document.video1.FileName = index_url[lop];
                   execPlay();
               }
                set_pos = index_sec[lop];
                setPosition();

                break;
            }
        }
        else
        {
            now_index = lop;

            document.video1.FileName = index_url[now_index];
            execPlay();

            set_pos = index_sec[now_index];
            setPosition();

            break;
        }
    }
    if(lop == max_index)
    {
        return;
    }
    return;
}

function skipBack()
{
    l_index = now_index;
    l_pos = document.video1.CurrentPosition;
    if(l_pos < 0)
    {
        l_pos = 0;
    }
    if(l_pos < (index_sec[now_index] + 5) && now_index != 0)
    {
        for(lop = 0 ;lop < now_index ;lop++)
        {
            if(index_url[now_index] != index_url[lop])
            {
                if(index_url[l_index] != index_url[lop])
                {
                    l_index = lop;
                }
            }
        }

        document.video1.FileName = index_url[l_index];
        execPlay();

        set_pos = index_sec[now_index - 1];
        setPosition();

        now_index = l_index;

        return;
    }
    for(lop = (now_index + 1) ;lop < max_index ;lop++)
    {
        if(index_url[now_index] != index_url[lop])
        {
            break;
        }
        if(l_pos > (index_sec[lop] + 5))
        {
            l_index = lop;
        }
    }
   if(document.video1.PlayState != 2)
   {
       document.video1.FileName = index_url[l_index];
       execPlay();
   }
    set_pos = index_sec[l_index];
    setPosition();

    return;
}

function loadTimerFunc1()
{
    clearTimeout(load_timer1);
    execPlay();
}

function execPlay()
{
    clearTimeout(play_timer);

    if(use_loading)
    {
        if(document.video1.PlayState != 1)
        {
            document.all.waitL.style.visibility = "visible";
            document.all.playL.style.visibility = "hidden";
        }
    }
    if(document.video1.CurrentPosition == -1)
    {
        clearTimeout(load_timer1);
        load_timer1 = setTimeout("loadTimerFunc1()", 100);
        return;
    }
    if(document.video1.PlayState == 3)
    {
        clearTimeout(load_timer1);
        load_timer1 = setTimeout("loadTimerFunc1()", 100);
        return;
    }

    document.video1.Play();
    play_timer = setTimeout("timerFunc()", 10000);

    return;
}

function loadTimerFunc2()
{
    clearTimeout(load_timer2);
    setPosition();
}

function setPosition()
{
    if(document.video1.PlayState == 3)
    {
        clearTimeout(load_timer2);
        load_timer2 = setTimeout("loadTimerFunc2()", 100);
        return;
    }
    if(document.video1.CurrentPosition == -1)
    {
        clearTimeout(load_timer2);
        load_timer2 = setTimeout("loadTimerFunc2()", 100);
        return;
    }
    document.video1.CurrentPosition = set_pos;
    return;
}

function execStop()
{
    clearTimeout(play_timer);
    document.video1.Stop()

    set_pos = index_sec[now_index];
    setPosition();

    return;
}

function execPause()
{
    clearTimeout(play_timer);
    document.video1.Pause();

    return;
}

function skipIndex(l_index)
{
   l_start_index = l_index;
   lop = l_index;

   while(1)
   {
       if(index_url[l_index] == index_url[lop])
       {
           l_start_index = lop;
       }
       else
       {
           break;
       }
       if(lop == 0)
       {
           break;
       }
       lop--;
   }

   now_index = l_start_index;

   document.video1.FileName = index_url[l_index];
   execPlay();

    set_pos = index_sec[l_index];
    setPosition();

    return;
}

function upVol()
{
    now_vol = document.video1.Volume;
    now_vol = now_vol + 500;
    if(now_vol > 0)
    {
        now_vol = 0;
    }
    document.video1.Volume = now_vol;

    return;
}
function downVol()
{
    now_vol = document.video1.Volume;
    now_vol = now_vol - 500;

    if(now_vol < -10000)
    {
        now_vol = -10000;
    }
    document.video1.Volume = now_vol;

    return;
}
function muteVol()
{
    if(document.video1.Mute)
    {
        document.video1.Mute = false;
    }
    else
    {
        document.video1.Mute = true;
    }
    return;
}
