﻿$(
    function() {
        cms.comments();
        cms.gallery();
        cms.form();
    }
)

    var cms = {
        gallery: function() {
            if ($("div.gallery-navigation")) {
                $("div.gallery-navigation a").live("click",
                function(e) {
                    e.preventDefault();
                    $("div.right-content").load($(this).attr("href") + " div.right-content");

                }
            )
            }
        },

        comments: function() {
            if ($(".comments")) {
                $(".add-comment h3").click(
                function() {
                    $(".add-comment form div").toggle();
                }
            )

                $(".comments span[href]").attr("title", function() { return $(this).attr("href"); }).addClass("link").click(function() { window.location = "mailto:" + $(this).attr("href"); });

                $(".comments li a").click(
                function() {
                    $(this).nextAll("div").toggle();
                }
            );
            }
        },

        form: function() {
            if ($("div.form")) {
                $("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(data);
                            }
                            )
                        }
                    }
                )
            }
        }
    }


