<!doctype html>
<html lang="en">
<head>
    <title>Xibo Open Source Digital Signage</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width={{ viewPortWidth }}" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <!-- Copyright 2006-2014 Daniel Garner. Part of the Xibo Open Source Digital Signage Solution. Released under the AGPLv3 or later. -->
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            font-family: sans-serif, Arial, Verdana, "Trebuchet MS";
        }

        h1, h2, h3, h4, p {
            margin-top: 0;
        }
    </style>
    {{ head|raw }}
    <style type="text/css">
        .flip-clock-wrapper {
            text-align: center;
            position: relative;
            margin: 0;
        }
    </style>
</head>
<!--[if lt IE 7 ]><body class="ie6"><![endif]-->
<!--[if IE 7 ]><body class="ie7"><![endif]-->
<!--[if IE 8 ]><body class="ie8"><![endif]-->
<!--[if IE 9 ]><body class="ie9"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><body><!--<![endif]-->
<div id="clock"></div>
{{ body|raw }}
</body>
{{ javaScript|raw }}
<script type="text/javascript">

    function getTimeRemaining(endtime) {
        var t = Date.parse(endtime) - Date.parse(new Date());
        var seconds = Math.floor( (t/1000) % 60 );
        var minutes = Math.floor( (t/1000/60) % 60 );
        var hours = Math.floor( (t/(1000*60*60)) % 24 );
        var days = Math.floor( t/(1000*60*60*24) );
        return {
            'total': t,
            'days': days,
            'hours': hours,
            'minutes': minutes,
            'seconds': seconds
        };
    }

    var clock;
    var offset = "{{ offset }}";

    $(document).ready(function() {
        // Show Seconds: {{ showSeconds }}
        // Offset: {{ offset }}
        var options = {{ options|raw }};
        var width = options.previewWidth;
        var height = options.previewHeight;

        if (width == 0 || height == 0) {
            width = $(window).width();
            height = $(window).height();
        }

        var clockFace = "{{ clockFace }}";
        var showSeconds = {{ showSeconds }};
        var clock_width = 460;

        // Flip clock is always the same size
        if (clockFace === "DailyCounter")
            clock_width = 620;

        // If we are a clock, then reduce the width to fit without the seconds if appropriate
        if (showSeconds === 0 && (clockFace === "TwelveHourClock" || clockFace === 'TwentyFourHourClock'))
            clock_width = 300;

        // Calculate the width ratio between the actual width and the clock_width
        var ratio = width / clock_width;

        // What IE are we?
        if ($("body").hasClass('ie7') || $("body").hasClass('ie8')) {
            $("#clock").css({
                "width": clock_width + "px",
                "filter": "progid:DXImageTransform.Microsoft.Matrix(M11=" + ratio + ", M12=0, M21=0, M22=" + ratio + ", SizingMethod='auto expand'"
            });
        }
        else {
            $("#clock").css({
                "width": clock_width + "px",
                "transform": "scale(" + ratio + ")",
                "transform-origin": "0 0"
            });
        }

        if (clockFace === "TwelveHourClock" || clockFace === "TwentyFourHourClock") {
            clock = $('#clock').FlipClock({
                clockFace: '{{ clockFace }}',
                showSeconds: (showSeconds === 1)
            });

            clock.setTime(clock.getTime() + (offset * 60 * 1000));
        } else {
            var duration;
            if (isNaN(offset)) {
                duration = getTimeRemaining(offset).total / 1000;
            } else {
                duration = {{ duration }};
            }

            clock = $('#clock').FlipClock(duration, {
                clockFace: '{{ clockFace }}',
                showSeconds: (showSeconds === 1),
                countdown: true
            });
        }
    });
</script>
</html>
{{ controlMeta|raw }}
