﻿$(function() {

    $("[id$='txtTourDate']").datepicker({
        beforeShowDay: function(date) {

            var day = date.getDay()
            if (day == 0 || day == 1 || day == 2 || day == 3) {
                return [false, '', 'Tours are only given on Thursday, Friday, or Saturday'];
            }
            else {
                return [true, '', ''];

            }
        },
        onSelect: function(dateText, inst) {
            $("[id$='txtTourDate']").val(dateText);
            $("[id$='HiddenTourDate']").val(dateText);

        }

    });

    $('#clear').click(function() {

        $("#contact_form input.edit,textarea,#contact_form input.full, [id$='HiddenTourDate']").val('');
    });

    $('#YearsAccordion').accordion({
        collapsible: false,
        autoHeight: false
    });

    $('.ConcoursAccordion').accordion({
        collapsible: false,
        autoHeight: false
    });

    //When they click the year header load the first concours
    $('a.Year').click(function() {
        //get the year
        var year = $(this).text();
        //if the year header was active ignore and return        
        if ($("#h" + year + ".ui-state-active").length > 0) {
            return;
        }

        //set up a delay to show the first concours 
        //(without delay it doesn't expand all the way. I don't know why)
        var delay = function() { DoThis(year); };
        setTimeout(delay, 50);
    });

    function DoThis(year) {
        $('div#' + year + ' a.Concours:first').click();
    }

});                /*End of JQuery Ready Function */