	// globals
	home_country = null;
	dest_country = null;
	map_open = false;
	
	// defines
	var AU = {
		name:'Australia',
		code:'au',
		id:18188,
		left:703,
		top:339,
		size:'large',
		link_glue:'gap-year-locations',
		link_name:'australia'
	};
	var CA = {
		name:'Canada',
		code:'ca',
		id:18213,
		left:200,
		top:158,
		size:'large',
		link_glue:'where-can-i-go',
		link_name:'canada'
	};
	var CH = {
		name:'China',
		code:'ch',
		id:18219,
		left:669,
		top:162,
		size:'large',
		link_name:'china'
	};
	var IN = {
		name:'India',
		code:'in',
		id:18275,
		left:566,
		top:235,
		size:'large',
		link_name:'india'
	};
	var NZ = {
		name:'New Zealand',
		code:'nz',
		id:18332,
		left:767,
		top:355,
		size:'large',
		link_glue:'gap-year-locations',
		link_name:'new-zealand'
	};
	var SG = {
		name:'Singapore',
		code:'sg',
		id:18373,
		left:621,
		top:266,
		size:'small',
		link_name:'singapore'
	};
	var SA = {
		name:'South Africa',
		code:'sa',
		id:18378,
		left:50,
		top:50,
		size:'large',
		link_name:'south-africa'
	};
	var TH = {
		name:'Thailand',
		code:'th',
		id:18392,
		left:614,
		top:237,
		size:'small',
		link_name:'thailand'
	};
	var UK = {
		name:'United Kingdom',
		code:'uk',
		id:18406,
		left:410,
		top:156,
		size:'small',
		link_glue:'where-can-i-go',
		link_name:'united-kingdom'
	};
	var US = {
		name:'United States',
		code:'us',
		id:18407,
		left:226,
		top:202,
		size:'large',
		link_glue:'where-can-i-go',
		link_name:'united-states'
	};
	var FR = {
		name:'France',
		code:'fr',
		id:1111,
		left:414,
		top:171,
		size:'small',
		link_glue:'where-can-i-go',
		link_name:'france'
	};	
	var SK = {
		name:'South Korea',
		code:'sk',
		id:1112,
		left:614,
		top:238,
		size:'large',
		link_glue:'where-can-i-go',
		link_name:'south-korea'
	};	
	
	// append destinations now that they have all been set
	AU.destinations = [CA,CH,TH,SG,UK,NZ,IN,US,FR];
	CA.destinations = [AU,NZ,CH,TH,IN,UK,FR];
	CH.destinations = [AU,CA,IN,SG,TH,UK,US,FR];
	IN.destinations = [AU,CA,IN,SG,TH,UK,US,FR];
	NZ.destinations = [CA,CH,TH,SG,UK,AU,IN,US,FR];
	SG.destinations = [AU,CA,IN,SG,TH,UK,US,FR];
	SA.destinations = [AU,CA,IN,SG,TH,UK,US,FR];
	TH.destinations = [AU,CA,IN,SG,TH,UK,US,FR];
	UK.destinations = [AU,CH,TH,SG,NZ,IN,FR];
	US.destinations = [AU,NZ,CH,TH,IN,FR];
	
	// list of countries
	var countries = [AU,CA,CH,IN,NZ,SG,SA,TH,UK,US];

	
	$().ready(function() {
		
		//add_marker(2,'large','default',363,760);
		
		// add home countries
		add_home(AU);
		add_home(CA);
		add_home(NZ);
		add_home(UK);
		add_home(US);
		
		
		init_map();
	});
	
	
	/////////////////////////////////////////////////////////////
	// close map
	function toggle_map() {
		speed = 1000;
		if (map_open) {
			
			$('#map_holder').animate({
				height: '-=425'
			}, speed, function() {});
			
			$('#map').animate({
				top: '-=425'
			}, speed, function() {});
			
			$('#map_selection').animate({
				top: '-=69'
			}, speed, function() {});
			
			map_open = false;
		} else {
			
			$('#map_holder').animate({
				height: '+=425'
			}, speed, function() {});
			
			$('#map').animate({
				top: '+=425'
			}, speed, function() {});
			
			$('#map_selection').animate({
				top: '+=69'
			}, speed, function() {});
			
			map_open = true;
		}
	}
	
	
	/////////////////////////////////////////////////////////////
	// initilise map
	function init_map(home_country,dest_country) {
		if (home_country && dest_country) {
			toggle_home(home_country);
			toggle_destination(dest_country);
		} else if (home_country) {
			toggle_home(home_country);
		} else {
			toggle_home(null);	
		}
	}
	
	
	/////////////////////////////////////////////////////////////
	// add home country
	function add_home(country) {
		
		// add home marker
		add_home_marker(country);
		
		// add markers for destinations
		//for (var key in country.destinations) {
		//	add_dest_marker(country.destinations[key]);
		//}
		
	}
	
	
	/////////////////////////////////////////////////////////////
	// select a home
	function toggle_home(country) {
		
		if (!home_country && country) {
			
			// save selection
			home_country = country;
			
			// show paths
			$('#map #P_'+country.code).show();
			
			// change icon
			$('#map #H_'+country.code).attr('src','/images/resources/map/map_pin_home_'+country.size+'.png');
			
			// add destination markers
			for (var key in country.destinations) {
				add_dest_marker(country.destinations[key]);
			}
			
			// hide all other homes
			$('#map .Home').each(function(index) {
				if ($(this).attr('id')!='H_'+country.code) $(this).fadeTo('fast',0);
			});
			
			// update selection box
			$('#selection_home').html('<div class="selection_flag"><img src="/images/resources/map/map_flatpin_home.png" /><img class="close" src="/images/resources/map/map_close_sml.png" onclick="toggle_home('+country.code.toUpperCase()+');" /></div>Your home country is: <span class="home">'+country.name+'</span>');
			$('#selection_dest').html('<div class="selection_flag"><img src="/images/resources/map/map_flatpin_grey.png" /></div>Select destination: <span>Country</span>');
			
			// update instructions
			$('#info_heading').html('Instructions');
			$('#info_body').html('Your home country is: <span class="home">'+country.name+'</span>. Where would you like to do your gap year?');
			$('#info_flag').html('<img src="/images/resources/map/flags/'+country.code+'.png" width="32" height="32" />');
			
			// update flag
			$('#map_menu_home').html('<img src="/images/resources/map/flags/'+country.code+'.png" width="32" height="32" />');
			
		} else {
			// deselect everything
			
			// remove selection
			home_country = null;
			
			// toggle destination if one was selected
			if (dest_country)
				toggle_destination(dest_country);
			
			// change icon
			if (country)
				$('#map #H_'+country.code).attr('src','/images/resources/map/map_pin_default_'+country.size+'.png');
			
			// remove destination markers
			$('#map .Dest').remove();
			
			// remove flights
			$('#map .Flight').remove();
			
			// hide paths
			$('#map .Path').hide();
					
			// show all homes
			$('#map .Home').each(function(index) {
				$(this).fadeTo('fast',1);
			});
			
			// update selection box
			$('#selection_home').html('<div class="selection_flag"><img src="/images/resources/map/map_flatpin_grey.png" /></div>Select your home: <span>Country</span>');
			$('#selection_dest').html('<div class="selection_flag"><img src="/images/resources/map/map_flatpin_grey.png" /></div>Select destination: <span>Country</span>');
			
			// update instructions
			$('#info_heading').html('Instructions');
			$('#info_body').html('Where are you from? Select your home <span>Country</span>.');
			$('#info_flag').html('<img src="/images/resources/map/map_flatpin_grey.png" />');
			
			// update flag
			$('#map_menu_home').html('<img src="/images/resources/map/flags/unselected.png" width="32" height="32" />');
			
			
		}
		
		
	}
	
	
	/////////////////////////////////////////////////////////////
	// select a destination
	function toggle_destination(country) {
		
		if (!dest_country) {
			
			// save selection
			dest_country = country;
			
			// show flight paths
			$('#map #F_'+country.code).show();
			
			// change icon
			$('#map #D_'+country.code).attr('src','/images/resources/map/map_pin_dest_'+country.size+'.png');
			
			// hide other destinations
			$('#map .Dest').each(function(index) {
				if ($(this).attr('id')!='D_'+country.code)
					$(this).fadeTo('fast',0.3,function() {
						
					});
			});
			
			// update selection box
			$('#selection_dest').html('<div class="selection_flag"><img src="/images/resources/map/map_flatpin_dest.png" /><img class="close" src="/images/resources/map/map_close_sml.png" onclick="toggle_destination('+country.code.toUpperCase()+');" /></div>Your destination is: <span class="dest">'+country.name+'</span>');
			
			// update instructions
			$('#info_heading').html(country.name);
			$('#info_body').html('Click here to find out more about a gap year in <span class="dest">'+country.name+'</span><a id="info_button" href="/'+home_country.link_name+'/'+home_country.link_glue+'/'+dest_country.link_name+'/"><img src="/images/resources/map/learn_more.png" /></a>');
			$('#info_flag').html('<img src="/images/resources/map/flags/'+country.code+'.png" width="32" height="32" />');
			
			// update flag
			$('#map_menu_dest').html('<img src="/images/resources/map/flags/'+country.code+'.png" width="32" height="32" />');
			
		} else {
			// deselect everything
			
			// remove selection
			dest_country = null;
			
			// change icon
			$('#map #D_'+country.code).attr('src','/images/resources/map/map_pin_default_'+country.size+'.png');
			
			// show other destinations
			$('#map .Dest').each(function(index) {
				$(this).fadeTo('fast',1,function() {
					$(this).show();
				});
			});
			
			// remove flight paths
			$('#map .Flight').hide();
			
			// update selection box
			$('#selection_dest').html('<div class="selection_flag"><img src="/images/resources/map/map_flatpin_grey.png" /></div>Select destination: <span>Country</span>');
			
			// update instructions
			$('#info_heading').html('Instructions');
			$('#info_body').html('Your home country is: <span class="home">'+country.name+'</span>. Where would you like to do your gap year?');
			$('#info_flag').html('<img src="/images/resources/map/map_flatpin_home.png" />');
			
			// update flag
			$('#map_menu_dest').html('<img src="/images/resources/map/flags/unselected.png" width="32" height="32" />');
			
		}
		
	}
	
	
	/////////////////////////////////////////////////////////////
	// add a home marker
	function add_home_marker(country) {
		
		// image source
		src = '/images/resources/map/map_pin_default_'+country.size+'.png';
		
		// adjust for image offsets
		if (country.size=='small') {		// small
			x = country.left-10;
			y = country.top-22;
		} else {							// normal
			x = country.left-13;
			y = country.top-30;
		}
		
		// add home paths
		$('#map').append('<img id="P_'+country.code+'" class="Path Lines" src="/images/resources/map/paths/'+country.code+'.png" />');
		
		// add marker
		$('#map').append('<img id="H_'+country.code+'" class="Marker Home" style="top:'+y+'px; left:'+x+'px" src="'+src+'" />');
		
		// add actions to marker
		$('#map #H_'+country.code).hover(
			function() {
				// show home lines if home hasn't been chosen yet
				if (!home_country) {
					$('#map #P_'+country.code).show();
					
					// hide all other homes
					$('#map .Home').each(function(index) {
						if ($(this).attr('id')!='H_'+country.code) $(this).stop().fadeTo('fast', 0.3);
					});
				}
			},
			function() {
				// hide home lines if home hasn't been chosen yet
				if (!home_country) {
					$('#map #P_'+country.code).hide();
					
					// show all homes
					$('#map .Home').each(function(index) {
						$(this).stop().fadeTo('fast',1);
					});
				}
			}
		).click(function() {
			toggle_home(country);
		});
		
	}
	
	
	/////////////////////////////////////////////////////////////
	// add a destination marker
	function add_dest_marker(country) {
		
		// image source
		src = '/images/resources/map/map_pin_default_'+country.size+'.png';
		
		// adjust for image offsets
		if (country.size=='small') {		// small
			x = country.left-10;
			y = country.top-22;
		} else {							// normal
			x = country.left-13;
			y = country.top-30;
		}
		
		// add flight path
		$('#map').append('<img id="F_'+country.code+'" class="Path Flight" src="/images/resources/map/flights/'+home_country.code+'-'+country.code+'.png" />');
		
		// add marker
		$('#map').append('<img id="D_'+country.code+'" class="Marker Dest" style="top:'+y+'px; left:'+x+'px" src="'+src+'" />');
		
		// add actions to marker
		$('#map #D_'+country.code).hover(
			function() {
				// show flight path if dest hasn't been chosen yet
				if (!dest_country) {
					$('#map #F_'+country.code).show();
					
					// change icon
					$(this).attr('src','/images/resources/map/map_pin_dest_'+country.size+'.png');
				}
			},
			function() {
				// hide flight path if dest hasn't been chosen yet
				if (!dest_country) {
					$('#map #F_'+country.code).hide();
				
					// change icon
					$(this).attr('src','/images/resources/map/map_pin_default_'+country.size+'.png');
				}
			}
		).click(function() {
			
			// toggle off if one is already selected
			if (dest_country && dest_country!=country)
				toggle_destination(dest_country);
				
			toggle_destination(country);
		});
		
	}
