//Carry out tasks when page is loaded
$(document).ready(function(){					   
	
	//Old fading news ticker effect
	//$('#header ol').innerfade({ animationtype: 'fade', speed: 'slow', timeout: 5000, type: 'sequence', containerheight: 'auto' }); 
	
	//new scrolling ticker
	//$("#header ol li").css('display','block');
	$("#header ol").liScroll(); 
	
	
	
	//SELECTING COUNTRY TO DISPLAY COUNTIES
	$('#select_country').change(function(){								   
		var country = $(this).val();
		
		$('#retailerResults').html('');
		
		if(country == 'default'){
			$('#select_county').children().remove().end().append('<option selected value="default">Select your county...</option>');
			$('#selectCounty').removeClass('show').addClass('hide');
			
			return false;
		}
		else{
			country = $(this).val();	
		}
		
		
		
		$.post("/ajax/getCounties/", { chosenCountry:country },
	   		function(data){
								
				if(data){				
					$('#selectCounty').removeClass('hide').addClass('show');
					$('#select_county').children().remove().end().append('<option selected value="default">Select your county...</option>');
					$('#select_county').children().end().append(data);					
				}
				else{
					alert('We\'re very sorry but we are getting the list of counties for your region. Remember you can always order from the list of online stores above. ');	
					$('#selectCounty').removeClass('show').addClass('hide');
				}
				
	   });
		
		
		return false;
	});
	
	
	
	
	
	
	//SELECTING COUNTYTO DISPLAY ALL DEALERS FROM DATABASE
	$('#select_county').change(function(){								   
		var county = $(this).val();
				
		if(county == 'default'){
			return false;
		}
		else{
			county = $(this).val();	
		}
		
		
		
		$.post("/ajax/getRetailers/", { chosenCounty:county },
	   		function(data){
								
				if(data){				
					$('#retailerResults').html('').html(data);
				}
				else{
					alert('We\'re very sorry but we are unable to find any results for your chosen search criteria. Remember you can always order from the list of online stores above.');
				}
				
	   });
		
		
		return false;
	});
	
	
	
	
	
	
});//CLOSING DOCUMENT READY




/**
*	GENERAL FUNCTIONS TO USE IN DOCUMENT.READY ABOVE
**/






