$(document).ready(function(){
	function bindFormEvents(locationFilterForm, baseURL){
		locationFilterForm.bind('submit', function(e){
			var from = $(this).find('#from select').val();
			var to = $(this).find('#to select').val();

			var newURL = baseURL.replace('from-XXX', from);
			newURL = newURL.replace(/to\-XXX/, to);
			$(this).attr('action', newURL.replace(/\?$/, ''));
			// console.log(newURL);
      return true;
		});
	};
	
	var locationFilterForm = $('#deals #location-filter form');
	if(locationFilterForm.size() > 0)
		bindFormEvents(locationFilterForm, baseURL);
  
  $.tablesorter.addParser(Navigation.priceParser()); 
  $.tablesorter.addParser(Navigation.dateParser());  
  $.tablesorter.addParser(Navigation.stayDurationParser());  
  $.tablesorter.addWidget(Navigation.featuredRowsWidget());

	var tablesorterOptions = {
		sortList: [[1, 0]],
		headerOptions: {
			2: { sorter: 'stayduration' },
			3: { sorter: 'price' }
		}
	};
	navigation = new Navigation(0, 10, tablesorterOptions);
	$('.js-activation').show();
});