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 stub forms
    $("#signup_box_email, #signup_box_zip, #search_box_keywords").focus(function() {
        vanilla.swapValue(this, false);
    });
    $("#signup_box_email, #signup_box_zip, #search_box_keywords").blur(function() {
        vanilla.swapValue(this, true);
    });
    
    // stub forms in sidebar
    $("#heroes_form #id_subject").focus(function() {
        vanilla.swapValue(this, false, "Your Hero's Name");
    });
    $("#heroes_form #id_subject").blur(function() {
        vanilla.swapValue(this, true, "Your Hero's Name");
    });
    $("#heroes_form #id_message").focus(function() {
        vanilla.swapValue(this, false, "Why This Person Is Your Hero");
    });
    $("#heroes_form #id_message").blur(function() {
        vanilla.swapValue(this, true, "Why This Person Is Your Hero");
    });
    
    $("#myths_form #id_message").focus(function() {
        vanilla.swapValue(this, false, "Your Myth About Gay Marriage");
    });
    $("#myths_form #id_message").blur(function() {
        vanilla.swapValue(this, true, "Your Myth About Gay Marriage");
    });
    
    $("#video_form #id_message").focus(function() {
        vanilla.swapValue(this, false, "Your Video About Gay Marriage");
    });
    $("#video_form #id_message").blur(function() {
        vanilla.swapValue(this, true, "Your Video About Gay Marriage");
    });
    
    $("#events_form #id_message").focus(function() {
        vanilla.swapValue(this, false, "Your Upcoming Community Event");
    });
    $("#events_form #id_message").blur(function() {
        vanilla.swapValue(this, true, "Your Upcoming Community Event");
    });
    
    $("#march_form #id_message").focus(function() {
        vanilla.swapValue(this, false, "Your Opinion on the Next March on Washington");
    });
    $("#march_form #id_message").blur(function() {
        vanilla.swapValue(this, true, "Your Opinion on the Next March on Washington");
    });
    
    $("#quote_form #id_message").focus(function() {
        vanilla.swapValue(this, false, "A Celebrity Quote You Think is Insightful or Inspiring");
    });
    $("#quote_form #id_message").blur(function() {
        vanilla.swapValue(this, true, "A Celebrity Quote You Think is Insightful or Inspiring");
    });
    
    // always the same
    $(".stubform #stub_email").focus(function() {
        vanilla.swapValue(this, false, "Your Email Address");
    });
    $(".stubform #stub_email").blur(function() {
        vanilla.swapValue(this, true, "Your Email Address");
    });

    // open rssbox links in new window
    $(".rssboxitem a").each(function() {
        $(this).css("padding-right", "18px").css("background", "url(/images/newwindow.png) no-repeat right").click(vanilla.openInNewWindow);
    });

    // rotate thru a set of divs -- this ties into innerfade.js
    $('#fade').innerfade({
        speed: 2000,
        timeout: 8000,
        containerheight: 300,
        tracker: 'switcher',
        trackerclass: 'selected'
    });

    $('#stop').click(function() {
        clearTimeout($('#fade').data('timer'));
        $('#fade').removeData('timer');
        $('#stop').hide();
        $('#start').show();
        return false;
    });


    $('#start').click(function() {
        $('#start').hide();
        $('#stop').show();
        $('.selector').removeClass('selected');
        $('#fade').innerfade({
            speed: 2000,
            timeout: 8000,
            containerheight: 300,
            tracker: 'switcher',
            trackerclass: 'selected'
        });
        var id = $('#fade').data('next');
        $('#' + id).addClass('selected');
        return false;
    });

    $('.selector').click(function() {
        if (this.id == 'stop' || this.id == 'start') {
            return;
        }

        if($('#fade').data('timer')) {
            clearTimeout($('#fade').data('timer'));
            $('#fade').removeData('timer');
            $('#stop').hide();
            $('#start').show();
        }

        var id = Number(this.id);
        $('.selector').removeClass('selected');
        $(this).addClass('selected');
        $('#fade li:visible').fadeOut(2000);
        $('#feature_' + id).fadeIn(2000);
        var num = $('#fade').data('num_elements');
        if (id < num) {
            $('#fade').data('next', id);
        } else {
            $('#fade').data('next', 0);
        }
        return false;
    });
    
    // add social bookmarks
    $("#bookmarks").bookmark({icons: '/images/bookmarks.png', sites: ['delicious', 'digg', 'facebook', 'fark', 'google', 'kaboodle', 'mixx', 'propeller', 'reddit', 'stumbleupon', 'technorati', 'twitthis', 'yahoobuzz']});
    $("#bookmarks ul").prepend('<li class="share">Share&#160;</li>');

    $("#bookmarks2").bookmark({icons: '/images/bookmarks26.png', iconSize: 26, sites: ['yahoobuzz', 'delicious', 'digg', 'facebook', 'stumbleupon']});
    $("#bookmarks2 ul").prepend('<li class="share">Share&#160; &#160;</li>');
    
    $(".thankyoubookmarks").bookmark({
        icons: "/images/bookmarks.png", 
        sites: ["delicious", "digg", "facebook", "fark", "google", "kaboodle", "mixx", "propeller", "reddit", "stumbleupon", "technorati", "twitthis", "yahoobuzz"]
    });
    $(".thankyoubookmarks").prepend('<p><strong>Share this with your friends:</strong></p>');


    // handler for checkbox on contribute pages
    $("#id_send_tribute").click( function() {
        if ($("#id_send_tribute").attr("checked")) {
            $("#acknowledgement").show();
        } else {
            $("#acknowledgement").hide();
        }
    });
});
