$.fn.marquee = function (list) {

    $(this)
        .css('background', 'url(scripts/loader.gif) no-repeat center center')
        .each(function () {
            var target = this;

            var cursor = 0;
            var __show = function (data, onload) {
                var ant = $(target).find('> *');
                
                var sheet = $(' \
                    <div style="display: none; position: absolute; top: 0px; left: 0px; cursor: pointer; "> \
                      <div class="descripcion"> \
                        <h1>' + data.titulo + '</h1> \
                        <p>' + data.descripcion + '</p> \
                      </div> \
                    </div> \
                ')
                    .click(function () {
                        location.href = 'index.php?accion=noticias&ver=' + data.id_noticia;
                        return false;
                    })
                    .appendTo(target)
    
                sheet
                    .append(
                        $('<img src="index.php?mod=noticias_c.thumb&clave=' + data.id_noticia + '">')
                            .load(function () {
                                if($(this).data('__load'))
                                    return;
                                
                                $(this).data('__load', true)
                                
                                $(target)
                                    .css('background-position', '600px 600px')

                                ant.fadeOut('slow')

                                sheet.fadeIn('slow', function () {
                                    ant.remove();
                                    onload();
                                });
                            })
                            .each(function () {
                                if(this.complete && !$(this).data('__load'))
                                    $(this).load();
                            })
                    )
            }


            var __get = function () {
                modTT780(
                    'noticias_c.registro',
                    {
                        clave: list[cursor]
                    },
                    function (data) {
                        try {
                            data = eval('(' + data.responseText + ')')
                        }
                        catch(e) {
                            $(target).html(
                                $('<div style="position: absolute; top: 50%; left: 50%; text-align: center; margin-top: -6px; margin-left: -50px; ">Ha ocurrido un error</div>')
                            )
                            return;
                        }

                        __show(data, function () {
                            cursor++;
                            if(cursor >= list.length)
                                cursor = 0;

                            setTimeout(__get, 5000)
                        });
                    }
                )
            }

            __get();
        })
}

