Use hasClass
if(!$(this).hasClass('.active') )
{
$(this).animate({width: "400px"}, 300);
$(this).addClass('active');
$(activePanel).animate({width: "60px"}, 300);
activePanel = this;
$('.close').css({display: "block"});
}
Edit
I've updated your code provided in the fiddle
$(document).ready(function () {
activePanel = $("#accordion div.panel:first");
$(activePanel).addClass('active');
$(".panel").click(function () {
if ($(this).not('.active')) {
$(".active").animate({
width: "60px"
}, 300);
if ($(this).css("width") == "400px") {
$(this).animate({
width: "60px"
}, 300);
$('.close').hide();
} else {
$(this).animate({
width: "400px"
}, 300);
$('.close').show();
}
$(this).addClass("active");
}
});
$(".close").click(function (e) {
e.stopPropagation();
$(this).hide();
$(".active").animate({
width: "60px"
}, 300);
});
});