var CruisesFront = Class.create(AttractionsFront, {
    initialize: function() {
        console.log('CruisesFront::initialize');
        
        this.searchDetails = {};
        
		this.sortType = 'default';
		this.sortDirection = 'none';
		
        this.selectedActivityId = $('results').getAttribute('activityId');
        
		this.itemsPerPage = 10;
		this.curPage = 1;
		
        this.showResultsAfterTime = 10;
        
        this.attractionsStorage = new AttractionsStorage();
		this.attractionsView = new AttractionsView();
        
		$('sortType').observe('change', this.changeSortType.bindAsEventListener(this));
		$('sortDirection').observe('change', this.changeSortDirection.bindAsEventListener(this));
        
        this.startSearch();
    },
    startSearch: function() {
        console.log('CruisesFront::startSearch');
        
        this._doRequestForStartSearch();
    
        this.getView().showResults.delay(this.showResultsAfterTime);
        
    },
    _proccessResults: function(response) {
        console.log('CruisesFront::_proccessResults');
		if (response.responseJSON.attractions.length != 0) {
			this.getStorage().update(response.responseJSON.attractions);
			this.redrawList();
            this.getView().showResults();
		}
        this.getView().hideSearchIndicator();
    },
    _doRequestForStartSearch: function() {
        console.log('CruisesFront::_doRequestForStartSearch');
        var params = {locationId: $('results').getAttribute('locationId'),
                      locationType: $('results').getAttribute('locationType')};
        new Ajax.Request('/cruises-search/start/', 
            { method: 'post', 
              parameters: $H(params).toQueryString(), 
              onComplete: this._startGrabResults.bind(this) }
        );
    },
    _doRequestForGetResults: function() {
        console.log('CruisesFront::_doRequestForGetResults');
        var params = {locationId: $('results').getAttribute('locationId'),
                      locationType: $('results').getAttribute('locationType')};
        new Ajax.Request('/cruises-search/get-results/', 
            { method: 'post', 
              parameters: new Hash(params).toQueryString(), 
              onComplete: this._proccessResults.bind(this) }
        );
    }
});
