$(document).ready(function () {
var pub_head_title = $('.index_pub_head_title h2');
var countPubHeadTitle = pub_head_title.length;
var firstPubHeadTitle = pub_head_title.eq(0);
var fixed_nav = $("#index_fixed_nav_container");
var nav_ul = fixed_nav.children('ul');
var nav_li_html = '';
pub_head_title.each(function () {
nav_li_html = nav_li_html + '
' + $(this).text() + '
';
});
nav_ul.append(nav_li_html);
var nav_li = nav_ul.children('li');
nav_li.eq(0).click(function () {
$('html,body').animate({'scrollTop' : 0});
});
nav_li.filter(':gt(0)').click(function () {
var this_index = $(this).index();
var toTop = pub_head_title.eq(this_index - 1).offset().top;
var nextHeadTitle = pub_head_title.eq(this_index);
if (nextHeadTitle.length > 0) {
var nextPartitionTop = nextHeadTitle.offset().top - $(window).height() / 1.5;
if (toTop >= nextPartitionTop) {
toTop = nextPartitionTop;
}
}
toTop = toTop - 20;
$('html,body').animate({'scrollTop' : toTop});
});
function OnScroll() {
var windowScrollTop = $(window).scrollTop();
if (windowScrollTop >= firstPubHeadTitle.offset().top - $(window).height() / 2.7) {
fixed_nav.addClass('on');
}
else {
fixed_nav.removeClass('on');
return;
}
var i;
for (i = countPubHeadTitle - 1; i >= 0; i--) {
var theTitle = pub_head_title.eq(i);
if (windowScrollTop >= theTitle.offset().top - $(window).height() / 1.5) {
var theLi = nav_li.eq(i + 1);
theLi.siblings('li').removeClass('on');
theLi.addClass('on');
break;
}
}
}
OnScroll();
$(window).scroll(function () {
OnScroll();
});
});