document.write('<link rel="stylesheet" type="text/css" media="all" href="http://digg.com/css/widget.css" />');
function diggwb(obj) {
    $('#'+digg_id+' ul').html('');
    var tpl = function() {
        return [
            'li', {}, [
                'a', { 'href': this.href+'?OTC-widget', 'class': 'digg-count' }, this.diggs+' <span>diggs</span>',
                'h3', {}, [
                    'a', { 'href': this.href+'?OTC-widget', 'target':  digg_target, 'style': 'color: '+digg_custom_link+' ' }, this.title
                ],
                'p', {}, this.description
            ]
        ];
    };
    if(!obj) {
        $('#'+digg_id+' ul').html('We were unable to retrieve matching stories from Digg. Please refresh the page to try again.');
    }
    if(!obj.stories || obj.stories.length == 0) {
        $('#'+digg_id+' ul').html('Currently, there are no recent stories of this type on Digg.');
    }
    for (var i = 0 ; i < obj.stories.length ; i++) {
            if(obj.stories[i].diggs > 10000) {
                obj.stories[i].diggs = Math.floor(obj.stories[i].diggs/1000)+'K+';
            }
            $('#'+digg_id+' ul').tplAppend(obj.stories[i], tpl);
    }
    if(digg_custom_hoverlink != '') {
        $('#'+digg_id+' ul a').hover(function(){$(this).css('color',  digg_custom_hoverlink)}, function() {$(this).css('color',  digg_custom_link)});
    }
}

digg_width = typeof digg_width == 'string' ? digg_width : '300px';
digg_height  = typeof digg_height  == 'string' ? digg_height  : '350px';
digg_border  = typeof digg_border  == 'number' ? digg_border  : 1;
digg_target  = typeof digg_target  == 'number' ? '_blank' : '';
digg_count = typeof digg_count  == 'number' ? 'no-digg-count'  : '';
digg_description = typeof digg_description  == 'number' ? ''  : 'no-digg-description';
digg_theme = typeof digg_theme  == 'string' ? digg_theme  != 'digg-widget-unstyled' ? 'digg-widget '+digg_theme : digg_theme  : 'digg-widget digg-widget-theme1';
digg_title = typeof digg_title  == 'string' ? digg_title  : 'All popular stories in All Topics';
digg_custom_header = typeof digg_custom_header  == 'string' ? 'background: '+digg_custom_header+';'  : '';
digg_custom_border = typeof digg_custom_border  == 'string' ? 'border-color: '+digg_custom_border+';'  : '';
digg_custom_link = typeof digg_custom_link  == 'string' ? digg_custom_link  : '';
digg_custom_hoverlink = typeof digg_custom_hoverlink  == 'string' ? digg_custom_hoverlink  : '';
digg_custom_footer = typeof digg_custom_footer  == 'string' ? ' style="color: '+digg_custom_footer+'"'  : '';
digg_id = typeof digg_id  == 'string' ? ''+digg_id+''  : 'digg-widget-container';

document.write('<div id="'+digg_id+'" class="'+digg_theme+'" style="width: '+digg_width+'; border-width: '+digg_border*7+'px; '+digg_custom_border+' '+digg_custom_header+'">');
document.write('<div class="digg-widget-header" style="'+digg_custom_header+'"><h1><a href="http://www.digg.com/?OTC-widget">Digg</a></h1><div><a href="http://digg.com/add-digg?OTC-widget">Get a Widget</a></div></div>');
document.write('<div class="digg-widget-topic">'+digg_title+'</div>');
document.write('<ul style="height: '+digg_height+';" class="'+digg_count+' '+digg_description+'"></ul>');
document.write('<div class="digg-widget-footer"><a href="http://www.digg.com/?OTC-widget"'+digg_custom_footer+'>Powered by Digg\'s Users</a></div></div>');