$(function() {
   $(document).ready(function(){ 
        $("#drop-menu > ul").superfish({ 
            // animation: {height:'show'},   // slide-down effect without fade-in 
            speed: 'fast',
            delay:     400               // 1.2 second delay on mouseout 
        });
        
        // Top navigation
        var path = window.location.pathname;
        $("a", "#nav").each(function() {
            if ($(this).attr("href") == path) {
                $(this).addClass("active");
                return false;
            }
        });
    }); 
   
   // $('#drop-menu ul ul').animate({
        // opacity: 1
    // }, 500)
   
   /* drop down */
    $(".dropdown dt a").click(function() {
        $(this).closest(".dropdown").find('dd').toggle();
        return false;
    });
                
    $(".dropdown dd ul li a").click(function() {
        var text = $(this).html();
        $(this).closest(".dropdown").find("dt a span").html(text);
        $(this).closest(".dropdown").find("dd").hide();
        $("#result").html("Selected value is: " + getSelectedValue("sample"));
    });
    
    function getSelectedValue(id) {
        return $("#" + id).find("dt a span.value").html();
    }
    
    $(document).bind('click', function(e) {
        var $clicked = $(e.target);
        if (! $clicked.parents().hasClass("dropdown"))
            $(".dropdown dd").hide();
    });
    
    // Logo
    $("#emergelogo").parent().append('<img src="/images/emerge-color.png" width="146" height="59" id="emergelogocolor"/>');
    $("#emergelogocolor").fadeTo(0, 0).mouseover(function() {
        $(this).stop().animate({
            opacity: 1
        }, 1000);
    }).mouseout(function() {
        $(this).stop().animate({
            opacity: 0
        }, 1000);
    });
});
