// DOM Ready
$(function() {

    var $el, leftPos, newWidth;
       
    
    $("#gnavi ul").append("<li id='moveLine'></li>");
    
    /* Cache it */
    var $mLine = $("#moveLine");
    
    $mLine
        .width($(".selected").width())
        .css("left", $(".selected a").position().left)
        .data("origLeft", $mLine.position().left)
        .data("origWidth", $mLine.width());
        
    $("#gnavi li").find("a").hover(function() {
        $el = $(this);
        leftPos = $el.position().left;
        newWidth = $el.parent().width();
        
        $mLine.stop().animate({
            left: leftPos,
            width: newWidth
        });
    }, function() {
        $mLine.stop().animate({
            left: $mLine.data("origLeft"),
            width: $mLine.data("origWidth")
        });    
    });
    
    
});
