//This allows for mouseOver event on hovered buttons, and should stop them from recurring until animation has completed
$(function () {
    $(".menu a").hover(function () {
        if ($(this).hasClass('animated')) {
            $(this).next('em').stop(true, true).animate({
                opacity: "show",
                top: "-85"
            }, "slow")
        }
    }, function () {
        $(this).addClass('animated').next('em').animate({
            opacity: "hide",
            top: "-100"
        }, "fast")
});
	});

//This allows for login panel to slide up and down
$(document).ready(function () {

    // Expand Panel
    $("#open").click(function () {
        $("div#panel").slideDown("slow");

    });

    // Collapse Panel
    $("#close").click(function () {
        $("div#panel").slideUp("slow");
    });

    // Switch buttons from "Log In | Register" to "Close Panel" on click
    $("#toggle a").click(function () {
        $("#toggle a").toggle();
    });

});

//Submits form with out reset, adds field errors, adds focus colors
$(function () {
    $('.error').hide();
    $('input.text-input').css({
        backgroundColor: "#9fb39a"
    });
    $('input.text-input').focus(function () {
        $(this).css({
            backgroundColor: "#dff5d9"
        });
    });
    $('input.text-input').blur(function () {
        $(this).css({
            backgroundColor: "#4e5e4a"
        });
    });

    $('.error').hide();
    $('textarea.text-area').css({
        backgroundColor: "#9fb39a"
    });
    $('textarea.text-area').focus(function () {
        $(this).css({
            backgroundColor: "#dff5d9"
        });
    });
    $('textarea.text-area').blur(function () {
        $(this).css({
            backgroundColor: "#4e5e4a"
        });
    });

    $(".button").click(function () {
        // validate and process form
        // first hide any error messages
        $('.error').hide();

        var name = $("input#name").val();
        if (name == "") {
            $("label#name_error").show();
            $("input#name").focus();
            return false;
        }
        var phone = $("input#phone").val();
        if (phone == "") {
            $("label#phone_error").show();
            $("input#phone").focus();
            return false;
        }
        var email_quote = $("input#email_quote").val();
        if (email_quote == "") {
            $("label#email_error").show();
            $("input#email_quote").focus();
            return false;
        }

        var info = $("textarea#info").val();
        if (info == "") {
            $("label#info_error").show();
            $("textarea#info").focus();
            return false;
        }

        var dataString = 'name=' + name + '&email_quote=' + email_quote + '&phone=' + phone + 'info=' + info;
        //alert (dataString);return false;
        $.ajax({
            type: "POST",
            url: "/process.php",
            data: dataString,
            success: function () {
                $('#contact_form').html("<div id='message'></div>");
                $('#message').html("<div class='getaquote'><h2 style='margin-top:5px;'>Contact Form Submitted!</h2></div>").append("<p>We will review your quote, and then contact you within 24 hours. Thank you for your time.</p>").hide().fadeIn(1500, function () {
                    $('#message').append("<img id='checkmark' src='/images/check.png' />");
                });
            }
        });
        return false;
    });
});
runOnLoad(function () {
    $("input#name").select().focus();
});
