var LEBISTRO = window.LEBISTRO || {};

LEBISTRO.Default = function() {
    var object = {
        init: function() {
            $('#navigation a, a.navigation').click(function(e) {
                var href = $(this).attr('href');
                $.scrollTo(href, {'duration': 1000});
                e.preventDefault();
                e.stopPropagation();
            });

            $('#slider').nivoSlider({
                pauseTime: 5000,
                controlNav: false,
                directionNav: false,
                effect: 'fade',
                animSpeed: 1000
            });

            $('#contact input[type=text], #contact textarea').each(function() {
                var label = $(this).prev('label');
                label.hide();

                var text = $(this).val();
                if (text == null || text.length == 0) {
                    $(this).val(label.text());
                } else {
                    $(this).addClass('dirty');
                }

                $(this).change(function() {
                    $(this).addClass('dirty');

                }).click(function() {
                    if (!$(this).hasClass('dirty')) {
                        $(this).select();
                    }
                })
            });

            $('#contact input.send').click(function() {
                $('#contact input:not(.dirty), #contact textarea:not(.dirty)').val('');
            });

            var count = 0;
            $('#contact div.error-message').each(function() {
                var message = $(this).text();
                $(this).hide();

                var field = $(this).prev('input, textarea');
                field.removeClass('dirty').css({'background': '#e79292'}).val(message);
                if (count == 0) {
                    field.select();
                }
                count++;
            });

            $('.flash-error, .flash-warning, .flash-success').hide().fadeIn(3000, function() {
                $(this).delay(1000).fadeOut(1000);
            });
        }
    }

    return object;
}();

$(document).ready(function() {
    LEBISTRO.Default.init();
});

