﻿// vim: set et sw=4 ts=4 sts=4 fdm=marker ff=unix fenc=utf8 nobomb:
/**
 * @date  2011-05-31
 */

jQuery(function($) {
    /**
     * 输入框自动补全
     */
    

    // 锚点动画滚动
    $(".totop a").click(function(e) {
        var target = $(this).attr('href'), scrollTop = parseInt($(target).offset().top, 10);
        if (target.match(/^#.+/)) {
            $("html, body").animate({scrollTop:scrollTop}, 500, function() {
                // 动画完成后，改变锚点地址
                location.hash = target;
            }); 
            return false;
        }
    });

    // 动态调整向上滚动按钮
    var adjustGotoTopEl = function() {
        var goTopEl = $("#goto-top"),
            offsetLeft = $("#page").offset().left + $("#page").width();

        var scrollTop = $(window).scrollTop(), clientHeight = $(window).height();

        goTopEl[(scrollTop < clientHeight/2) ? "hide" : "show"]();
        goTopEl.css('left', offsetLeft);

        if (jQuery.browser.msie < 7) {
            goTopEl.css('position', 'absolute');
            goTopEl.css('top', scrollTop + clientHeight/2);
        }
    }
    $(window).bind('scroll', adjustGotoTopEl);
    $(window).bind('resize', adjustGotoTopEl);

    
});


