$(document).ready(function(){
	$('#continent').change(function(){
		var continent_id = $(this).attr('value');
		
		if(country_id && !isNaN(country_id)){
			$.post(basehref + 'ajax/getCountries.php', { continent_id: continent_id, type_id: $('#type').attr('value') }, function(data) {
				$('#country').html(data);
				$('#country').removeAttr('disabled');
			});
		}else{
			$('#country').html('<option value="">Kies een continent</option>');
			$('#country').attr('disabled','disabled');
		}
	});
	
	$('#type').change(function(){
		var continent_id = $('#continent').attr('value');
		if(continent_id){
			var type_id = $(this).attr('value');
			
			if(type_id && !isNaN(type_id)){
				$.post(basehref + 'ajax/getCountries.php', {continent_id: continent_id, country_id: $('#country').attr('value'), type_id: type_id}, function(data) {
					$('#country').html(data);
					$('#country').removeAttr('disabled');
				});
			}else{
				$('#type').html('<option value="">Kies een continent</option>');
				$('#type').attr('disabled','disabled');
			}
		}
	});
	
	$('#zoeksubmit').click(function(){
		if($('#continent').attr('value') == '' && $('#type').attr('value') == ''){
			alert('Kies eerst een type of continent om reizen te zoeken');
			return false;
		}
	});
	
	$('#overview').append('<div id="offerBox"></div>');
	setOffers();
});

$('#pagination a').live('click',function(){
	var new_page = $(this).html();
	
	if(new_page == 'Volgende'){
		page++;
	}else if(new_page == 'Vorige'){
		page--;
	}else{
		page = new_page;
	}
	
	setOffers();
});

$('#sorts a').live('click',function(){
	order = (order == 'asc')?'desc':'asc';
	page = 1;
	
	setOffers();
});

$('#offerList .meer').live('click',function(){
	var par = $(this).parent('.mid');
	$(this).css('display','none');
	par.children('.p').css('display','none');
	par.children('.hid').css('display','block');
});

function setOffers(){
	$.post(basehref + 'ajax/getOffers.php', {type_id: type_id, page: page, country_id: country_id, order: order}, function(data){
		$('#offerBox').html(data);
	});
}
