$(document).ready(function () {
    $(".login").click(function (e) {
        e.preventDefault();
        $(".modal").css("margin-left", "-215px");
    });
    $(".closelogin").click(function (e) {
        e.preventDefault();
        $(".modal").css("margin-left", "-10000px");
    });
    var i = 0;
    $("#submit").click(function (e) {
        e.preventDefault();
        if ($("#name").val() == "") {
            alert("Please leave us your name.");
            $("#name").css("border-color", "#FF0000");
        } else if ($("#email").val() == "") {
            alert("Please leave us your email address.");
            $("#name").css("border-color", "");
            $("#email").css("border-color", "#FF0000");
        } else {
            var responseBox = $("#output");
            var currentDate = new Date()
            var day = currentDate.getDate()
            var month = currentDate.getMonth()
            var year = currentDate.getFullYear()
            $.ajax({
                type: "POST", url: 'process.php', data: "name=" + $("#name").val() + "&" + "email=" + $("#email").val() + "&" + "comments=" + $("#comments").val() + "&" + "time=" + day + "/" + month + "/" + year,
                complete: function (data) {
                    responseBox.html(data.responseText);
                }
            });
        };
    });
    function changeImage() {
        $(".productad img:eq(" + i + ")").siblings().delay(4000).fadeTo(800, 0);
        $(".productad img:eq(" + i + ")").delay(4000).fadeTo(800, 1, function () {
            if (i < 2) {
                i += 1;
            } else {
                i = 0;
            };
            changeImage();
        });
    };
    changeImage();

    var path = location.pathname.substring(11);
    if (path) {
        $('.servicelink a[href$="' + path + '"]').hide();
    };
    $(".enclick").click(function () {
        $("body").append("<div class='cover'></div>");
        $(this).fadeTo(250, 0, function () {
            $(this).css("display", "none");
        });
        $(".cover").fadeTo(0, 0).delay(800).fadeTo(400, .6);
        $(".enclosed").animate({ "height": "0px" }, 250, "linear", function () {
            $(".enopened").animate({ "height": "42px" }, 250, "linear", function () {
                $(".encard").animate({ "bottom": "160px" }, 300, function () {
                    $(this).animate({ "right": "180px", "height": "280px", "width": "500px", "bottom": "30px" }, 400, function () {
                        $(this).html("<div><img src='images/sigssm.jpg' alt='' />Looking for the perfect gift? <br /><br />Our gift card can be used for our skin care products, cosmetic and elective procedures, including laser! <br /><br />Please call us at 614.777.1200 for more information.<img src='images/ex.png' alt='' class='mclose' /></div>");
                    });
                });
            });
        });
        $(".cover, .mclose").live("click", function () {
            $(".cover").fadeTo(400, 0, function () {
                $(this).remove();
            });
            $(".encard").empty().animate({ "bottom": "160px", "right": "6px", "width": "109px", "height": "72px" }, 400, function () {
                $(this).animate({ "bottom": "0px" }, 300, function () {
                    $(".enopened").animate({ "height": "0px" }, 250, "linear", function () {
                        $(".enclosed").animate({ "height": "45px" }, 250, "linear");
                        $(".enclick").css("display", "block").fadeTo(250, 1);
                    });
                });
            });
        });
    });
});
