// following codes are dual licensed under the MIT and GPL licenses:
// http://www.opensource.org/licenses/mit-license.php
// http://www.gnu.org/licenses/gpl.html

// extension for scrollTo
$.fn.extend({
    scrollTo : function(speed){
        return this.each(function(){
            var targetOffset = $(this).offset().top;
            $("html,body").animate({scrollTop: targetOffset}, speed);
        });
    }
});
$(function(){
    mws = 'http://dormouse.oops.jp/';
// generate update information and accordionize
    $("#pagebody #sidebar div#udtlist").load(mws + 'update/update.txt', function(){
        $("#pagebody #sidebar div#udtlist dl").accordion({
            header : 'dt',
            autoheight : true
        });
        $("#pagebody #sidebar div#udtlist dt").hover(
            function(){$(this).addClass("hoverDT");},
            function(){$(this).removeClass("hoverDT");}
        );
    });
});
$(function(){
// load category menu
    $("#hobby div#sidemenu").load(mws + 'menus/hobby.txt', function(){
        $("#hobby div#sidemenu ul").accordion({
            header : '.lhd',
            active : true,
            alwaysOpen : false,
            autoheight : false
        });
    });
    $("#study div#sidemenu").load(mws + 'menus/study.txt', function(){
        $("#study div#sidemenu ul").accordion({
            header : '.lhd',
            active : true,
            alwaysOpen : false,
            autoheight : false
        });
    });
// backlink to pagetop
    $("#contents p.back a").removeAttr("href");
    $("#contents p.back").click(function(){
        $("#pagebody").scrollTo(500);
    });
});
$(function(){
// tooltips
    $("a,abbr,em,blockquote").Tooltip({
        track   : true,
        fixPNG  : true
    });
// colorbox
    $("a.colorbox").click(function(){
        $(this).colorbox();
    });
// display document.lastModified
    $("#contents h2#pagetitle").after('<p class="lmdate">Last Modified : ' + document.lastModified + '</p>');
// rss_icon
    $("#header h1#sitename").after('<a class="snap_noshots" href="http://feeds.feedburner.com/dormouse"><img id="rss_icon" src="' + mws + '/imgs/icons/icon_rss_24.png" width="24" height="24" alt="rss" /></a>');
// remove readmorelink
    $("#contents p.nextButton a").removeAttr('href');

// MTCounter
    $("#pagebody #sidebar ul#list_more").before('<p class="showhide">次の5件を表示 &raquo;</p>');
    $("#pagebody #sidebar p.showhide").toggle(function(){
        $(this).html('&laquo; 隠す');
        $("ul#list_more").slideToggle(500);
    }, function(){
        $(this).html('次の5件を表示 &raquo;');
        $("ul#list_more").slideToggle(500);
    });
});

// search form
function inputFocus(widget){
    if (widget.value == '検索'){
        widget.value = '';
    }
}
// monthly dropdown
function nav(sel) {
   if (sel.selectedIndex == -1) return;
   var opt = sel.options[sel.selectedIndex];
   if (opt && opt.value)
      location.href = opt.value;
}

// load another scripts
function chainLoad(file){
    file = 'http://dormouse.oops.jp/script/' + file;
    document.write('<script type="text/javascript" src="' + file + '"></script>');
}
chainLoad('modules/generator-pn.js');
chainLoad('modules/generator-et.js');
chainLoad('modules/cookie.js');
