$(document).ready(function() {
    $("input.clear-text")
        .focus(function() {
            $(this).attr("lastVal",$(this).val());
            $(this).val("");
        })
        .blur(function(){
            if($(this).val()=="") {
                $(this).val($(this).attr("lastVal"));
            }
        });
    $("._blank").click(function() {
        window.open($(this).attr("href"));
        return false;
    });
    $(".share-link").click(function() {
        var path = $(this).attr("href");
        if($("#share")) { $("#share").remove(); }
        $("<div id=\"share\"><div id=\"share-content\"></div></div>").insertAfter(this);
        $("#share-content").load(path);
        $('#share').css({
            'right': 980-$(this).position().left-$(this).width() + 'px',
            'top': $(this).position().top + 'px'
        }).show("fast", function() {
            $('.share-close').click(function() {
                $('#share').hide("fast", function() {
                    $("#share").remove();
                });
                return false;
            });
            $("body").bind("click", closeShareOnBlur);
            $(".arrow").css('border-width',"1px");
        });
        return false;
    });
    $('#language').hover(
        function(){
            _this = $(this);
            _this.addClass('list-flags');
            $('#flag-list').css({
                'bottom': _this.height()
            }).show('fast')
        },
        function(){
            $(this).removeClass('list-flags');
            $('#flag-list').hide('fast')
        }
    );
});
function closeShareOnBlur(e) {
    var actor = $('#share');
    var inWidth = (e.pageX>actor.offset().left && e.pageX<(actor.offset().left+actor.width())) ? 1 : 0;
    var inHeight = (e.pageY>actor.offset().top && e.pageY<(actor.offset().top+actor.height())) ? 1 : 0;

    if (!(inWidth && inHeight)) {
        actor.hide("fast", function() {
           $("#share").remove();
           $("body").unbind("click", closeShareOnBlur);
        });
    }
}