/* pc.js v1.0 */
var mppc = {
viewerHeight: window.innerHeight ? window.innerHeight : $(window).height(),
pagetop: function()
{
window.scrollTo(0, 0);
},
tpChange: function(target)
{
if ($("#topicstab-" + target).hasClass("current")) {
location.href = $("#topicstab-" + target).attr("data-url");
} else {
$("#topicsblock-" + target).siblings(":not(nav)").addClass("hidden");
$("#topicsblock-" + target).removeClass("hidden");
$("#topicstab-" + target).siblings().removeClass("current");
$("#topicstab-" + target).addClass("current");
}
},
mrChange: function(target)
{
$("#index-magazineranking .magazineranking-block").hide();
$("#index-magazineranking #" + $(target).val()).show();
var ranking_ctg = $(target).val().replace(/^mr-/,"");
if ( ranking_ctg.length < 2 ) ranking_ctg = 'all';
$("#index-magazineranking .link a").attr("href","/ranking/magazine/"+ranking_ctg+"/weekly");
},
hsOver: function(target)
{
var t = target;
var i = t.find("img");
var s = t.find("ul");
$("header nav li").removeClass("hover");
$("header nav ul.sub").hide();
$("header nav img").each(function() {
$(this).attr("src", $(this).attr("src").replace(/_sub\.png$/, ".png"));
});
t.addClass("hover");
s.show();
if (i.attr("src").search(/_sub\.png$/) == -1) {
i.attr("src", i.attr("src").replace(/\.png$/, "_sub.png"));
}
t.hover($.noop, function(e) {
t.removeClass("hover");
s.hide();
if (i.attr("src").search(/_sub\.png$/) != -1) {
i.attr("src", i.attr("src").replace(/_sub\.png$/, ".png"));
}
});
},
searchType: function(type)
{
switch (type) {
case "article":
$("#word-search-type").val("article");
$(".word-search").removeClass("current");
$("#word-search-article").addClass("current");
if ($("#word-search-query").val() == "ウェブ検索") {
$("#word-search-query").val("記事検索");
}
break;
case "web":
$("#word-search-type").val("web");
$(".word-search").removeClass("current");
$("#word-search-web").addClass("current");
if ($("#word-search-query").val() == "記事検索") {
$("#word-search-query").val("ウェブ検索");
}
break;
}
},
coverTimeoutlId: 0,
coverView: function(id)
{
var menu = $("#cover .menu li");
var menu_a = $("#cover .menu li a");
var content = $("#cover .content li");
var setCategory = function(id) {
var current_id;
if (typeof id === "string") {
if (id == menu.find("a.current").parent().attr("class")) {
location.href = "/" + menu.find("a.current").parent().attr("class");
}
current_id = id;
menu_a.removeClass("current");
menu.filter("." + current_id).find("a").addClass("current");
} else if (!menu_a.hasClass("current")) {
var t = menu.eq(0);
current_id = t.attr("class");
t.find("a").addClass("current");
} else {
current_id = menu.find("a.current").parent().next().attr("class");
if (typeof current_id !== "string") {
var t = menu.eq(0);
menu.animate({ "top":"0px" }, "fast");
menu_a.removeClass("current");
current_id = t.attr("class");
t.find("a").addClass("current");
$("#cover .menu ul").animate({ "top": 0 }, "fast");
} else {
var t = menu.filter("." + current_id);
menu_a.removeClass("current");
t.find("a").addClass("current");
$("#cover .menu ul").animate({ "top": -312 * Math.floor(menu.index(t) / 8) + "px" }, "fast");
}
}
setContent(current_id);
};
var setContent = function(id) {
var c = content.filter("." + id);
var img = c.find(".image");
content.removeClass("current");
content.find(".image").css("opacity", 0);
clearTimeout(mppc.coverTimeoutlId);
c.addClass("current");
if (img.height() > 353) {
img.css("top", (353 - img.height()) + "px");
img.animate({ opacity: 1 }, { duration: 3000, queue: false })
.animate({ top: 0 }, { duration: 6000, easing: "easeInOutQuad", queue: false });
} else {
img.animate({ opacity: 1 }, { duration: 1000, queue: false });
}
mppc.coverTimeoutlId = setTimeout(mppc.coverView, 6500);
};
if (typeof id === "string") {
return setCategory(id);
}
setCategory(id);
},
coverNext: function()
{
var menu = $("#cover .menu ul");
if (menu.position().top - 312 > -menu.height()) {
menu.animate({ "top":"-=312px" }, "fast");
}
},
coverBack: function()
{
var menu = $("#cover .menu ul");
if (menu.position().top < 0) {
menu.animate({ "top":"+=312px" }, "fast");
}
},
coverViewInit: function()
{
setTimeout(mppc.coverView, 1000);
},
rankingCurrent: "",
rankingClose: function(e)
{
if (typeof e != "undefined" && !$(e.target).hasClass("btn")) {
$(".ranking-select .current").removeClass("open");
$(".ranking-select .list").hide();
}
},
rankingDaily: function()
{
$(".ranking-daily .current").toggleClass("open");
$(".ranking-daily .list").toggle();
$("body").one("click", mppc.rankingClose);
if (mppc.rankingCurrent == "daily") {
mppc.rankingClose();
mppc.rankingCurrent = "";
} else {
mppc.rankingCurrent = "daily";
}
},
rankingMonthly: function()
{
$(".ranking-monthly .current").toggleClass("open");
$(".ranking-monthly .list").toggle();
if ($(".monthly").length <= 3) {
$(".monthly").show();
} else {
var first = 0;
$(".monthly").each(function(i, e) {
if ($(this).css("display") != "none") {
first = i;
return false;
}
});
if (first == 0) {
$(".monthly:lt(3)").show();
$(".ranking-monthly .list")
.addClass("navigation")
.prepend("<")
.append(">");
$(".ranking-monthly a.btn").css("top", $(".ranking-monthly .list").height() / 2 - 37);
}
}
mppc.rankingBtnCheck();
var skip = $(".ranking-monthly .monthly").index($(".ranking-monthly .monthly .selected").parents(".monthly"));
for (var i = 0; i < skip; i++) {
mppc.rankingNext();
}
$("body").one("click", mppc.rankingClose);
if (mppc.rankingCurrent == "monthly") {
mppc.rankingClose();
mppc.rankingCurrent = "";
} else {
mppc.rankingCurrent = "monthly";
}
},
rankingNext: function()
{
$(".monthly").each(function(i, e) {
if ($(this).css("display") != "none") {
if (i+3 < $(".monthly").length) {
$(this).hide();
$(".monthly:eq(" + (i+3) + ")").show();
}
return false;
}
});
mppc.rankingBtnCheck();
},
rankingPrev: function()
{
$(".monthly").each(function(i, e) {
if ($(this).css("display") != "none") {
if (i > 0) {
$(".monthly:eq(" + (i-1) + ")").show();
$(".monthly:eq(" + (i+2) + ")").hide();
}
return false;
}
});
mppc.rankingBtnCheck();
},
rankingBtnCheck: function()
{
$(".monthly").each(function(i, e) {
if ($(this).css("display") != "none") {
if (i == 0) {
$(".ranking-monthly .btn-prev").hide();
} else if (i+3 >= $(".monthly").length) {
$(".ranking-monthly .btn-next").hide();
} else {
$(".ranking-monthly .btn-prev").show();
$(".ranking-monthly .btn-next").show();
}
return false;
}
});
$("body").one("click", mppc.rankingClose);
}
};
$(function() {
$("header nav .onsub").hover(function() {
if (!$(this).hasClass("hover")) {
mppc.hsOver($(this).parent());
}
}, $.noop);
$("#word-search-query")
.focus(function() {
if ($(this).val() == "記事検索" || $(this).val() == "ウェブ検索") {
$(this).val("").css("color", "#000");
}
})
.blur(function() {
if ($(this).val() == "") {
switch ($("#word-search-type").val()) {
case "article":
$(this).val("記事検索").css("color", "#666");
break;
case "web":
$(this).val("ウェブ検索").css("color", "#666");
break;
}
}
});
});