	// globals
	home_country = null;
	dest_country = null;
	map_open = false;
	
	// defines
	var CH = {
		name:'China',
		code:'ch',
		left:659,
		top:206,
		size:'large',
		link_name:'learn-mandarin',
		language:'Mandarin'
	};
	var FR = {
		name:'France',
		code:'fr',
		left:446,
		top:169,
		size:'large',
		link_name:'learn-french',
		language:'French'
	};
	var AR = {
		name:'Argentina',
		code:'ar',
		left:320,
		top:374,
		size:'large',
		link_name:'learn-spanish',
		language:'Spanish'
	};
	var IT = {
		name:'Italy',
		code:'it',
		left:468,
		top:180,
		size:'large',
		link_name:'learn-italian-in-italy',
		language:'Italian'
	};
	
	
	// list of countries
	var countries = [CH,FR,AR,IT];
	
	
	$().ready(function() {
		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_open = false;
		} else {
			
			$('#map_holder').animate({
				height: '+=425'
			}, speed, function() {});
			
			$('#map').animate({
				top: '+=425'
			}, speed, function() {});
			
			map_open = true;
		}
	}
	
	
	/////////////////////////////////////////////////////////////
	// initilise map
	function init_map() {
		for (i in countries) {
			add_home_marker(countries[i]);
		}
	}
	
	
	
	/////////////////////////////////////////////////////////////
	// select a home
	function toggle_home(country) {
		
		if (!home_country && country) {
			
			// save selection
			home_country = country;
			
			// change icon
			$('#map #H_'+country.code).attr('src','/images/resources/map/map_pin_home_'+country.size+'.png');
			
			// hide all other homes
			$('#map .Home').each(function(index) {
				if ($(this).attr('id')!='H_'+country.code) $(this).fadeTo('fast',0);
			});
			
			// update instructions
			$('#info_heading').html(country.name);
			$('#info_body').html('Click here to find out more about learning <span class="dest">'+country.language+'</span> in <span class="dest">'+country.name+'</span><a id="info_button" href="/languages/'+home_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
			home_country = null;
			
			// change icon
			if (country)
				$('#map #H_'+country.code).attr('src','/images/resources/map/map_pin_default_'+country.size+'.png');
					
			// show all homes
			$('#map .Home').each(function(index) {
				$(this).fadeTo('fast',1);
			});
			
			// update instructions
			$('#info_heading').html('Instructions');
			$('#info_body').html('Where would you like to learn? Select a <span>Country</span>.');
			$('#info_flag').html('<img src="/images/resources/map/map_flatpin_grey.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 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) {
					// 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) {
					// show all homes
					$('#map .Home').each(function(index) {
						$(this).stop().fadeTo('fast',1);
					});
				}
			}
		).click(function() {
			toggle_home(country);
		});
		
	}
	
