$(document).ready(function() {
	
	var country_id = 0;

	// open map
	$(".map_link, .map_label").click(function(){
		
		$('.form_box').css({"visibility":"hidden"});
		$('.map_hide').css({"visibility":"hidden"});
		$('#site_footer').css({"visibility":"hidden"});
		
		$(".map_label").hide();
		$(".map_link").animate({
			"width":1150,
			"height":600,
			"top":-230,
			"left":-30
		},400,function(){
			$("#map_overlay_container").fadeIn(1000);
		});
		return false;
	});
	
	
	// close map
	$(".close_map_link").click(function(){
		$(".map_link").animate({
			"width":357,
			"height":240,
			"top":10,
			"left":10
		},800, function(){
			$(".map_label").fadeIn(200);
		});
		$("#map_overlay_container").hide();
		$('.form_box').css({"visibility":"visible"});
		$('.map_hide').css({"visibility":"visible"});
		$('#site_footer').css({"visibility":"visible"});
		return false;
	});
	
	
	// click on a country
	$(".country_map_link").click(function(){
		
		country_id = $(this).attr("rel");
		
		for (i=0;i<number_of_countries; i++) {
			if(countries[i][0]==country_id){
				
				country_id = countries[i][0];
				original_width = countries[i][1];
				original_height = countries[i][2];
				original_top = countries[i][3];
				original_left = countries[i][4];
				new_width = countries[i][5];
				new_height = countries[i][6];
				new_top = countries[i][7];
				new_left = countries[i][8];
				country_name = countries[i][9];
				break;
			}
		}
		
		$("#map_image_" + country_id).fadeIn(800);
		$(".close_map_link").fadeOut(800);
		$("#map_key").fadeOut(800);
		$("#map").fadeOut(800);
		$("#map_overlay").css({"background-image":"none"});

		$("#map_image_" + country_id).animate({
			"top":new_top,
			"left":new_left,
			"width":new_width,
			"height":new_height
		},1600);
		
		$(".country_table").load("/map/inc_table.cfm?countrycode=" + country_id);
		
		$(".country_map_link").fadeOut(2200,function(){
			$(".country_close").fadeIn(800);
			$(".country_table").fadeIn(800);
			
			//$(".country_table").load("/map/inc_table.cfm?countrycode=" + country_id).fadeIn(800);
			//$(".country_table h2").html(country_name);
			//$(".country_table h2").addClass("flag_" + country_id);
			//$(".country_table").fadeIn(800);

		});
		
		//$(".country_table").load("/map/inc_table.cfm?countrycode=" + country_id).fadeIn(2500);
		
		return false;
	});
	
	// close country view
	$("a.country_close").click(function(){
		
		$("#map_image_" + country_id).animate({
			"top":original_top,
			"left":original_left,
			"width":original_width,
			"height":original_height
		},1600);
		
		$(".country_table").fadeOut(3000);
		
		$(".country_close").fadeOut(1600,function(){
			
			//$(".country_table h2").html('');
			//$(".country_table h2").removeClass("flag_" + country_id);
			
			$(".country_table").html('');
			
			$("#map_image_" + country_id).fadeOut(800);
			$(".close_map_link").fadeIn(1200);
			$("#map_key").fadeIn(1600);
			$("#map").fadeIn(1000);
			$(".country_map_link").fadeIn(1200);
			$("#map_overlay").css({"background-image":"url(/images/map/MapOn.jpg)"});
			
		});
		
		return false;
	});
	
	
	
});
