
bindEvents = function(){
	$('#photographers-search-btn').click(function(event){
		$.ajax({
			url: urlSearch,
			type: 'POST',
			data: $('#photographers-search-form').serialize(),
			success: function(response){
				$('#photographers-results').html(response);
				
				// click on photographer -> view photographers portfolio
				$(".photographer-profile").click(function(){
					window.location = $(this).attr("name");
				});
				
				bindSortEvents();
			}
		});
		
		event.preventDefault();
		
		return false;
	});
}

bindSortEvents = function(){

	$('a.sort').click(function(event){
		$.ajax({
			url: $(this).attr('href'),
			type: 'POST',
			data: $('#photographers-search-form').serialize(),
			success: function(response){
				$('#photographers-results').html(response);
				
				// click on photographer -> view photographers portfolio
				$(".photographer-profile").click(function(){
					window.location = $(this).attr("name");
				});
				
				bindSortEvents();
			}
		});
		
		event.preventDefault();
		
		return false;
	})
}


$(document).ready(function(){
	bindEvents();
	bindSortEvents();
	
	//add more specialty filters
	$('#add-new-specialty').click(function(){
		var currentSpecialtyId = $('#specialty_filters_count').val();
		var nextSpecialtyId = parseInt(currentSpecialtyId) + 1;
		
		$('#specialty_filters_count').val(nextSpecialtyId);
		
		// add a new specialty list box
		$('#specialty-container').append('<div class="specialty-select"><img class="search-margin" src="' + imageURL + 'search-input-left.png" />' +
											'<div class="select-container">' +
											'<select id="specialty_' + nextSpecialtyId + '" class="search select-search" name="specialty_' + nextSpecialtyId + '"></select>' +
											'</div>' +
											'<img class="search-margin" src="'+imageURL+'search-input-right.png" /></div>');
		
		// fill the select box with specialties
		//var specialtiesOptions = '';
		//$('#specialty_' + currentSpecialtyId + 'option').
		//alert(specialtyList);
		$('#specialty_' + nextSpecialtyId).html(specialtyList);
		
	});
	
	// click on photographer -> view photographers portfolio
	$(".photographer-profile").click(function(){
		window.location = $(this).attr("name");
	});
	
		
		/*$.ajax({
			type: "GET",
			url: refreshSpecialtyFiltersUrl,
			success: function(msg){
						$('#specialty-container').html(mgs);
					}
		});
*/		
		// add a new select box for specialty filters 
		/*$('#specialties-container').append('<img class="search-margin" src="' + imageURL + '/search-input-left.png" />' + 
										   '<div class="select-container">' + 
										   '<select id="specialty_filter_"' + nextSpecialtyId + 'class="specialty" />' +
										   '</div>' + 
										   '<img class="search-margin" src="' + imageURL + '/search-input-right.png" />');*/
		//$('#serving_locations').append('<input id="account_serving_'+nextLocationId+'" name="account[serving]['+nextLocationId+']" class="text-input location" />');
		
		//return false;
	//});
});
