$(function() {
$('div[class^="class"]').each(function(i, elem) {
var el = $('.' + elem.className).not(elem).parent();
$(elem).click(function() {
el.toggleClass('active');
}).on('mouseenter mouseleave', function() {
el[e.type == 'mouseenter' ? 'addClass' : 'removeClass']('active_hover');
});
});
});