function addDelicious (strTitle, strURL, strDesc, strKeyword) {
      window.open('http://del.icio.us/post?v=4&noui&jump=close&url='+strURL+'&title='+strTitle+'&notes='+strDesc+'&tags='+strKeyword, 'delicious','toolbar=no,width=700,height=400');
 }

 function addFacebook (strThumb, strURL, strTitle, strDesc) {
      window.open('http://www.facebook.com/sharer.php?s=100&p[medium]=100&p[title]='+strTitle+'&p[images][0]='+strThumb+'&p[url]='+strURL+'&p[summary]='+strDesc+'','sharer','toolbar=0,status=0,width=626,height=436');
 }

 function addGBookmark (strTitle, strURL, strDesc, strKeyword) {
      window.open('http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk='+strURL+'&title='+strTitle+'&labels='+strKeyword+'&annotation='+strDesc, 'googlebookmark','toolbar=no,width=700,height=500');
 }

 function addDigg (strTitle, strURL, strDesc) {
      window.open('http://digg.com/submit?phase=2&url='+document.location.href+'&title='+strTitle, 'digg','scrollbars=yes,toolbar=no,width=760,height=500');
 }

 function addYahoo (strTitle, strURL, strDesc, strKeyword) {
      window.open('http://myweb2.search.yahoo.com/myresults/bookmarklet?u='+strURL+'&t='+strTitle2+'&tag='+strKeyword+'&d='+strDesc, 'yahoo','toolbar=no,width=700,height=400');
 }

 function addTusul (strURL) {
      window.open('http://www.tusul.com/submit.php?url='+strURL, 'tusul','toolbar=no,width=700,height=400');
 }

 function addTechnorati (strUL) {
      window.open('http://www.technorati.com/faves?add='+strURL, 'technorati','scrollbars=yes,toolbar=no,width=800,height=500');
 }

 function addSpurl (strTitle, strURL) {
      window.open('http://www.spurl.net/spurl.php?url='+strURL+'&title='+strTitle,'spurl','toolbar=no,width=700,height=400');
 }
(function($) {

    $.fn.pager = function(options) {
        var opts = $.extend({}, $.fn.pager.defaults, options);
        return this.each(function() {
        // empty out the destination element and then render out the pager with the supplied options
            $(this).empty().append(renderpager(parseInt(options.pagenumber), parseInt(options.pagecount), options.buttonClickCallback));
            // specify correct cursor activity
            $('.pages li').mouseover(function() { document.body.style.cursor = "pointer"; }).mouseout(function() { document.body.style.cursor = "auto"; });
        });
    };
    // render and return the pager with the supplied options
    function renderpager(pagenumber, pagecount, buttonClickCallback) {
        // setup $pager to hold render
        var $pager = $('<ul class="pages"></ul>');
        // add in the previous and next buttons
        $pager.append(renderButton('<<', pagenumber, pagecount, buttonClickCallback)).append(renderButton('<', pagenumber, pagecount, buttonClickCallback));
        // pager currently only handles 10 viewable pages ( could be easily parameterized, maybe in next version ) so handle edge cases
        var startPoint = 1;
        var endPoint = 4;
        if (pagenumber > 4) {
            startPoint = pagenumber - 4;
            endPoint = pagenumber + 4;
        }

        if (endPoint > pagecount) {
            startPoint = pagecount - 8;
            endPoint = pagecount;
        }

        if (startPoint < 1) {
            startPoint = 1;
        }

        // loop thru visible pages and render buttons
        for (var page = startPoint; page <= endPoint; page++) {

            var currentButton = $('<li class="page-number">' + (page) + '</li>');

            page == pagenumber ? currentButton.addClass('pgCurrent') : currentButton.click(function() { buttonClickCallback(this.firstChild.data); });
            currentButton.appendTo($pager);
        }

        // render in the next and last buttons before returning the whole rendered control back.
        $pager.append(renderButton('>', pagenumber, pagecount, buttonClickCallback)).append(renderButton('>>', pagenumber, pagecount, buttonClickCallback));

        return $pager;
    }

    // renders and returns a 'specialized' button, ie 'next', 'previous' etc. rather than a page number button
    function renderButton(buttonLabel, pagenumber, pagecount, buttonClickCallback) {

        var $Button = $('<li class="pgNext">' + buttonLabel + '</li>');

        var destPage = 1;

        // work out destination page for required button type
        switch (buttonLabel) {
            case "<<":
                destPage = 1;
                break;
            case "<":
                destPage = pagenumber - 1;
                break;
            case ">":
                destPage = pagenumber + 1;
                break;
            case ">>":
                destPage = pagecount;
                break;
        }

        // disable and 'grey' out buttons if not needed.
        if (buttonLabel == "<<" || buttonLabel == "<") {
            pagenumber <= 1 ? $Button.addClass('pgEmpty') : $Button.click(function() { buttonClickCallback(destPage); });
        }
        else {
            pagenumber >= pagecount ? $Button.addClass('pgEmpty') : $Button.click(function() { buttonClickCallback(destPage); });
        }

        return $Button;
    }

    // pager defaults. hardly worth bothering with in this case but used as placeholder for expansion in the next version
    $.fn.pager.defaults = {
        pagenumber: 1,
        pagecount: 1
    };

})(jQuery);

