﻿/// <reference path="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"/>

$(document).ready(function () {

    (function () { // Main Menu

        // get items
        var menu = $("#main-menu");
        var openedSection = $("> .opened", menu);
        var menuItems = $("> .opened > ul", menu);
        var sectionLink = $("> .opened > a:first", menu);

        // Change HTML structure
        menu.removeClass("no-js");
        var sectionHeader = $("<h2/>", { html: sectionLink.html() });
        sectionLink.replaceWith(sectionHeader);
        var selectedLink = $(".opened > ul > li.selected", menu); //.remove();
        $("<span/>", { "class": "selected", html: selectedLink.children("a").html() }).insertAfter(sectionHeader);

        // Add hover events
        $.event.special.hover.delay = 50;
        $.event.special.hover.speed = 25;

        openedSection.hover(
                function () {
                    menuItems.addClass("drop-shadow").slideDown("fast");
                },
                function () {
                    menuItems.slideUp("fast").removeClass("drop-shadow");
                });

        var closedSections = $("> li", menu).not(".opened");
        closedSections.hover(
            function () {
                var items = $("ul", this);
                $(this).addClass("drop-shadow");
                items.addClass("drop-shadow").slideDown("fast");
            },
            function () {
                var items = $("ul", this);
                items.slideUp("fast").removeClass("drop-shadow");
                $(this).removeClass("drop-shadow");
            });

    })();

    (function () { // Contact Form

        var button = $("#contact");

        $("#contact").click(function () {
            bodyelem = $.browser.safari ? $("body") : $("html");
            bodyelem.animate({ scrollTop: 0 }, 500);
            $("#contact-form").slideDown("fast");
            button.addClass("dim");
            return false;
        });

        $("#contact-form input[name=close]").live("click", function () {
            $("#contact-form").slideUp("fast");
            button.removeClass("dim");
            return false;
        });

        $("a.contact-link").click(function () {
            button.click();
            return false;
        });

    })();

});
