$.fn.cycle.transitions.scrollDown = function($cont, $slides, opts) {
    $cont.css('overflow','hidden');
    opts.before.push(function(curr, next, opts) {
        $(this).show();
        opts.cssBefore.top = 0-next.offsetHeight;
        opts.animOut.top = curr.offsetHeight;
    });
    opts.cssFirst = { top: 0 };
    opts.animIn   = { top: 0 };
    opts.cssAfter = { display: 'none' };
};

new function() {
    var Public = {
             'auto': function( bool ) {
                         return bool != undefined ? Private.auto = bool
                                                  : Private.auto;
                     },
             'init': function() {
                         return Private.init();
                     },

        // Perform the 'widont' transformation on a given string.
        'transform': function( string ) {
                         return Private.widont( string );
                     }
    };
    $.jqwidont = Public;
    var Private = {
            'auto': true,
            'init': init,

        // Add a non-breaking space between the last two words of a given
        // string.
          'widont': widont,

        // Regular expression for use later in the plugin.
          'regexp': new RegExp(
                        '[\\n\\r\\s]+'            // whitespace/newlines
                      + '('                       // capture...
                      + '[^\\n\\r\\s(?:&#160;)]+' // non-whitespace/newlines
                      + '[\\n\\r\\s]*'            // trailing whitespace
                      + ')$'                      // ...to end of the string

                        , 'm' // match across newlines
                    )
    };

    $(document).ready(function() {
        if( Private.auto ) init();
    });

    function init() {
        // Use the plugin on all <h*> elements in the page..
        $( 'h1,h2,h3,h4,h5,h6' ).widont();
    };

    $.fn.widont = function() {
        return $(this).each(function() {
            var $obj = $(this);

            $obj.html( Private.widont( $obj.html() ) );
        });
    };

    function widont( string ) {
        return string.replace( Private.regexp, "&#160;$1" );
    };
}();


function toggleFollows()
{
    $('#followed').css({'height': 'auto'}).next().remove();
    return false;
}

$.jqwidont.auto(false);

$(function(){
    var follows = $('#followed li');
    if (follows.length > 25)
    {
        $('#followed')
            .css({'height': 100, 'overflow': 'hidden'})
            .after($('<a href="#" class="block">View all ' + follows.length + '</a>').click(toggleFollows))
    }
    
    if (Dailylog.TwitterHandle) {
        $('.twitter_com .regular div').append('<span class="via">&#x21AA; via <a href="http://twitter.com/#/' + Dailylog.TwitterHandle + '" title="@' + Dailylog.TwitterHandle + ' on Twitter">@' + Dailylog.TwitterHandle + '</a></span>');
    };


    $('.titlelink span, .twitter_com .regular div').widont();

    $('#n-info').click(function(){
        $('#description').slideToggle();
        $(this).toggleClass('open');
        return false;
    });
    
    $('.post').hover(function(){
        $(this).find('.comments').css('display','none').fadeIn('fast');
    });

    $('#searchbox').not('body.search *').addClass('hint').attr('value', 'Search').one('focus', function(){$(this).attr('value', '').removeClass('hint')});
    
    $('.audio .rotate').cycle({ 
        fx: 'scrollDown'
    });
    
    if (Dailylog.TwitterHandle) {
        $("#tweet").tweet({
            username: Dailylog.TwitterHandle,
            join_text: "auto",
            avatar_size: 0,
            count: 1,
            auto_join_text_default: "I said,", 
            auto_join_text_ed: "I",
            auto_join_text_ing: "I was",
            auto_join_text_reply: "I replied to",
            auto_join_text_url: "I checked out",
            loading_text: "Loading...",
            query: '-tumblr.com from:' + Dailylog.TwitterHandle
        });
    }

});

