//var $menu=new Array("cell1","cell2","cell3","cell4","cell5","cell6");

function load_submenu(brand, cell){
    if(brand==null){
        return;
    }
    $.ajax({
        type: "POST",
        url: "actions.php",
        data: "action=GET_BRAND_CATEGORIES&brand="+brand,
        cache: false,
        dataType: "json",
        success: function(result){
            mark_selected_brand(cell);
            $("#submenu").html("&nbsp;");
            try{
                show_submenu(result["elements"],result["idbrand"]);
            }catch(err){}
        }
    });

}

function mark_selected_brand(cell){
    var $cell=null;
    //unselect
    $("#row3 > div").each(function(){
        $(this).removeClass("bleft");
        $(this).removeClass("bright");
        $(this).css({"height":""});
    });


    //select
    $cell=$("#row3 > #"+cell);
    $cell.removeClass("bbottom");
    $cell.addClass("bleft bright");
    $cell.css({"height":"17px"});
}

function show_submenu(elements, brand){
    i=0;html="";

    if(elements==null){
        return;
    }

    while(i<elements.length){
        html+="<li><a href='prod_list.php?action=clear&id_brand="+brand+"&id_category="+elements[i].id+"'>"+elements[i].name+"</a></li>";
        i++;
    }
    $("#submenu").html(html).show("slow");
}

function set_selected_brand(brand){
    if(brand==null || brand==""){
        return;
    }
    $("#row3 > div").each(function(){
        if($(this).text().toLowerCase()==brand.toLowerCase()){
            load_submenu(brand, $(this).attr("id"));
            return;
        }
    })
}

function mark_selected_category(category){
    if(category==null || category==""){
        return;
    }
    $("#submenu > li").each(function(){
        $link=$(this).html();
        if($link.indexOf("id_category="+category)>0){
            $(this).children().addClass("selected");
        }
    })
}