jQuery.noConflict();
jQuery(document).ready(function($){
    $("a[rel=external]").attr("target","_blank");
    $("a[rel=rekisteriseloste]").attr("target","reg").click(function(){
        var atreg=window.open('', 'reg', 
       'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=640,height=520'); atreg.focus();
    });

});

function paginateArchive(){
    jQuery("div.c_paivakirja div.archiveBrowser div").append("<a id='aPrev' href='javascript:void(0);' title='Edellinen'>&lt;</a><span id='aCount'></span><a id='aNext' href='javascript:void(0);' title='Seuraava'>&gt;</a>"); 
    var pageSize = 9;
    var currentPage = Math.floor(jQuery("ul#diaryArchive li").index(jQuery("ul#diaryArchive li:has(b)")) / pageSize);
    var lastPage = Math.floor(jQuery("ul#diaryArchive li").size() / pageSize);
    if(currentPage < 0) currentPage = 0;
    if(lastPage < 0) lastPage = 0;
    var displayPage = function(p){
        var lowIndex = p * pageSize;
        var highIndex = lowIndex + pageSize - 1;
        jQuery("ul#diaryArchive li").show();
        jQuery("ul#diaryArchive li:lt(" + lowIndex + "), ul#diaryArchive li:gt(" + highIndex + ")").hide();
        updateCount();
    }
    
    var updateCount = function(){
        jQuery("span#aCount").text((currentPage+1) + " / " + (lastPage+1));
    }
    
    jQuery("a#aPrev").click(function(){
        if(currentPage > 0) displayPage(--currentPage);
    });
    
    jQuery("a#aNext").click(function(){
        if(currentPage < lastPage) displayPage(++currentPage);
    });
    
    displayPage(currentPage);
}