// JavaScript Document
var nearestMarker;

$(document).ready(function()
{
	// Country Selector
	var countrySelectionConfig = {    
		interval: 150,
		sensitivity: 4,
		over: openCountrySelector,
		timeout: 400,
		out: closeCountrySelector
	};

	var countryHeight = $('#selector-storeCountry').children().size();
	countryHeight = $('.language').height() * countryHeight;
	
	$("#selector-storeCountry").hoverIntent(countrySelectionConfig);
	
	function openCountrySelector() {
		$('#selector-storeCountry').animate({'height':countryHeight+'px'});	
	}

	function closeCountrySelector() {
		$('#selector-storeCountry').animate({'height':$('.language').height()+'px'});	
	}

	// Focuses postcode search box on page load
	$('#postcode').focus();

	$('#frmStoreLocator').submit(function() {
		$('#postcode-right-column').empty(); // Remove Current Stores

		if ($('#postCode').val() != '') {
			gLocalSearch.execute($('#postCode').val());

			$.post('stores/json', $(this).serialize(), function(data){
				if (data['markers'].length != 0) {
					clearMarkers(); // Remove Markers
					setMarkers(data['markers']); // Add Markers

					$('#postcode-right-column').html(data['stores']); // Insert Right Column Data
				}
				else {
					alert(error_message); // Defined on page inline script tag using PHP for translation
				}
			}, 'json');
		}
		else {
			alert(error_message); // Defined on page inline script tag using PHP for translation
		}

		return false;
	});

	$('#selector-storeCountry .disabled a').click(function(event){
		//return false; // Prevent Link from working
		event.preventDefault();
	});
});

