jQuery(document).ready(function($) {

    // fade out error message bg color
    $("#messages, #comment_errors, #comment_msgs").animate({opacity: 1.0}, 3000).animate({backgroundColor: '#ffffff'}, 3000);


    // share bookmarks on thankyou pages
    $(".thankyoubookmarks").bookmark({
        icons: "/images/bookmarks2.png", 
        sites: ["delicious", "digg", "facebook", "google", "kaboodle", "reddit", "stumbleupon", "technorati", "twitthis", "yahoobuzz"]
    });
    $(".thankyoubookmarks").prepend('<p><strong>Share this with your friends:</strong></p>');
    
    // share bookmarks in general
    $(".bookmarks").bookmark({
        icons: "/images/bookmarks2.png", 
        sites: ["delicious", "digg", "facebook", "google", "kaboodle", "reddit", "stumbleupon", "technorati", "twitthis", "yahoobuzz"]
    });
    $(".bookmarks ul").prepend('<li class="share">Share &#160;</li>');
    
    $("#bookmarks2").bookmark({
	    icons: "/images/bookmarks2.png", 
	    sites: ["delicious", "digg", "facebook", "google", "kaboodle", "reddit", "stumbleupon", "technorati", "twitthis", "yahoobuzz"]
	});

    
    // opacity effect for bookmarks
    $(".hasBookmark ul a").css("opacity", ".6");
    $(".hasBookmark ul a").hover(
        function() {
            $(this).css("opacity", "1");
        },
        function() {
            $(this).css("opacity", ".6");
        }
    );

    // 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);
    });

	// handlers for fields in testup stub form
    $("#testup_box_email, #testup_box_zip").focus(function() {
        vanilla.swapValue(this, false);
    });
    $("#testup_box_email, #testup_box_zip").blur(function() {
        vanilla.swapValue(this, true);
    });
    
    // rotating banners on homepage
    $("#fade").innerfade({
	    speed: 2000,
	    timeout: 8000,
	    containerheight: 274,
	    tracker: "switcher",
	    trackerclass: "selected",
	    repeat: 1
	});
	
	$(".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.substr(1));
	    $(".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;
	});
	
	// enable nav hover for dropdowns in IE6 -- this site uses non-standard div id
    $("#sidebar_nav li").hover(
        function () {
            $(this).addClass("over");
        },
        function () {
            $(this).removeClass("over");
        }
    );


});

// CF thermometer
vanilla.addLoadEvent(function() {
    if (typeof vanilla.cf_data == 'undefined') {
        return;
    }
    
    // we delay this a bit so the user will see the entire effect
    setTimeout(function() {
        jQuery('#cf_progress #goal').html('$' + vanilla.format_number(vanilla.cf_data.goal));
        jQuery('#cf_progress #count').html(vanilla.cf_data.count + ((vanilla.cf_data.count == 1) ? ' donor' : ' donors'));
        jQuery('#cf_progress #average').html('$' + vanilla.format_number((vanilla.cf_data.raised/20).toFixed(2)));

        jQuery("#cf_progress").progressBar({
            value    : Math.round(vanilla.cf_data.raised * 100 / vanilla.cf_data.goal),
            height   : 190,
            width    : 32,
            callback : function(config) {
                var raised = 0;
                if (config.value > 0) {
                    raised = vanilla.format_number((vanilla.cf_data.raised * (config.runningValue / config.value)).toFixed(2));
                    raised = raised.replace('.00', '');
                }
                jQuery('#cf_progress #raised').html('$' + raised);
                
                if (config.runningValue == config.max) {
                    jQuery('#cf_progress').addClass('goal_reached');
                    jQuery('#cf_progress #scale').hide();
                }
                if (config.runningValue > config.max) {
                    jQuery('#cf_progress').addClass('goal_exceeded');
                    jQuery('#cf_progress #scale').hide();
                }
            }
        });
    }, 500);
});


