$(function(){
    
    $("#q").focus();
    
    if($("#q").val() == ''){
        $("#q").addClass("bg_texto");
    }
    
    $("#q").keyup(function (event){
        if($("#q").val() != ''){
            $(this).removeClass("bg_texto");    
        }else{
            $(this).addClass("bg_texto");
        }
    }).keydown(function (event){
        if($("#q").val() != ''){
            $(this).removeClass("bg_texto");    
        }else{
            $(this).addClass("bg_texto");
        }
    });
    
    $('ul.estados li:has(ul)').hover( 
      function(e){ 
         $("#estado").removeClass("down");
         $("#estado").addClass("up");
         $(this).find('div').css({display: "block"}); 
         $(this).find('ul').css({display: "block"}); 
      }, 
      function(e){ 
         $("#estado").removeClass("up");
         $("#estado").addClass("down");
         $(this).find('div').css({display: "none"});
         $(this).find('ul').css({display: "none"}); 
      } 
   ).click(function (){
        $(this).find('div').css({display: "none"});
        $(this).find('ul').css({display: "none"});
   });
    
    $(".li_estado").click(function(evento){
        evento.preventDefault();
        var ID = $(this).attr("name");
        $("#es").val(ID);
        document.getElementById("estado").innerHTML = document.getElementById("li_"+ID).innerHTML;
    });
});
