$(document).ready(function() {
	var $mapImg = $('#world_map img').eq(0);
	var $mapWidth = $mapImg.width();
	var $world_map_container = $('#world_map');
	var $mapSrc = $mapImg.attr('src');
	$world_map_container.css({
		'width': (2 * $mapWidth) + 'px',
		'background-image': 'url(' + $mapSrc + ')',
		'background-repeat': 'repeat-x',
		'background-position': '0px 0px'
	});
	$mapImg.remove();
	var $linkParent=$(this).toggleClass('active');
		animate_globe();
		return false;
		
	//var $linkParent = $('<div id="controls" />');
//	$('<a href="#">Rotate</a>')
//	.click(function() {
//		$(this).toggleClass('active');
//		animate_globe();
//		return false;
//	})
//	.appendTo($linkParent);
//	
//	$('<a href="#">Stop</a>')
//	.click(function() {
//		$(this).toggleClass('active');
//		$world_map_container
//		.stop()
//		.animate({
//			'background-position': '0px 0px'
//		}, 500);
//		return false;
//	})
//	.appendTo($linkParent);
//	$linkParent.appendTo('#main_content');
	
	function animate_globe() {
		$world_map_container.animate({
			'background-position': '-' + $mapWidth + 'px 0'
		}, 4000, function() {
			$world_map_container.css({
				'background-position': '0px 0px'
			});
			animate_globe();
		});
	}
});

