document.write('<script type="text/javascript" src="http://media.digg.com/js/loader/219/JS_Libraries,jquery|jquery-dom"></script>');
document.write('<link rel="stylesheet" type="text/css" media="all" href="/hr/inc/css/digg_widget.css" />');

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+'">');
document.write('<div class="digg-widget-header" style="'+digg_custom_header+'"><h1><a href="http://digg.com/?OTC-widget">Digg</a></h1><div><a href="http://digg.com/tour?OTC-widget">What is Digg?</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"></div></div>');

function diggwb(obj) {
    if (!$) setTimeout(function() { diggwb(obj); }, 200); //hack for IE not loading scripts that are included via document.write until it decides too
    $('#'+digg_id+' ul').html('');
    var tpl = function() {
		if(this.thumbnail)
        return [
            'li', {}, [
                'a', { 'href': this.href+'?OTC-widget', 'target':  digg_target, 'class': 'digg-count' }, this.diggs+' <span>diggs</span>',
				'img', {'src' : this.thumbnail.src, 'class': 'diggImg'}, '',
                'h3', {}, [
                    'a', { 'href': this.href+'?OTC-widget', 'target':  digg_target, 'style': 'color: '+digg_custom_link+' ' }, this.title
                ],
                'p', {}, this.description
            ]
        ];
		else
			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.');
    }
    if (obj.stories) {
        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)});
    }
}
function swapTabs_digg(tab1,tab2){
	document.getElementById('digg-widget-'+tab1).style.display = "none";
	document.getElementById('digg-widget-'+tab2).style.display = "block";
	document.getElementById('li_'+tab1).className = "";
	document.getElementById('li_'+tab2).className = "active";
}