 $(document).ready(function(){
        var tamanio_caja=620;                          // tamanio de los bloques del slide
        var ancho_total = 0;        
        var $slidem = $("#slidem");                      //elemento slider

        var cantidad = $slidem.children().length;   // cantidad de elementos en el slider
        ancho_total = (cantidad * tamanio_caja);    // ancho del contenedor ( slider)
        $slidem.css("width",ancho_total+"px");

        slide_destacados();
        var id_intervalo = setInterval(animar_auto,get_interval_slider());

        // funcion para crear los elementos del slider
        function slide_destacados(){
            //var tamanio_caja = 780;
            var cantidad = $slidem.children().length;   // cantidad de elementos en el slider
            ancho_total = (cantidad * tamanio_caja);    // ancho del contenedor ( slider)
            $slidem.css("width",ancho_total+"px");

            $("#contenedor_noticias_destacado").append("<div id='ul_headline'></div>");

            for(i=1;i<=cantidad;i++){
                $("#ul_headline").append("<span><a class='hlindicador' id='slide_"+i+"' href='#'>"+i+"</a></span>");
            }

            $("#ul_headline")
                .find("span:first").addClass("activo").end()
                .find("a").click(function(clic){
                    clearInterval(id_intervalo);                    //cancelacion del intervalo automatico
                    id_intervalo = setInterval(animar_auto,get_interval_slider());   //nuevo intervalo automatico
                    clic.preventDefault();
                    var $this = $(this);
                    $this.parent()
                        .addClass("activo")
                        .siblings().removeClass("activo");
                    var posicionf=(parseInt($this.attr('id').replace(/\D/g, ""), 10) - 1) * tamanio_caja * -1;
                   // $slidem.stop().animate({left:posicionf+"px"},'slow');
                    $slidem.fadeOut('fast',function(){
                        $(this).css("left",posicionf+"px").fadeIn();
                    });


                });
        }

        function get_interval_slider() {
            return window._interval_slider ? Math.max(window._interval_slider, 3000) : 8000;
        }

        // slider funcione automaticamente
        function animar_auto(){
               pos = $slidem.position().left-tamanio_caja;
               if ( pos-tamanio_caja < (ancho_total*-1))
                   pos=0;

                w = Math.abs(pos/tamanio_caja)+1;
                 //w = "#headline_"+constr;
                $("#slide_"+w).parent()
                    .addClass("activo")
                    .siblings().removeClass("activo");

               //$slidem.stop().animate({left:pos+"px"},'slow');
                   $slidem.fadeOut('fast',function(){
                            $(this).css("left",pos+"px").fadeIn();
                        });
               //$slidem.fadeOut().css("left",pos+"px").fadeIn();
        }
});
    
