
var highlightSrc = function(src){
    return src.replace(/([.][^.]+)$/, "_on$1");
};


/**
 * Global Navigation Highlight
 */
(function(){
    $("#head .menu1 a, #head .menu2 a").each(function(i, a){
        var corner = "/" + a.pathname.replace(new RegExp("^/"), "").replace(new RegExp("([^/]+/).*"), "$1");
        if (location.pathname.indexOf(corner) == 0){
            var img = $(a).children("img")[0];
            img.src = highlightSrc(img.src);
            $(img).removeClass("ahl");
        }
    });
})();


/**
 * Auto Highlight
 */
(function(){
    var imgs = $(".ahl");
    imgs.each(function(i, img){
        new Image().src = highlightSrc(img.src);
    });
    imgs.mouseenter(function(){
        var normal = jQuery.data(this, "highlight_normal_src");
        if (normal){
            return;
        }
        jQuery.data(this, "highlight_normal_src", this.src);
        this.src = highlightSrc(this.src);
    });
    imgs.mouseleave(function(){
        var normal = jQuery.data(this, "highlight_normal_src");
        if (!normal){
            return;
        }
        this.src = normal;
        jQuery.removeData(this, "highlight_normal_src");
    });
})();


/**
 * Scroll to top
 */
(function(){
    $(".to_page_top").click(function(event){
        event.preventDefault();
        $("html, body").animate({scrollTop: 0});
    });
})();

