﻿Cufon.replace('h1', { fontFamily: 'Century', hover: true });
Cufon.replace('.panelhead', { fontFamily: 'Century', hover: true });
Cufon.replace('.panelsubhead', { fontFamily: 'Century', hover: true });
Cufon.replace('.subtext', { fontFamily: 'Century', hover: true }); 

$(document).ready(function () {

    $(".contact-click").click(function () {
        if ($("#contactContainer").is(":hidden")) {
            showContactForm();
        }
        else {
            hideContactForm();
        }
        return false;
    });

    $(".modalOverlay").click(function () {
        hideContactForm();
    });

    setTimeout(function () {
        var options = { direction: "up" };
        $("#siteNavigation").show("drop", options, 300);
    }, 500);

    bindContactFieldEvents();

    $(window).resize(function () {
        $(".modalOverlay").height("100%");
        $(".modalOverlay").width("100%");
    });

});

function showContactForm() {     
        loadContactForm();
    }

function loadContactForm() {
    $("#contactContainer").fadeIn("slow");
    $(".modalOverlay").show();
    $("#contactFormHolder .textbox:first").focus();
}

function hideContactForm() {
    $("#contactContainer").fadeOut("slow");
    $(".modalOverlay").hide();
}

function submitContactForm() {

    var text = $("#contactButton").html();

    $("#contactButton").attr('disabled', true);
    $("#contactButton").html("Sending...");

    $.ajax({
        type: "POST",
        url: "/ContactUs/ContactFormPartial",
        data: $("#contactForm").serialize(),
        success: function (data) {
            if (data != "") {
                $("#contactContainer").html(data);
                bindContactFieldEvents();
            }
        }
    });
}

function bindContactFieldEvents() {

    $("#contactFormHolder .textbox").keydown(function () {
        $(this).next(".textoverlay").hide();
    });

    $("#contactFormHolder .textbox").focusin(function () {
        $(this).parent("div").addClass("focus");
        $(this).removeClass("input-validation-error");
    });

    $("#contactFormHolder .textbox").focusout(function () {
        if ($(this).val() == null || $(this).val().length == 0)
            $(this).next("#contactForm .textoverlay").show();
        $(this).parent("div").removeClass("focus");
    });

    $("#contactFormHolder .textoverlay").click(function () {
        $(this).prev(".textbox").focus();
    });

    $("#contactButton").click(function () {
        submitContactForm();
    });

    $("#contactButton").mouseenter(function () {
        $(this).addClass("button-hover");
        $(this).removeClass("button-standard");
    });

    $("#contactButton").mouseleave(function () {
        $(this).addClass("button-standard");
        $(this).removeClass("button-hover");
    });

    $("#contactButton").mousedown(function () {
        $(this).addClass("button-down");
        $(this).removeClass("button-hover");
        $(this).removeClass("button-standard");
    });

    $("#contactButton").mouseup(function () {
        $(this).addClass("button-hover");
        $(this).removeClass("button-down");
        $(this).removeClass("button-standard");
    });

    $(".close-contact-form").click(function () {
        hideContactForm();
        return false;
    });

    $("#contactFormHolder .textbox").each(function () {
        if ($(this).val() != null && $(this).val().length > 0)
            $(this).next(".textoverlay").hide();
    });
}

function unbindContactFieldEvents() {
    $("#contactFormHolder .textbox").unbind("keydown");
    $("#contactFormHolder .textbox").unbind("focusin");
    $("#contactFormHolder .textbox").unbind("focusout");
    $("#contactFormHolder .textoverlay").unbind("click");
}

