﻿
var opts;

(function($) {
    var defaults = {
        date: new Date(),
        countdownselector: '.container',
        city: 'City',
        reservationselector: '.reservation',
        hasreservation: true,
        reservationlink: '#',
        language: 'fr'
    };
    $.fn.openrestaurant = function(options) {
        opts = jQuery.extend(defaults, options);

        return this.each(function() {
            $this = jQuery(this);
            $countdown = $this.find(opts.countdownselector);
            $reservation = $this.find(opts.reservationselector);

            jQuery.countdown.setDefaults(jQuery.countdown.regional['fr']);

            $countdown.countdown({
                until: opts.date,
                layout: '<div class="ouverture">Ouverture de notre 2e restaurant...<span class="nom-restaurant">&agrave; ' + opts.city +
                    ' !</span><span class="jours">{dl}-{d<}{dn}{d>}</span></div>' +
                    //'	<div class="heure">{h10}{h1}:{m10}{m1}:{s10}{s1}</div>' +
			        '</div>',
                compact: true,
                format: 'DHMS' /*'YODHMS'*/,
                onExpiry: expiryCountdown,
                onTick: tickCountdown
            });
            $countdown.countdown(jQuery.countdown.regional[opts.language]);

        });

    };
})(jQuery);

var initPeriods = 0;

function tickCountdown(periods) {
    if (initPeriods == 1)
        $this.slideDown('slow');
    if (initPeriods == 2) {
        if (opts.hasreservation) {
            if ($reservation[0].tagName.toUpperCase() == 'A') {
                $reservation.attr('href', opts.reservationlink);
                $reservation.fadeIn(400);
            }
        }
    }
    if (initPeriods <= 2)
        initPeriods++;
}

function expiryCountdown() {
    $this.fadeOut('slow');
}

function openPopOuverture(){$('#popOuvertureRestaurant').show();return false;}
function closePopOuverture(){$('#popOuvertureRestaurant').hide();;return false;}
