﻿$(
    function() {
        
        $("img").load(function() { $(this).show(); });

        $("img").error(
            function() {
                $(this).remove();
            }
        )

        $("div.Comments ol a").toggle(
            function() {
                $(this).parent().addClass("Selected");
                $(this).nextAll("div").fadeIn("fast");
            },
            function() {
                $(this).parent().removeClass("Selected");
                $(this).nextAll("div").hide();
            }
        )

        $("div.Comments span[href]").attr("title", function() { return $(this).attr("href"); }).addClass("Link").click(function() { window.location = "mailto:" + $(this).attr("href"); });

        $("div.AddComment h3").click(
            function() {
                $("div#AddCommentHid").toggle();
            }

        );

        $("div.Comment-Title a").click(
            function() {
                $("div.Comment-Hidden", $(this).parent().parent().toggleClass("Comment-Wrapper")).toggle();
            }
        );

        $("div.Form form").submit(
            function(e) {
                return false;
            }
        )

        $("div.Form form button").click(
            function() {
                if (CheckFrm($("div.Form form").get(0))) {

                    var html = "";

                    $("div.Form form input:text").each(
                        function(i) {
                            var $this = $(this);
                            html += $this.prev("label").text() + " " + $this.val() + "<br />";
                        }
                    )

                    $("div.Form form textarea").each(
                        function(i) {
                            var $this = $(this);
                            html += $this.prev("label").text() + " " + $this.val() + "<br />";
                        }
                    )

                    $("div.Form form :checked").each(
                        function(i) {
                            var $this = $(this);
                            html += $this.next("label").text() + "<br />";
                        }
                    )

                    $("div.Form form").attr({ method: "post" });

                    var wrapper = $("div.Form");

                    var formData = "SubmitContact=True&html=" + escape(html);

                    $(this).text(sending).attr("disabled", true);

                    $.post(url, formData, function(data) {
                        wrapper.html("<div style=\"padding: 0 20px;\">" + data + "</div>");
                    }
                    )
                }
            }
        )
    
    }
)
