vanilla.switchStyles = function(styleName) {
    jQuery("link[@rel*=style][title]").each(function(i) {
        this.disabled = true;
        if (this.getAttribute('title') == styleName) this.disabled = false;
    });
    vanilla.cookie.set('style', styleName, 365, '/');
};


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

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


    // share bookmarks on thankyou pages
    $(".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>');
    
    // share bookmarks in general
    $(".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>');
    

    // 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);
    });
    
    // style switcher
    $("#textsize a").click(function() {
        vanilla.switchStyles(this.getAttribute("rel"));
        return false;
    });
    var style = vanilla.cookie.get("style");
    if (style) vanilla.switchStyles(style);
    
    // hide empty boxes in the resource center sidebar
    $('#sidebar .resourcebox .archivebox').not(':contains("More")').parent().hide();
    
    // hide empty content on profile dashboard
    $('body.profile_form div.field_content div.content:empty').parent().hide();
    
    // fix iframe thickbox escape key
    $(this).keydown(function(e){
        if (e == null) { // ie
            keycode = event.keyCode;
        } else { // mozilla
            keycode = e.which;
        }
        if(keycode == 27){ // close
            top.tb_remove();
        }
    });
    
    // rounded corners
    var roundStr = '<b class="cn tl"></b><b class="cn tr"></b><b class="cn bl"></b><b class="cn br"></b>';
    jQuery("#form").addClass("boxc").append(roundStr);
    jQuery("#form .innerform").addClass("boxc").append(roundStr);
    
});
