var oldBackground = "right center";
$(document).ready(function() {

    $('.nav-link').mouseover(function() {
        oldBackground = $(this).parent().css('background-position-x');
        $('.active').css('background-position', '-50px')
        //$('li.active').addclass('no-bg');
        $(this).parent().css('background-position', 'right center');
    });
    $('.nav-link').mouseout(function() {
        $('.active').css('background-position', 'right')
        $(this).parent().css('background-position', oldBackground);
    });


    $('#selector .option .label').mouseover(function() {
        //  Highlight the indicator
        $(this).prev().attr('oldBG', $(this).prev().css('background-color'));
        $(this).prev().css('background-color', '#bf3028');
    });
    $('#selector .option .label').mouseout(function() {
        $(this).prev().css('background-color', $(this).prev().attr('oldBG'));
    });
    $('#selector .option .label').click(function() {
        //  Highlight the indicator
        $(this).prev().attr('oldBG', '#bf3028');
        $('#Course').val($(this).attr('title'));
    });

    $('.appointmentLink').click(function(e) {
        e.preventDefault();
        $('.booking-form').show('slow');
    });

    $('#book-send').click(function(e) {
        e.preventDefault();
        $('.prompted').each(function(){
            var $this = $(this);
            if ($this.val() === $this.attr('prompt')) {
                $this.val('');
            }
        });

        if ($('#Course').val().length < 3) {
            alert('Please select a course');
            setPrompts();
            return false;
        }
        if ($('#Time').val().length < 3) {
            alert('Please indicate you prefered time');
            setPrompts();
            return false;
        }
        if ($('#Date').val().length < 3) {
            alert('Please indicate you prefered date');
            setPrompts();
            return false;
        }
        if ($('#Area').val().length < 3) {
            alert('Please indicate you prefered location');
            setPrompts();
            return false;
        }
        if ($('#Name').val().length < 3) {
            alert('Please enter your name');
            setPrompts();
            return false;
        }
        if ($('#Email').val().length < 3) {
            alert('Please enter your email address');
            setPrompts();
            return false;
        }
        if ($('#Phone').val().length < 3) {
            alert('Please enter aphone number we can contact you on');
            setPrompts();
            return false;
        }

        $('#booking-form').submit();

    });

    $('.booking-form').hide();
    $('#Course').val('');

    $('.prompted').each(function() {
        var $this = $(this);
        if ($this.val() === '') {
            $this.val($this.attr('prompt'));
        }
        $this.focus(function() {
            if ($this.val() === $this.attr('prompt')) {
                $this.val('');
            }
        });
        $this.blur(function() {
            if ($this.val() === '') {
                $this.val($this.attr('prompt'));
            }
        });
    });


});

function setPrompts()
{
    $('.prompted').each(function() {
        var $this = $(this);
        if ($this.val() === '') {
            $this.val($this.attr('prompt'));
        }
    });
}


