﻿var currentSizeIndex = 3;
var sizes = new Array(0.325, 0.425, 0.525, 0.625, 0.725, 0.825, 0.925);
$(document).ready(function()
{
    $('.fontsize').click(function(e)
    {
        e.preventDefault();
        
        // Get direction.
        var direction = $(this).attr('accesskey');
        
        // Set size.
        setFontSize(currentSizeIndex, direction);
    });
    
    $('.print').click(function(e)
    {
        e.preventDefault();
        
        window.print();
    });
});
function setFontSize(index, direction)
{
    index += (direction == '-') ? -1 : 1;
    index = (index > 6) ? 6 : index;
    index = (index < 0) ? 0 : index;
    
    currentSizeIndex = index;
    
    $('body').css('font-size', sizes[index] + 'em');
}
 

        /* Pagination for news and event items */
        var max_items_per_page = 4;
        function pageselectCallback(page_index, jq){            
                //hide results once called by initPagination 
                $('#hidden-newsAndEventsListing').hide();
                //show pagination containers
                $('#newsAndEventsListing').show();
                $('#Pagination').show();
                // Get number of elements per pagionation page from form            
                var num_entries = $('#hidden-newsAndEventsListing li.clear').length;
                var items_per_page = max_items_per_page;
                var max_elem = Math.min((page_index+1) * items_per_page, num_entries);
                var newcontent = '';                                   
                $('#newsAndEventsListing').empty()
                // Iterate through a selection of the content and build an HTML string
                for(var i=page_index*items_per_page;i<max_elem;i++)
                {
                        $('#newsAndEventsListing').append($('#hidden-newsAndEventsListing li.clear:eq('+i+')').clone());
                }    
                // Prevent click eventpropagation
                return false;
        }
      
        function initPagination() {
                var num_entries = $('#hidden-newsAndEventsListing li.clear').length;
                // Create pagination element
                $("#Pagination").pagination(num_entries, {
                        items_per_page:max_items_per_page,
                        callback:pageselectCallback                    
                });
        }
                            
        $(document).ready(function(){      
                if ($('#hidden-newsAndEventsListing ul.clear').length > (max_items_per_page - 1)) {                    
                        initPagination();
                }
        });