//Ext.BLANK_IMAGE_URL = 'images/default/s.gif';

var nitems;
var News = function () {
    return {
        init: function () {
            var nid = gup("nid");
            if (nid=="") {
                News.getHelpItems();
            } else {
                News.displayHelp(nid);
            }
        }, // end init
        
        getHelpItems: function() {
            new Ajax.Request('News?action=b', {
                method:'get',
                onSuccess: function(transport){
                    nitems = transport.responseText.evalJSON();

                    var histr = "";

                    nitems.news.each(function(n){
                        histr += '<div class="news-summary">';
                        histr += '<h3><a href="news.jsp?action=b&nid=' + n.nid + '">' + n.ntitle + '</a></h3>';
                        histr += '<p><span class="news-date">' + n.datestart + '</span></p>';
                        histr += '<p>' + n.nteaser + '</p>';
                        histr += '</div>';
                    });

                    //console.log("adding items:");
                    //console.log(histr);

                    $('nitems').update(histr);
                }
            });

        }, // end getHelpItems

        displayHelp: function(nid) {
            new Ajax.Request('News?action=b&nid='+nid, {
                method:'get',
                onSuccess: function(transport){
                    nitems = transport.responseText.evalJSON();

                    var histr = "";

                    nitems.news.each(function(n){
                        histr += '<div class="news-detail">';
                        histr += '<h3>' + n.ntitle + '</h3>';
                        histr += '<p><span class="news-date">' + n.datestart + '</span></p>';
                        histr += '<p>' + n.nbody + '</p>';
                        histr += '</div>';
                    });

                    histr += '<p><a href="news.jsp">&lt; Back to News</a></p>';

                    //console.log("adding items:");
                    //console.log(histr);

                    $('nitems').update(histr);
                }
            });

        } // displayHelp
    };  // end return
}();  // end News
//Ext.onReady(News.init, News, true);
window.onload = News.init; 

// from http://www.netlobo.com/url_query_string_javascript.html
function gup(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
