dojo.declare("com.mgh.ArchiveCategories",[com.mgh.Categories], {
	constructor : function(configParams) {

	},

	updateQuery : function()
	{
		var m = this.queryParams;
		this.query = m.href + '?az=' + m.az + '&age=' + m.age + '&cat=' + m.cat +  '&subcat=' + m.subcat + '&type=' + m.type + '&query=' + m.query + 
		'&month=' + (m.month + 1) + '&audience=' + m.audience + '&eventType=' + m.eventType + '&mediaType=' + m.mediaType + '&newsType=' + m.newsType + 
		'&year=' + m.year + '&topic=' + m.topic;
		//alert(this.query);
	}, 
		
 	buildCategories : function (){
		var i;
		//removes all category names from display
		var regEx = /\(.*\)/;
		var myCategories = this.categories.getElementsByTagName("NAME");
		var myCatIds = this.categories.getElementsByTagName("ID");
		var output = '<h3>Type:</h3>';
	    //output += '<ul>';
	    
		if (this.linksToDisplay > myCategories.length){
			this.linksToDisplay = myCategories.length;
		}        
	    var trimmed = '';
	    var rows = 0;

		var sortedCats = new Array();

		//first store the category and its ids and sort this new array
		for (i=0; i<myCategories.length; i++){
			sortedCats[i] = myCategories[i].childNodes[0].nodeValue + '|' + myCatIds[i].childNodes[0].nodeValue;
		}
			
		sortedCats = sortedCats.sort();
			
        // now with the ids sorted, use the sorted categories arrray to get an alphabetized list. use the 
        // sortedCats array instead of the original nodeList elements myCats and myCatIds

        //output += '<table width="100%" border="0" cellspacing="5" cellpadding="5" valign="top">'
        //output += '<tr>';
        for (var x=0; x < 3; x++){
	    	//output += '<td width="33%" valign="top">';
	    	output += '<ul>';        	
	        for (i=rows; i < (this.linksToDisplay * (x+1)); i++){
				try {
		        	trimmed = sortedCats[i].split('|')[0].replace(regEx,'');
		        	output += '<li><a href="#" onclick="filterArchiveByCategory(\''+
		        	sortedCats[i].split('|')[1] + '\'); updateArchiveCategories(\'' + 
		        	sortedCats[i].split('|')[1] +'\',\'' + 
		        	trimmed + '\')">' + 
		        	trimmed + '</a></li>';
		        	rows +=1;
		        	if (i > (this.linksToDisplay *3)-1){
						output += '<li><a href="#" class="goBack" onclick="buildHiddenPanel(\'categoriesContent\',\'categories\'); dijit.byId(\'categoriesDialog\').show()">Display All</a></li>';		        		
		        	}
				} catch (e) {
					break;
				} 
	        }
	    	output += '</ul>';
	    	//output += '</td>';	        
        }
        //output += '</tr>';
        //output += '</table>';
		dojo.byId('filter1').innerHTML = output;	
	},
	
	updateCategories : function (id,nodeName){
		//console.log(id + ' update categories ' + nodeName);
		var output = '<h3>Type:</h3>';
        output += '<ul>';
		var nodes = dojo.query('li', id);
		output += '<li id="' + nodeName + '" class="active"><strong>' + nodeName + '</strong></li>';
		output += '<li><a href="#" class="goBack" onclick="removeFilter(\'archiveCategories\')">Show all</a></li>';
		output += '</ul>'
		dojo.byId('filter1').innerHTML = output;
		this.previousCat = id;
	}	
});