Hide if subpages are shown

Doesn’t seem like you are using an if-statement for showing the sub-pages? If you are not, I guess you can do it with jQuery.

var sub = $("div.subpages");

if (sub.length > 0) {
    $("#secondary").hide(); // replace "secondary" with the ID of the sidebar
}