﻿function sendAnotherMessage(){
    $("#contactFormMessage").fadeOut().html("Wow, you like us that much. Ok...send another message.").fadeIn();
    $("#contactForm").slideToggle();
}

$(document).ready(function() {
    $('input[title!=""]').hint();
    $('textarea[title!=""]').hint();
    $("#contactForm").validate({
        errorClass: "invalid",
        errorLabelContainer: "#contactFormErrors",
        wrapper: "li",
        submitHandler: function(form) {
                            $("#submit").slideToggle();
                            $("#sendingMessage").slideToggle();
                            $("#contactFormMessage").fadeOut().html("");
   	                        $.ajax({
                                type: 'POST',
                                url: $('#contactForm').attr("action"),
                                data: $('#contactForm').serialize(),
                                success:    function(responseText) {
                                                var message = responseText == "false" ? "Invalid request." : responseText;
                                                $("#contactFormMessage").fadeOut().html(message).fadeIn();
                                                $("#submit").slideToggle();
                                                if(responseText != "false"){
                                                    $("input").val("");
                                                    $("textarea").val("");
                                                    $("#contactForm").slideToggle();
                                                }
                                            }
                            });
                            },
        rules: {
            nameInput: {
                required: true,
                minlength: 2
            },
            emailInput: {
                required: true,
                email: true
            },
            message: {
                required: true,
                minlength: 2
            }
        },
        messages: {
            nameInput: {
                required: "- We would like to know your name.",
                minlength: jQuery.format("You need to use at least {0} characters for your name.")
            },
            emailInput: {
                required: "- We need a valid email address so we can pong your ping."
            },
            message: {
                required: "- Let us know something. Type a message."
            }
        }
    });
});

$(function() {
    $("button[rel]").overlay();
    $(".projectRollout").hover(	function() {
								  $("#hoverBox").animate({ marginTop: "0px" }, 600);
								},
								function() {
								  $("#hoverBox").animate({ marginTop: "212px" }, 800);
								}
								)
});

jQuery.fn.hint = function(blurClass) {
    if (!blurClass) {
        blurClass = 'blur';
    }

    return this.each(function() {
        // get jQuery version of 'this'
        var $input = jQuery(this),

        // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = jQuery(this.form),
      $win = jQuery(window);

        function remove() {
            if ($input.val() === title && $input.hasClass(blurClass)) {
                $input.val('').removeClass(blurClass);
            }
        }

        // only apply logic if the element has the attribute
        if (title) {
            // on blur, set value to title attr if text is blank
            $input.blur(function() {
                if (this.value === '') {
                    $input.val(title).addClass(blurClass);
                }
            }).focus(remove).blur(); // now change all inputs to title

            // clear the pre-defined text when form is submitted
            $form.submit(remove);
            $win.unload(remove); // handles Firefox's autocomplete
        }
    });
};
