
/**
             * Callback function for the image container
             */
            function imagePageselectCallback(page_index, jq) {
                 jQuery('div.gallGroup:visible').hide();
                 jQuery('div.gallGroup:eq(' + page_index + ')').animate({"opacity": "show"});

            }

            /**
             * Initialisation function for pagination
             */
            function initPagination() {
                // Create pagination for images
                var num_entries = jQuery('div.gallGroup').length;
                jQuery("#ImagePagination").pagination(num_entries, {
                    callback: imagePageselectCallback,
                    link_to: 'javascript: void(0);',
                    items_per_page:1 // Show items per page
                });
             }



jQuery(document).ready(function(){


    jQuery('div.gallery').prepend('<div id="ImagePagination"></div><div style="clear:both;"></div>');
    jQuery('div.gallery').append('<div style="clear:both;"></div>');
    jQuery('div.gallery br').remove();

    var $pArr = jQuery('div.gallery dl');
    var pArrLen = $pArr.length;
    var pPerDiv = 9;
    for (var i = 0;i < pArrLen;i+=pPerDiv){
        $pArr.filter(':eq('+i+'),:lt('+(i+pPerDiv)+'):gt('+i+')').wrapAll('<div class="gallGroup" />');
    }

    jQuery('#gallery-1 dl:nth-child(3n)').after('<div style="clear:both;"></div>');
    //jQuery('#gallery-1 dl:nth-child(3n)').css('background','red');

    initPagination();

});
