$(document).ready(function() {
	$('#tab2').click();
	
	$('.footer-popup-tabs').click(function() {
		
		$("#footer-popup-container-no-tab").hide();
		var contactLink = $(this);
		var code = contactLink.parent().attr('class');

		// Load the map only if the flag is clicked
		if (code == 'cn') {
			scrollToFlags();
			$("#footer-popup-container").css("bottom", "10");
			url = "http://maps.google.com/maps/ms?t=h&amp;ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=109516855706372455034.00047f0ed5aa05a38c5fb&amp;ll=22.537254,114.117222&amp;spn=0.011891,0.012875&amp;z=15&amp;output=embed";
			urlhz = "http://maps.google.co.uk/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=%4030.27889707150173,120.16473412513733&amp;sll=30.273978,120.155361&amp;sspn=0.832568,1.586151&amp;ie=UTF8&amp;t=h&amp;ll=30.27886,120.164702&amp;spn=0.005559,0.006437&amp;z=16&amp;output=embed";
			setTimeout('$("#footer-map-sz").html(\'<iframe width="300" height="275" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="\' + url + \'"></iframe>\');', 100);
			setTimeout('$("#footer-map-hz").html(\'<iframe width="300" height="275" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="\' + urlhz + \'"></iframe>\');', 100);
		} else {
			$("#footer-popup-container").css("bottom", "80");
		}
		
		$("#footer-popup-container").show();
		$("#footer-popup-container").css("left", contactLink.position().left - "120");
	});
	
	$('.footer-popup-no-tab').click(function() {
		$("#footer-popup-container").hide();
		var contactLink = $(this);
		var code = contactLink.parent().attr('class');
		$("#fntdc").html($("#footer-" + code).html());
		
		// Load the map only if the flag is clicked
		if (code == 'hk') {
			scrollToFlags();
			url = "http://maps.google.com/maps/ms?source=s_q&amp;hl=en&amp;g=france&amp;ie=UTF8&amp;cd=1&amp;geocode=FSxz6QIdt3kjAA&amp;split=0&amp;num=10&amp;t=k&amp;msa=0&amp;msid=109516855706372455034.00048041c554328c2cf3a&amp;ll=22.281274,114.182421&amp;spn=0.002978,0.003219&amp;z=17&amp;output=embed";
			setTimeout('$("#footer-map-hk").html(\'<iframe width="300" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="\' + url + \'"></iframe>\');', 100);
		} else if  (code == 'fr') {
			scrollToFlags();
			//url = "http://maps.google.com/maps/ms?source=s_q&amp;hl=en&amp;g=france&amp;ie=UTF8&amp;cd=1&amp;geocode=FSxz6QIdt3kjAA&amp;split=0&amp;num=10&amp;t=h&amp;msa=0&amp;msid=109516855706372455034.000480415ef88d4a28beb&amp;ll=48.854077,2.325196&amp;spn=0.002118,0.003219&amp;z=17&amp;output=embed";
			url = "http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=54,+rue+de+Varenne,+75007+Paris+France+&amp;sll=48.854077,2.325196&amp;sspn=0.004151,0.011362&amp;ie=UTF8&amp;hq=&amp;hnear=54+Rue+de+Varenne,+75007+Paris,+Ile-de-France,+France&amp;t=h&amp;ll=48.854529,2.321538&amp;spn=0.002118,0.003208&amp;z=17&amp;iwloc=A&amp;output=embed";
			setTimeout('$("#footer-map-fr").html(\'<iframe width="300" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="\' + url + \'"></iframe>\');', 100);
		} else if (code =="in") {
			url = "http://maps.google.com/maps?q=28.540927,77.252769&amp;num=1&amp;t=h&amp;sll=28.540629,77.252871&amp;sspn=0.002238,0.006866&amp;hl=en&amp;ie=UTF8&amp;ll=28.540987,77.252812&amp;spn=0.001414,0.001609&amp;z=18&amp;output=embed";
			setTimeout('$("#footer-map-in").html(\'<iframe width="300" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="\' + url + \'"></iframe>\');', 100);
		}
		
		$("#footer-popup-container-no-tab").show();
		$("#footer-popup-container-no-tab").css("bottom", "80");
		$("#footer-popup-container-no-tab").css("left", contactLink.position().left - "120");
	});
	
	$('.close-footer-popup').click(function() {
		$("#footer-popup-container").hide();
		$("#footer-popup-container-no-tab").hide();
	})
});

function emailMap(office) {
	$.post("/qi/aiweb.nsf/(2010SendSzMap)?openagent",
		$("#mapFrom" + office).val() + "&" + $("#mapTo" + office).val() + "&" + escape($("#mapBody" + office).val()) + "&" + office,
		function(data) {
			$("#sendMap" + office).slideToggle('slow', function() {alert('E-mail successfully sent')});
		}
	);
}

function scrollToFlags() {
	$("body").animate({ scrollTop: parseInt(document.body.scrollHeight) - $(window).height() - 240}, "slow");
}
