var ScheduleSearch = function(path, 
						  imagePath, 
						  defaultSearchString, 
						  defaultEpisodeBroadcastId, 
						  defaultStartDate, 
						  defaultEndDate,
						  defaultChannel) 
{
	
	
	
	this.path = path;
	this.imagePath = imagePath;
	this.runtime = new ScheduleSearchRuntime(defaultSearchString, 
						  defaultEpisodeBroadcastId, 
						  defaultStartDate, 
						  defaultEndDate,
						  'relevance',
						  1,
						  15,
						  defaultChannel);
}

ScheduleSearch.prototype.display = function() 
{
	
	
	

	broadcastId = (this.runtime.episodeBroadcastId == null) ? '' :this.runtime.episodeBroadcastId; 
	params = {
		'searchString': this.runtime.searchString,
		'broadcastId': broadcastId,
		'startDate': this.runtime.startDate,
		'endDate': this.runtime.endDate,
		'sortBy': this.runtime.sortBy,
		'channel': this.runtime.channel,
		'pageNumber': this.runtime.pageNumber,
		'perPage': this.runtime.perPage,
		'requestCounter': this.runtime.requestCounter
	};
		this.showProgressWidget();	
     new $('#results').load(this.path+'/?controller=scheduleSearchResultSet', params, 
	 	function() {
            ScheduleSearch.hideProgressWidget() 
		} );

	 /*, 
	 {
            onCreate: ScheduleSearch.showProgressWidget,
            onComplete: ScheduleSearch.hideProgressWidget,
			evalScripts: true,
			method: 'post',
			parameters: params
	});*/
		
	$('#bottom').show();
	this.runtime.requestCounter++;	    
}

ScheduleSearch.prototype.displayPage = function(pageNumber)
{
	this.runtime.pageNumber = pageNumber;
	this.display();
}

ScheduleSearch.prototype.doAfterRender = function()
{
	$('#bottom').hide();
	//$('.advanced_search_box').hide();
	if (''+this.runtime.searchString != '' || ''+this.runtime.episodeBroadcastId != '')
		this.display();
}

ScheduleSearch.prototype.handleNoResults = function()
{
	$('#bottom').hide();
}

// class methods
ScheduleSearch.displayPage = function(pageNumber)
{
	search.displayPage(pageNumber);
}

ScheduleSearch.prototype.showProgressWidget = function() 
{
    if ($('#loading_box')) 
	{
		$('#loading_box').html('Performing Search...<br /><img src="'+this.imagePath+'/animation_loading.gif">');
		$('#loading_box').fadeIn('normal');
	}
}
                    
ScheduleSearch.displayProgressWidget = function() 
{

}
                      
ScheduleSearch.hideProgressWidget = function()
{
	$('#loading_box').hide();
	$('#results').fadeIn('normal'); 
	search.runtime._ajaxLoaded = true;
}
