// <meta name="robots" content="noindex,nofollow">
document.write('<script type="text/javascript" src="http://bytheboxes.com/javascripts/jquery.js"></script>');
document.write('<script type="text/javascript" src="http://bytheboxes.com/javascripts/jquery-dom.js"></script>');
document.write('<link rel="stylesheet" type="text/css" media="all" href="http://bytheboxes.com/stylesheets/widget.css" />');
document.write('<!--[if lte IE 6]><link rel="stylesheet" type="text/css" media="all" href="http://bytheboxes.com/stylesheets/widget_ie.css" /><![endif]-->');



var start = new Date();
var uniq_id = Math.round(start.getTime()*Math.random());

app_domain = typeof app_domain == 'string' ? app_domain : 'bytheboxes.com';

btboxes_width = typeof btboxes_width == 'string' ? btboxes_width : '450px';
btboxes_height  = typeof btboxes_height  == 'string' ? btboxes_height  : '280px';  // TODO
btboxes_title_height  = typeof btboxes_title_height  == 'string' ? btboxes_title_height  : '37px';  // TODO
btboxes_border  = typeof btboxes_border  == 'number' ? btboxes_border  : 1;
btboxes_count = typeof btboxes_count  == 'number' ? 'no-btboxes-count'  : '';


btboxes_description = typeof btboxes_description  == 'number' ? ''  : 'no-btboxes-description';
btboxes_box_title = typeof btboxes_title  == 'title' ? ''  : 'untitled';
btboxes_theme = typeof btboxes_theme  == 'string' ? btboxes_theme  != 'btboxes-widget-unstyled' ? 'btboxes-widget '+btboxes_theme : btboxes_theme  : 'btboxes-widget btboxes-widget-theme1';
// btboxes_title = typeof btboxes_title  == 'string' ? btboxes_title  : 'All popular stories in All Topics';
btboxes_custom_header = typeof btboxes_custom_header  == 'string' ? 'background: '+btboxes_custom_header+';'  : '';
btboxes_custom_border = typeof btboxes_custom_border  == 'string' ? 'border-color: '+btboxes_custom_border+';'  : '';
btboxes_custom_link = typeof btboxes_custom_link  == 'string' ? btboxes_custom_link  : '';
btboxes_custom_hoverlink = typeof btboxes_custom_hoverlink  == 'string' ? btboxes_custom_hoverlink  : '';
btboxes_custom_footer = typeof btboxes_custom_footer  == 'string' ? ' style="color: '+btboxes_custom_footer+'"'  : '';



document.write('<div id="btboxes-widget-container'+uniq_id+'" class="'+btboxes_theme+'" style="width: '+btboxes_width+'; border-width: '+btboxes_border*7+'px; '+btboxes_custom_border+' '+btboxes_custom_header+'">');
document.write('<div class="btboxes-widget-topic" id="box-title"></div>');
document.write('<div class="btboxes-widget-subtopic" id="box-subtitle"></div>');
document.write('<div class="btboxes-widget-header" style="'+btboxes_custom_header+'"><h1><a href="http://'+app_domain+'/?BTB-widget-widget"></a></h1><div><a href="http://'+app_domain+'/?BTB-widget">Get a Widget</a></div></div>');
document.write('<ul style="margin-left:10px;margin-top:15px;" class="'+btboxes_count+' '+btboxes_description+'"></ul>');
document.write('<div class="clear-it" style="clear:both;"><!-- --></div>')
document.write('<div class="btboxes-widget-footer" style="margin-top:16px;"><a href="http://'+app_domain+'/?BTB-widget"'+btboxes_custom_footer+'>Powered by byTheBoxes</a></div></div>');


function btboxeswb(obj) {
    $j('#btboxes-widget-container'+uniq_id+' #box-title').html('<a href="http://'+app_domain+'/boxes/'+ obj.id + obj.url_name +'">'+ obj.title + '</a>');
    $j('#btboxes-widget-container'+uniq_id+' #box-subtitle').html(obj.subtitle);
    $j('#btboxes-widget-container'+uniq_id+' ul').html('');
    var tpl = function() {
        return [
            'li', { 'class': 'number_item' }, [
                'div', { 'class': 'number_box', 'style':'background:'+ this.background +' url(http://'+app_domain+'/corners/rnd_'+ this.color_name +'_03.gif) no-repeat bottom left;float:left;'+ this.box_size }, [
                'dl', { 'class': 'color_'+ this.color, 'style': 'background:  url(http:\/\/'+app_domain+'\/corners\/rnd_'+ this.color_name +'_01.gif) no-repeat top left;' }, [
                  'dt', { 'style':'background: url(http:\/\/'+app_domain+'\/corners/rnd_'+ this.color_name +'_02.gif) no-repeat top right;'+ this.number_font_size }, [ 'a', { 'href': this.href+'?BTB-widget', 'class': 'btboxes-count' }, '<span>'+ this.value_prefix +'</span>' + this.value_raw + '<span>'+ this.value_suffix +'</span>' ,
                    ] , 
                  'dd', {'style':'background: url(http:\/\/'+app_domain+'\/corners\/rnd_'+ this.color_name +'_04.gif) no-repeat bottom right;'}, [ 'a', { 'href': this.href+'?BTB-widget', 'class': 'btboxes-count' }, this.title ,
                    ],
                  ],
                ],
                'p', {}, this.description
            ]
        ];
    };
    if(!obj) {
        $j('#btboxes-widget-container'+uniq_id+' ul').html('We were unable to retrieve this box from byTheBoxes.  Please refresh the page to try again.');
    }
    if(!obj.numbers || obj.numbers.length == 0) {
        $j('#btboxes-widget-container'+uniq_id+' ul').html('Currently, these boxes do not exist on byTheBoxes.');
    }

    for (var i = 0 ; i < obj.numbers.length ; i++) {
            if(obj.numbers[i].sferes > 10000) {
                obj.numbers[i].sferes = Math.floor(obj.numbers[i].btboxess/1000)+'K+';
            }
            $j('#btboxes-widget-container'+uniq_id+' ul').tplAppend(obj.numbers[i], tpl);
    }

    
    if(btboxes_custom_hoverlink != '') {
        $j('#btboxes-widget-container'+uniq_id+' ul a').hover(function(){$j(this).css('color',  btboxes_custom_hoverlink)}, function() {$j(this).css('color',  btboxes_custom_link)});
    }
}
