<html>
<head>
<title><i18n>MythTV System Overview</i18n></title>
</head>
<body>

    <div style="margin: 0 auto; width:660px;" class="pressed">
        <h2><i18n>Last Ten Recordings</i18n></h2>
    </div>

    <div style="margin: 0 auto;" id="lasttencontainer">
        <div style="padding: 10px 0px;" id="lasttencontent">
<%
            var oDvr = new Dvr();
            var list = oDvr.GetRecordedList( true, 0, 10 );
            for (var nIdx=0; nIdx < list.Programs.length; nIdx++)
            {
                var program = list.Programs[ nIdx ];
                var title = '';
                if (program.SubTitle == '')
                    title = program.Title;
                else if (program.Episode > 0)
                    title = program.Title + " " + program.Season + "x" + pad(program.Episode) + " (" + program.SubTitle + ")";
                else
                    title = program.Title + " (" + program.SubTitle + ")";

                var month_names = new Array();
                month_names[month_names.length] = "<i18n>January</i18n>";
                month_names[month_names.length] = "<i18n>February</i18n>";
                month_names[month_names.length] = "<i18n>March</i18n>";
                month_names[month_names.length] = "<i18n>April</i18n>";
                month_names[month_names.length] = "<i18n>May</i18n>";
                month_names[month_names.length] = "<i18n>June</i18n>";
                month_names[month_names.length] = "<i18n>July</i18n>";
                month_names[month_names.length] = "<i18n>August</i18n>";
                month_names[month_names.length] = "<i18n>September</i18n>";
                month_names[month_names.length] = "<i18n>October</i18n>";
                month_names[month_names.length] = "<i18n>November</i18n>";
                month_names[month_names.length] = "<i18n>December</i18n>";

                var day_names = new Array();
                day_names[day_names.length] = "<i18n>Sunday</i18n>";
                day_names[day_names.length] = "<i18n>Monday</i18n>";
                day_names[day_names.length] = "<i18n>Tuesday</i18n>";
                day_names[day_names.length] = "<i18n>Wednesday</i18n>";
                day_names[day_names.length] = "<i18n>Thursday</i18n>";
                day_names[day_names.length] = "<i18n>Friday</i18n>";
                day_names[day_names.length] = "<i18n>Saturday</i18n>";

                function pad(n)
                {
                    return n<10 ? '0'+n : n
                }

                var startTime = program.StartTime.getHours() + ":" +
                                pad(program.StartTime.getMinutes());
                var desc = formatStr('<i18n>%1<br>Recorded %2, %3 %4 at %5.</i18n>',
                    program.Description, day_names[program.StartTime.getDay()],
                    month_names[program.StartTime.getMonth()],
                    program.StartTime.getDate(), startTime);
%>
                <img title="<%= title %>" alt="<%= desc %>" src="/Content/GetPreviewImage?ChanId=<%=program.Channel.ChanId %>&Height=300&StartTime=<%=UTCDateString( program.Recording.StartTs ) %>"/>
<%
            } 
%>
        </div>
    <div>

    <div style="margin: 0 auto; width:660px;" class="pressed">
        <h2><i18n>Current Tuner Activity</i18n></h2>
    </div>

    <div style="padding: 10px 0px;" id="encodercontainer">
        <div class="blackbox galleria-container indented" style="width:680px; padding: 0px 10px 0px 10px;" id="encodercontent">
        <ul>
<%
            var oDvr = new Dvr();
            var encoderlist = oDvr.GetEncoderList();
            for (var nIdx=0; nIdx < encoderlist.Encoders.length; nIdx++)
            {
                var encoder = encoderlist.Encoders[ nIdx ];
                var statestring = '';
                var state = encoder.State;
                switch(state)
                {
                    case 1:
                        var recording = encoder.Recording;
                        statestring = formatStr('<i18n>Encoder %1 is currently watching "%2" on Live TV.</i18n>',
                            encoder.Id, recording.Title);
                        break;
                    case 6:
                        var recording = encoder.Recording;
                        statestring = formatStr('<i18n>Encoder %1 is currently recording "%2."  This program is being viewed.</i18n>',
                            encoder.Id, recording.Title);
                        break;
                    case 7:
                        var recording = encoder.Recording;
                        var endtime = recording.EndTime.getHours() + ':' + pad(recording.EndTime.getMinutes());
                        statestring = formatStr('<i18n>Encoder %1 is currently recording "%2."  This recording will end at %3.</i18n>',
                            encoder.Id, recording.Title, endtime);
                        break;
                    default:
                        statestring = formatStr('<i18n>Encoder %1 is currently idle.</i18n>',
                            encoder.Id);
                        break;
                }

                os.writeln("<li>" + statestring + "</li>");
            }
%>

        </ul>
        </div>
    <div>

</body>
</html>

<%
function ISODateString(d)
{
  function pad(n)
  {
    return n<10 ? '0'+n : n
  }
  return d.getFullYear()+'-'
   + pad(d.getMonth()+1)+'-'
   + pad(d.getDate())+'T'
   + pad(d.getHours())+':'
   + pad(d.getMinutes())+':'
   + pad(d.getSeconds())+'Z'
}
%>

<%
function UTCDateString(d)
{
  function pad(n)
  {
    return n<10 ? '0'+n : n
  }
  return d.getUTCFullYear()+'-'
   + pad(d.getUTCMonth()+1)+'-'
   + pad(d.getUTCDate())+'T'
   + pad(d.getUTCHours())+':'
   + pad(d.getUTCMinutes())+':'
   + pad(d.getUTCSeconds())+'Z'
}
%>

<script src="/js/galleria/galleria-1.2.3.min.js"></script>

<script type="text/javascript">
    $(document).ready(function($){
        Galleria.loadTheme('/js/galleria/themes/classic/galleria.classic.min.js');
        $("#lasttencontent").galleria({
            width: 700,
            height: 350,
            autoplay: 7000,
            imageCrop: true,
            showInfo: true
        });
    });
</script>
