dojo.declare("com.mgh.Multimedia",[com.mgh.Search], {
	constructor : function(configParams) {
		// this class has an empty constructor because, although the values are initialized, no action is needed
		// until a category is clicked
		//accept a json object with all necessary constructor values
		//this.queryParams = configParams;
		this.newsArchive = new Array();
		this.currentYear = 0;
		this.urlRoot = "http://www.massgeneral.org/";
		this.url = 'news/multimedia.aspx?id=';
		this.currentPage = 0;
	},
	
	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;
	},
	
	refreshView : function (num){
		try{
			this.gotoPage(num);
		} catch (e) {
			console.log(e);
		}
	},

	defaultView : function(){
		try{
			this.gotoPage(0);
						
		} catch (e) {
			console.log(e);
		}
	},
	
	gotoPage : function (start){
		var page = this.displayResults(start,'',0);
		this.currentPage = start;
		var paging = this.createPaging(start);
		dojo.byId('browseResults').innerHTML = page;	
		dojo.byId('pagingTop').innerHTML = paging;
		dojo.byId('pagingBottom').innerHTML = paging;			
	},	
	
	displayResults : function (id,type,year){
		var i;
		var text = '';
		var text2 = '';
		var output = '';
		var letter = '';
		var nextLetter = '';
		var css = '';
		var counter = 0;
		var description = '';
		var physicianTableClass = 'physicianTable';
		var upperLimit;
		var ids;
		var dateYear = '';
		var nextDateYear = '';
		var currentYear;
		
		if (type != 'letter'){
			upperLimit = id + this.queryParams.numPerPage;		
		} else {
			//this is the point where elements can be sorted by date. 
			letter = String.fromCharCode(id);
			ids = this.letters[letter].split(',');
			if (this.letters[letter] != ''){
				id = parseInt(ids[0]);
			 	upperLimit = id + ids.length;
			}
		}

		var elements = new Array();
		var names = this.xmlDoc.getElementsByTagName('NAME');
		var metaTags = this.xmlDoc.getElementsByTagName('METADATA');
		var mediaId;
		var mediaDisplay;
		var mediaLength;
		var description;
		var metaTags;		
		
		output += '<div id="resultsGroup">';
		output += '<ul id="resultsList">';			
		for (i=id; i < upperLimit; i++){
			try {
				current = i;
				name = names[current].childNodes[0].nodeValue.split('|')[0];
				mediaId = this.getNodeData(metaTags[current],'MediaID');
				mediaLength = this.getNodeData(metaTags[current],'Length');
				mediaDisplay = this.getNodeData(metaTags[current],'MediaDisplay');
				description = this.getNodeData(metaTags[current],'Description');

				text += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
				text += '<tr>';
				text += '<td class="searchDescription">';
				
				text2 +='<div id="mediaDisplay"> (' + mediaDisplay 
				if (mediaLength.length>0){
					text2 += ' - ' + mediaLength;
				}
				text2 += ') </div> ';
				text +='' + description + '<br><br>';

				text +='</td>';
				text += '</tr>';
				text += '</table>';
									
				output += '<li><a href="' + this.urlRoot + this.url + mediaId  + '" class="multimediaLink">' + name + '</a>&nbsp;&nbsp;<span style="font-size: 11px">(' + mediaDisplay + ')</span>' + text + '</li>';
				text = '';
				text2 = '';
				
				description = '';
				text = '';
				counter += 1;
				
			} catch (e) {
				console.log(e);
				break;
			}		
		}
		output += '</ul>';
		output += '</div>';
		this.recordsDislaying = counter;	
		
		if (counter == 0){			
			output = '<p class="noResults">No Results Found.</p>';
			dojo.byId('descriptions').style.display = 'none';			
		} else {
			dojo.byId('descriptions').style.display = 'block';
		}
		console.log(output);
		return output;
	}
});