Just a quick tip to extend jQuery so you can set or unset a class to an element (or group of elements) depending on a boolean condition :

$.fn.setClass = function(myclass, action) {
    this.hasClass(myclass) == !! action || this.toggleClass(myclass);
    return this;
};

// Then do
$('#myelement').setClass('americaine', myBooleanFunction());