﻿infoit_width = typeof infoit_width == 'string' ? infoit_width : '300px';
infoit_height = typeof infoit_height == 'string' ? infoit_height : '350px';
infoit_border = typeof infoit_border == 'number' ? infoit_border : 1;
infoit_target = typeof infoit_target == 'number' ? '_blank' : '';
infoit_showPics = typeof infoit_showPics == 'number' ? infoit_showPics : 1;
infoit_summary = typeof infoit_summary == 'number' ? infoit_summary == 0 ? 'no-infoitSummary' : '' : '';
infoit_theme = typeof infoit_theme == 'string' ? infoit_theme != 'infoit-widget-unstyled' ? 'infoit-widget ' + infoit_theme : infoit_theme : 'infoit-widget infoit-widget-theme1';
infoit_title = typeof infoit_title == 'string' ? infoit_title : 'TODAS LAS SECCIONES - ÚLTIMAS NOTICIAS';
infoit_customHeader = typeof infoit_customHeader == 'string' ? ' style="background: ' + infoit_customHeader + '"' : '';
infoit_customTopic = typeof infoit_customTopic == 'string' ? ' style="background: ' + infoit_customTopic + '"' : '';
infoit_customBody = typeof infoit_customBody == 'string' ? 'background: ' + infoit_customBody + ';' : '';
infoit_customBorder = typeof infoit_customBorder == 'string' ? 'border-color: ' + infoit_customBorder + ';' : '';
infoit_customLink = typeof infoit_customLink == 'string' ? infoit_customLink : '';
infoit_customHoverLink = typeof infoit_customHoverLink == 'string' ? infoit_customHoverLink : '';
infoit_customFooter = typeof infoit_customFooter == 'string' ? ' style="background: ' + infoit_customFooter + '"' : '';
infoit_id = typeof infoit_id == 'string' ? '' + infoit_id + '' : 'widgetContainer';

document.write('<div id="' + infoit_id + '" class="' + infoit_theme + '" style="width: ' + infoit_width + '; border-width: ' + infoit_border * 7 + 'px; ' + infoit_customBorder + '">');
document.write('<div class="infoit-widget-header" ' + infoit_customHeader + '><h1><a href="http://www.mokanews.es" title="mokanews.es - Aggregazione Notizie"></a></h1></div>');
document.write('<div class="infoit-widget-topic" ' + infoit_customTopic + '>' + infoit_title + '</div>');
document.write('<ul style="height: ' + infoit_height + ';' + infoit_customBody + '" class="' + infoit_summary + '"></ul>');
document.write('<div class="infoit-widget-footer"' + infoit_customFooter + '></div></div>');

function __infowid(obj) {
    if (!$j) setTimeout(function() { __infowid(obj); }, 200); 
    $j('#' + infoit_id + ' ul').html('');
    var s = '';
    var tpl = function() {
        return [
            'li', {}, [
                'div', { 'class': infoit_pics }, ['a', { 'href': this.Url, 'target': infoit_target }, '<img src="' + this.ImageUrl + '" width="50px" height="50px" align="left" title="Foto: ' + this.ImagePublication + '"/>'],
                'h3', {}, [
                    'a', { 'href': this.Url, 'target': infoit_target, 'style': 'color: ' + infoit_customLink + ' ' }, this.Title
                ],
                'p', {}, this.Incipit,
                'span', {}, s
            ]
        ];
    };
    if (!obj) {
        $j('#' + infoit_id + ' ul').html('No ha sido posible adquirir las noticias de Mokanews. Sugerimos probar de nuevo, actualizando la página.');
    }
    if (!obj || obj.length == 0) {
        $j('#' + infoit_id + ' ul').html('En la categoría indicada, no es disponible alguna noticia.');
    }

    if (obj) {
        for (var i = 0; i < obj.length; i++) {
            s = '';
            if (obj[i].TotalNumberOfArticles > 1) {
                if (obj[i].TotalNumberOfArticles == 2)
                    obj[i].TotalNumberOfArticles = " y un otro artículo";
                else
                    obj[i].TotalNumberOfArticles = ' y otros ' + (obj[i].TotalNumberOfArticles - 1) + ' artículos';
            }
            else
                obj[i].TotalNumberOfArticles = '';
            var h =' (de ' + obj[i].Source + obj[i].TotalNumberOfArticles + ' - ' +obj[i].ReleasedOn+')';
            if (infoit_summary == '')
                obj[i].Incipit += h;
            else
                s=h;
            if (infoit_showPics==0 || (infoit_showPics==1 && obj[i].ImageUrl.length == 0))
                infoit_pics = 'no-infoit-pics';
            else
                infoit_pics = 'infoit-pics';
            $j('#' + infoit_id + ' ul').tplAppend(obj[i], tpl);
        }
    }

    if (infoit_customHoverLink != '') {
        $j('#' + infoit_id + ' ul a').hover(function() { $j(this).css('color', infoit_customHoverLink) }, function() { $j(this).css('color', infoit_customLink) });
    }
}
