$(document).ready(function() {
    
    /* Tabbed Content */
    
    $('#h-actionwrapper-tabs a').click(function() {
        $('#h-actionwrapper-tabs a').removeClass('current');
        $(this).addClass('current');
        $('#h-actionwrapper-cnt li').hide();
        $('#h-actionwrapper-cnt li:eq(' + $('#h-actionwrapper-tabs a').index(this) + ')').show();
        return false;
    });
    $('#h-actionwrapper-tabs a:first').click();
    
    /* Pulldown Content */
    
    $(".dropdown dt a").click(function() {
        $(".dropdown dd ul").toggle();
    });
    
    $(".dropdown dd ul li a").click(function() {
        var text = $(this).html();
        $(".dropdown dt a span").html(text);
        $(".dropdown dd ul").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 ul").hide();
    });
    
    /* Tabbed Content */
    
    $('#sub-actionwrapper-tabs a').click(function() {
        $('#sub-actionwrapper-tabs a').removeClass('current');
        $(this).addClass('current');
        $('#sub-actionwrapper-cnt li').hide();
        $('#sub-actionwrapper-cnt li:eq(' + $('#sub-actionwrapper-tabs a').index(this) + ')').show();
        return false;
    });
    $('#sub-actionwrapper-tabs a:first').click();
    
    /* Pulldown Content */
    
    $(".sub-dropdown dt a").click(function() {
        $(".sub-dropdown dd ul").toggle();
    });
    
    $(".sub-dropdown dd ul li a").click(function() {
        var text = $(this).html();
        $(".sub-dropdown dt a span").html(text);
        $(".sub-dropdown dd ul").hide();
        $("#result").html("Selected value is: " + getSelectedValue("sample"));
    });
    
    $(document).bind('click', function(e) {
        var $clicked = $(e.target);
        if (! $clicked.parents().hasClass("sub-dropdown"))
            $(".sub-dropdown dd ul").hide();
    });
    
});