﻿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_count = typeof infoit_count == 'number' ? infoit_count == 0 ? 'no-fainfoit-count' : '' : '';
infoit_summary = typeof infoit_summary == 'number' ? infoit_summary == 0 ? 'no-fainfoitSummary' : '' : '';
infoit_theme = typeof infoit_theme == 'string' ? infoit_theme != 'fainfoit-widget-unstyled' ? 'fainfoit-widget ' + infoit_theme : infoit_theme : 'fainfoit-widget fainfoit-widget-theme1';
infoit_title = typeof infoit_title == 'string' ? infoit_title : 'SOCIAL NEWS';
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="fainfoit-widget-header" ' + infoit_customHeader + '><h1><a href="http://fai.informazione.it" title="fai.informazione.it - Social News"></a></h1></div>');
document.write('<div class="fainfoit-widget-topic" ' + infoit_customTopic + '>' + infoit_title + '</div>');
document.write('<ul style="height: ' + infoit_height + ';' + infoit_customBody + '" class="'+ infoit_count + ' ' + infoit_summary + '"></ul>');
document.write('<div class="fainfoit-widget-footer"' + infoit_customFooter + '></div></div>');

function __infowid(obj) {
    if (!$j) setTimeout(function() { __infowid(obj); }, 200); 
    $j('#' + infoit_id + ' ul').html('');
    var s = '';
    var d = 'display:none;';
    var wvote = '';
    var tpl = function() {
        return [
            'li', {}, [
                'a', { 'href': this.Url, 'class': 'fainfoit-count' }, this.VoteCount + ' <span>' + wvote + '</span>',
                'h3', {}, [
                    'a', { 'href': this.Url, 'target': infoit_target, 'style': 'color: ' + infoit_customLink + ' ' }, this.Title,
                    'span', { 'style': d }, s
                ],
                'p', {}, this.Description,
                
            ]
        ];
    };
    if (!obj) {
        $j('#' + infoit_id + ' ul').html('Non è stato possibile acquisire le notizie da fai.informazione.it. Suggeriamo di riprovare, riaggiornando la pagina.');
    }
    if (!obj || obj.length == 0) {
        $j('#' + infoit_id + ' ul').html('Al momento, su fai.informazione.it non sono disponibili notizie del tipo richiesto.');
    }
    if (obj) {
        if (infoit_summary != '' )
            d = '';
        for (var i = 0; i < obj.length; i++) {
            s = '';
            if (d == '')
                s = ' - ' + obj[i].WhenPosted;
            else
                obj[i].Description += ' - ' + obj[i].WhenPosted;
            wvote = obj[i].VoteCount == 1 ? 'voto' : 'voti';
            $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) });
    }
}
