$(document).ready(function() {
$(".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();
                    $(".dropdown dt a img").html(text);

    var id = $('img', this).attr('alt');
    id = id.split('_');
    $("#local_language_bar").val(id[0]);

    if(window.location_url === undefined)
    {
        $("#link_language_bar").val(document.URL);
    }
    else
    {
        $("#link_language_bar").val(location_url);
    }
    document.languageForm.submit();

    return false;
});

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();
});
});
