function mapHighlight() {
	
	$("#map-wrapper li a").css({ 'text-decoration' : 'none' });
	
		$("area").hover(
			
		function(){
			var region = $(this).attr("class");
			$(".map").attr({ src: "/images/interface/map/" + region + ".gif" });
			$("#"+region+" a").css({ 'color' : '#214232' });
			
		}, function($this){
			var region = $(this).attr("class");
			$(".map").attr({ src: "/images/interface/map/null.gif" });
			$("#"+region+" a").css({ 'color' : '' });
			
		});
	
		$(".region-list li").hover(
			
		function(){
			var region = $(this).attr("id");
			$(".map").attr({ src: "/images/interface/map/" + region + ".gif" });
			$(this).css({ 'color' : '#214232' });
			
		}, function($this){
			var region = $(this).attr("id");
			$(".map").attr({ src: "/images/interface/map/null.gif" });
			$(this).css({ 'color' : '' });
			
		});
		
};

function matchHeight(element) {

	var tallest = 0;
	
	element.each( function() {
    
		var thisHeight = $(this).height();

		if( thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
	
    element.height(tallest);
};

function weatherFunc() {

	$('h2.national, h3.national, .tabbed-content .heading-link').hide();
    
	var tabContainers = $('ul.primary ~ div');
    $('ul.primary a').click(function () {
        tabContainers.hide().filter(this.hash).show();
        
        $('ul.primary a').removeClass('selected');
        $(this).addClass('selected');
        
        return false;
    }).filter(':first').click();
	
	
	var outlook = $('#outlook-tabs ~ img');
    $('#outlook-tabs a').click(function () {
        outlook.hide().filter(this.hash).show();
        
        $('#outlook-tabs a').removeClass('selected');
        $(this).addClass('selected');
        
        return false;
    }).filter(':first').click();
	
	
	var satellite = $('#satellite-tabs ~ img:not(.weather-key-pic)');
    $('#satellite-tabs a').click(function () {
        satellite.hide().filter(this.hash).show();
        
        $('#satellite-tabs a').removeClass('selected');
        $(this).addClass('selected');
        
        return false;
    }).filter(':first').click();
	
	
	var rainRadar = $('#rainfall-radar img:not(.weather-key-pic)');
    $('#rainfall-radar .btn').click(function () {
		var showRadar = $('#radar-region').val();
        rainRadar.hide().filter('#' + showRadar).show();
        
        return false;
    }).filter(':first').click();
	
	
	$('#warning-title ~ .heading-link').show();
	$('#weather-warning').hide();
	
	$('#warning-toggle').click(function () {
		$('#weather-warning').toggle();
		$('#warning-toggle').toggleClass("close");
	
		var warningStatus = $('#weather-warning').css("display");
		if (warningStatus == "block") {
			$('#warning-toggle').text("Close");
		} else {
			$('#warning-toggle').text("View");
		}
		
		return false;
	});
	
	
	$('#international-title').show();
	$('#international-title a, #world-map-title, div.international-region').hide();
	
	$('#world-map area').click(function () {
		var continent = $(this).attr('class');
		
		$('#international-title a, div#' + continent + '-forecast').show();
		var continentTitle = $('div#' + continent + '-forecast h2').text();
		$('#international-title h2').text(continentTitle);
		$('div#world-map-wrapper, div.international-region h2, div.international-region a').hide();
		
		return false;
	});
	
	$('#world-map-wrapper li').click(function () {
		var continent = $(this).attr('id');

		$('#international-title a, div#' + continent + '-forecast').show();
		var continentTitle = $('div#' + continent + '-forecast h2').text();
		$('#international-title h2').text(continentTitle);
		$('div#world-map-wrapper, div.international-region h2, div.international-region a').hide();
		
		return false;
	});
	
	$('a.world-map-return').click(function () {
		$('#international-title h2').text('World Map');
		$('#international-title a, div.international-region').hide();
		$('div.#world-map-wrapper').show();
		
		return false;
	});
};

function calendarPopUp(startDate,endDate) {
	
	// initialise the "Select date" link
	$('#date-pick')
		.datePicker(
			// associate the link with a date picker
			{
				createButton:false,
				startDate:startDate,
				endDate:endDate
			}
		).bind(
			// when the link is clicked display the date picker
			'click',
			function()
			{
				updateSelects($(this).dpGetSelected()[0]);
				$(this).dpDisplay();
				return false;
			}
		).bind(
			// when a date is selected update the SELECTs
			'dateSelected',
			function(e, selectedDate, $td, state)
			{
				updateSelects(selectedDate);
			}
		).bind(
			'dpClosed',
			function(e, selected)
			{
				updateSelects(selected[0]);
			}
		);
		
	var updateSelects = function (selectedDate)
	{
		var selectedDate = new Date(selectedDate);
		$('#date-day option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
		$('#date-month option[value=' + (selectedDate.getMonth()+1) + ']').attr('selected', 'selected');
		$('#date-year option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
	}
	// listen for when the selects are changed and update the picker
	$('#date-day, #date-month, #date-year')
		.bind(
			'change',
			function()
			{
				var d = new Date(
							$('#date-year').val(),
							$('#date-month').val()-1,
							$('#date-day').val()
						);
				$('#date-pick').dpSetSelected(d.asString());
			}
		);
	
	// default the position of the selects to today
	var today = new Date();
	updateSelects(today.getTime());
	
	// and update the datePicker to reflect it...
	$('#date-day').trigger('change');
};

var geocoder;
var map;

function getMap() {
	geocoder = new google.maps.Geocoder();
	var latlng = new google.maps.LatLng(-37.785897,175.281936);
	var myOptions = {
		zoom: 15,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	var mapCanvas = document.getElementById("store-map-canvas");
	if (mapCanvas == null) {
		mapCanvas = document.getElementById("admin-map-canvas");
	}
	if (mapCanvas == null) {
		mapCanvas = document.getElementById("order-map-canvas"); 
	}
	map = new google.maps.Map(mapCanvas, myOptions);
}

function codeAddress(storeAddress) {
	var address = (storeAddress);
	if (geocoder) {
		geocoder.geocode( { 'address': address}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				map.setCenter(results[0].geometry.location);
				var marker = new google.maps.Marker({
					map: map, 
					position: results[0].geometry.location
				});
			} else {
				//alert("Geocode was not successful for the following reason: " + status);
			}
		});
	}
}

