$(document).ready(function() {

    var time_now = new Date();
    var t_year = time_now.getFullYear(),
        t_month = time_now.getMonth(),
        t_day = time_now.getDate(),
        t_weekday = time_now.getDay();

    var basic_date = new Date(t_year + '-' + (t_month + 1) + '-' + t_day);
    var after_10_hours = new Date(basic_date.getTime() + 10 * 60 * 60 * 1000);

    function show_opening_hours() {
        $('.opening-hours').each(function (el) {
            var $el = $(this),
                location_id = $el.data('location'),
                $btn = $('#oh-status-' + location_id),
                $ul = $('ul', $el),
                $open_status = $('.for-' + location_id);

            $('li', $ul).each(function (i) {
                var $li = $(this),
                    weekday = $li.data("weekday");

                if (weekday == t_weekday) {
                    $btn.html($li.html());
                    $li.addClass('active');

                    if ($('.oh-hours', $li).length > 0) {
                        var open_text = 'CLOSED',
                            open_class = 'closed';
                        $('.oh-hours', $li).each(function (i) {
                            var start = new Date(basic_date.getTime() + parseInt($(this).data('start'))),
                                end = new Date(basic_date.getTime() + parseInt($(this).data('end')));


                            if (time_now.getTime() >= start.getTime() &&
                                time_now.getTime() < end.getTime()) {
                                open_text = 'OPEN';
                                open_class = 'open';
                            }

                        });

                        $open_status.addClass(open_class).text(open_text);
                    }
                }

            });


        });
    }
    show_opening_hours();
    window.setInterval(show_opening_hours, 1000);

});