
/*
q is the bug query: defaults to open bugs
div is the div to append the results to: defaults to 'bug_list'
bug_dispay is a string that will be converted into a jquery template

widget.css styles the output via class bug_display
 */

function bugWidget(q, div, bug_display){

		console.log("Calling bugWidget");

		// define the default query
        if (!q){
            q= 'status?q=open';
        }

		// define the default div name that holds the bugs.
        if(!div){
            div= '#bug_list';
        }
        
		// define the default template for a bug
        if(bug_display== null){

           var bug_display= '<h1><a href=${permalink}>${headline}</a></h1>';
			bug_display = bug_display + '<span class="bug_target">Error report for <a href="${pub_link}">${pub_title}</a></span>';
			bug_display = bug_display + '<span class="bug_date">${date}</span>';
			bug_display = bug_display + '<span class="bug_status"><img src="${status_img_20}" alt="${bug_status}" align="absmiddle" width="20" height="20" />&nbsp;${bug_status}</span>';

        }
        
        bug_display= "<div class='bug_display'>"+bug_display+"</div>";
        var t    = $.template(bug_display);
        

		// do the AJAX/JSONp call to the mediabugs server.
		
		$.getJSON('http://mediabugs.org/bugs/json/'+q+'&jsoncallback=?',function(json) {
	            for (var x in json) {
	                var bug = json[x];
	                $(div).append(t, bug);
	            }
		});

 };


