// Check that the page has loaded
$(document).ready(function () {

    // Add lightbox
    $('A.lightbox').lightBox();

    // Gallery lightbox
    $('A.lightbox1').lightBox();
    $('A.lightbox2').lightBox();
    $('A.lightbox3').lightBox();
    $('A.lightbox4').lightBox();
    $('A.lightbox5').lightBox();
    $('A.lightbox6').lightBox();
    $('A.lightbox7').lightBox();

    // Floorplan lightbox
    $('.floorplan1 A').lightBox();
    $('.floorplan2 A').lightBox();
    $('.floorplan3 A').lightBox();
    $('.floorplan4 A').lightBox();
    $('.floorplan5 A').lightBox();
    $('.floorplan6 A').lightBox();
    $('.floorplan7 A').lightBox();

    // GALLERY
    $('.gallery .thumbnail').click(function () {

        // Get which thumnail clicked
        var href = $(this).attr('href');

        // Move correct image to top of stack        
        $('.gallery .mainImgContainer A[href="' + href + '"]').prependTo($(this).parents('.gallery').find('.mainImgContainer'));

        return false

    });

    // ACCOMMODATION SWITCHER
    $('.accommoationTabs A').click(function () {

        // Close all accom info
        $('.accommotationInfo').hide();

        // Open correct accom info
        if ($(this).hasClass('aptType1')) {
            $('#aptType1').show();
        } else if ($(this).hasClass('aptType2')) {
            $('#aptType2').show();
        } else if ($(this).hasClass('aptType3')) {
            $('#aptType3').show();
        } else if ($(this).hasClass('aptType4')) {
            $('#aptType4').show();
        } else if ($(this).hasClass('aptType5')) {
            $('#aptType5').show();
        } else if ($(this).hasClass('aptType6')) {
            $('#aptType6').show();
        } else if ($(this).hasClass('aptType7')) {
            $('#aptType7').show();
        }

        // Remove selected
        $('.accommoationTabs LI').removeClass('selected');

        // Add selected to correct tab
        $(this).parent('LI').addClass('selected');

        return false;

    });

    // Add tab hover for IE6
    if ($('BODY').hasClass('browserIE6')) {
        $('.accommoationTabs A').hover(
          function () {
              $(this).parent('LI').addClass('over');
          },
          function () {
              $(this).parent('LI').removeClass('over');
          }
        );
    }


    // DATE PICKER
    $('.datePick INPUT').datepick({ showOn: 'focus', yearRange: '-1:+4', firstDay: '6', dateFormat: 'dd/mm/yy' });

    // ROW STRIPING
    $(".accomodationTable tbody tr:nth-child(odd)").addClass("odd");


    //$('TABLE TR:odd').addClass('odd');


    $("form[action$='Feedback']").submit(function () {

        var emailAddress = $("[id=contact_email]").val();
        var myregexp = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\b/i;
        if (!emailAddress.match(myregexp)) {
            alert('Please enter a valid email address');
            return false;
        }

        var values = $("form[action$='Feedback']").serialize()
        $.ajax({
            url: '/Contact/Feedback',
            type: 'POST',
            data: values,
            traditional: true,
            success: function (response) {
                $("form")[0].reset();
                alert("Thank you for contacting The Lodge Morzine about availability, your request has been sent. You will be contacted shortly.");
            }
        });
        return false;
    });


});
