var secondBar = false;
var btnCollapseSecondBar = false;
var secondBarCollapse = false;

var iptGrpOrder = false;

$(document).ready( function() {
    // COLLAPSE
    secondBar = $("div.secondbar");
    btnCollapseSecondBar = $("div.secondbar button.navbar-toggle");
    secondBarCollapse = $("div.secondbar div.navbar-collapse");
    if(secondBar.length>0 && secondBarCollapse.length>0 && btnCollapseSecondBar.length>0) initSecondBarCollapse();
    
    // ORDER
    iptGrpOrder = $("div.secondbar div.input-group.order");
    if(secondBar.length>0 && iptGrpOrder.length>0) initIptGrpOrder();
});

function initSecondBarCollapse() {    
    btnCollapseSecondBar.click(function(e) {
        e.preventDefault();
        $(this).blur();
        if(secondBarCollapse.hasClass("collapse")) secondBarCollapse.removeClass("collapse");
        else secondBarCollapse.addClass("collapse");
    })
}

function initIptGrpOrder() {
    iptGrpOrder.find("select").change(function(e) {
        $(this).blur();
        document.location = "?order="+$(this).val();
    });
    
    iptGrpOrder.find("button").click(function(e) {
        e.preventDefault();
        $(this).blur();
        $sens = $(this).hasClass("ASC") ? "DESC" : "ASC";
        document.location = "?sens="+$sens;
    });
}