jQuery(document).ready(function($) {

    // fade out error message bg color
    $("#messages, #comment_errors, #comment_msgs").animate({opacity: 1.0}, 3000).animate({backgroundColor: '#ffffff'}, 3000);


    // handlers for fields in signup stub form
    $("#signup_box_email, #signup_box_zip").focus(function() {
        vanilla.swapValue(this, false);
    });
    $("#signup_box_email, #signup_box_zip").blur(function() {
        vanilla.swapValue(this, true);
    });
    
    $("#bookmarks").bookmark({
        compact: false,
        icons: "/images/bookmarks.png", 
        sites: ["delicious", "digg", "facebook", "google", "myspace", "reddit", "twitthis", "yahoobuzz"]
    });
    $("#bookmarks ul").prepend('<li class="email"><a href="/forward/"><span></span>Email</a></li>');

    // home features
    var num_features = $("#home_features").children().length;
    // var random_feature = Math.floor(Math.random() * num_features);
    var random_feature = 0;
    $("#home_features").children().each(function(i) {
        if (i == random_feature) {
            $(this).show();
        }
        $(this).addClass("hf" + i);
        $(this).prepend('<div class="nextprev"><a href="#" class="ir prev">Prev</a> <a href="#" class="ir next">Next</a></div>');
    });
    $(".nextprev .next").each(function(i) {
        $(this).click(function() {
            var next = i + 1;
            if (next == (num_features)) next = 0; 
            $("#home_features .leadin").hide();
            $("#home_features .hf" + next).show();
        });
    });
    $(".nextprev .prev").each(function(i) {
        $(this).click(function() {
            var prev = i - 1;
            if (prev < 0) prev = num_features - 1; 
            $("#home_features .leadin").hide();
            $("#home_features .hf" + prev).show();
        });
    });

    // hide preview bars
    $('.preview_notice a.hide_preview').click(function() {
        $('.preview_notice').hide();
    });


});

