$(document).ready(function() {


    /*
     * MAIN PIXELMENU REGISTRATION */

    $('#menu').pixelMenu({
        moreText: '',
        animationSpeed: window.menuAnimSpeed,
        animationType: window.menuAnimType
    });


    /*
     * Height fix */
    
    /*

    var contentHeight = $('#content .main-col').height();
    var sidebarHeight = $('#content .sidebar').height();

    if ( contentHeight > sidebarHeight ) {
        $('#root .sidebar').height(contentHeight);
        $('#root .main-col').height(contentHeight);
    } else {
        $('#root .sidebar').height(sidebarHeight);
        $('#root .main-col').height(sidebarHeight);
    }
    */


    $('ol.children > li:last-child, ol.category-list > li:last-child').addClass('last');

    /*
     * IMAGE HOVER EFFECT
     * ==================================================== */

    $("#content a[rel^='prettyPhoto'], #content .gallery dl dt a").hover(
        function() {
            $(this).find('img').stop().animate({
                opacity: 0.5
            }, 300);
            $(this).find('.image-zoom').css('top', '-10px').animate({
                top: '0px'
            }, 500);
        },
        function() {
            $(this).find('img').stop().animate({
                opacity: 1
            }, 300);
            $(this).find('.image-zoom').animate({
                top: '-10px'
            }, 500);
        });        

    /*
     * ADDING SOME CLASSES
     * ======================================================= */

    $('#content .widget ul li:last-child').addClass('last');

    $('#bottom-sidebar .widget').each(function(index) {
        if ( index % 3 == 0 && index > 0 ) {
            $(this).addClass('last');
        }
    });

    $('#bottom-sidebar .widget ul li:last-child').addClass('last');
    $('#bottom-sidebar .widget blockquote:last').addClass('last');
    if ( typeof(isResButtonUnstyled) == 'undefined' || isResButtonUnstyled == 'false' ) {
        $('#menu ul#main-menu li:last-child:last').addClass('reservations');
    }
    $('#footer .widget:last-child').addClass('last');
    $('#submit').hover(
        function() {
            $(this).css('backgroundColor', '#a15749');
        },
        function() {
            $(this).css('backgroundColor', '#63261a');
        }
        );

    $('#content .sidebar-data .widget:last-child').addClass('last');


    /*
     * IMAGE GALLERY INITIALIZATION
     * ============================================================== */

    $("a[rel^='prettyPhoto']").prettyPhoto({
        theme: 'facebook',
        overlay_gallery: false
    });
    $("#content .gallery dl dt a").prettyPhoto({
        theme: 'facebook',
        overlay_gallery: false
    });

    $('#content-center .ngg-gallery-thumbnail-box').each(function(i) {
        var noPerRow = window.GAL_NO_PER_ROW ? window.GAL_NO_PER_ROW : 3;
        if ( (i + 1) % noPerRow == 0 ) {
            $(this).addClass('last');
        }
    });

    $('#content-center .ngg-galleryoverview .ngg-gallery-thumbnail a img').each(function(i) {
        var title = $(this).attr('title');
        $(this).parent().append('<span class="meta"><b>'+ title +'</b></span>');
    });

    $('#content-center .ngg-navigation a.next').html('&raquo;');
    $('#content-center .ngg-navigation a.prev').html('&laquo;');


    /*
     * DATEPICKER INITIALIZATION
     * ================================================================ */

    $("#date").datepicker({
        showOn: 'button',
        buttonImage: templateDir + '/images/calendar.gif',
        buttonImageOnly: true,
        showAnim: 'fadeIn',
        dateFormat: resDateFormat
    });


    /*
     * FORM ACTION
     * ================================================================ */

    $("#clear-form").click(function() {
        $("#res_name").val('');
        $("#email").val('');
        $("#subject").val('');
        $("#message").val('');
        $("#notes").val('');
        $("#time_hh").val(-1);
        $("#time_mm").val(-1);
        $("#meal_type").val(-1);
        $("#date").val('');
        $("#phone").val('');
        $("#party_size").val('');
        return false;
    });


    /*
     * SEARCH BAR
     * ================================================================= */

    $("#s").click(function() {
        $("#s").val('');
    });

    $("#s").focusout(function() {
        if ($("#s").val() == '' ) {
            $("#s").val('Search ...');
        }
    });
    $('#search-but').click(function() {
        $('#search-form').submit();
    });


    /*
     * RESERVATIONS FORM
     * ================================================================= */

    $('#send-reservation').click(function(e) {
        e.preventDefault();
        $('#reservations-form').submit();
    });


    /*
     * CONTACT FORM
     * ================================================================= */

    $('#contact_email').focusout(function() {
        $.post(MyAjax.ajaxurl, {
            action : 'rest_check_email',
            contact_email: $(this).val()
        }, function(response) {
            if ( 'valid' == response ) {
                $('#contact_email').attr('class', 'xmedium valid');
            } else {
                $('#contact_email').attr('class', 'xmedium invalid');
            }
        })
    });
    $('#send-email').click(function(e) {
        e.preventDefault();
        $('#contact-form').submit();
    });


});
