var map;
var icon;
var markers = Array();
var i = 1;

var info_opts = {
	paddingX: 70,
	paddingY: 0,
	beakOffset: -3
};

$( function() {

	$('#content div.left ul').supersleight({ shim: '/resources/x.gif'});

	$('#content div.right table tr th a').click( function() {

		//alert($(this).attr('rel'));
		
		show_location($(this).attr('rel'));

		//return false;

	});

	$('#content div.left ul li a').click( function() {

		show_mission($(this).attr('rel'));

		return false;

	});

});


function loadMap() {
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	//map.enableScrollWheelZoom();
	//map.enableContinuousZoom();

	center = new GLatLng(52.625144,-1.110649);
	//map.setCenter(center, 13, G_HYBRID_MAP);
	map.setCenter(center, 8, G_NORMAL_MAP);

	icon = new GIcon();
	icon.image = "resources/"+ resources +"/marker.png";
	icon.shadow = "resources/"+ resources +"/marker_shadow.png";
	icon.iconSize = new GSize(14, 25);
	icon.iconAnchor = new GPoint(7, 25);
	icon.infoWindowAnchor = new GPoint(12, 0);

	var marker = new GMarker(center, icon);

	load_extra();

};

function createMarker(point, info, id) {
	var marker = new GMarker(point, icon);

	marker.id = id;

	GEvent.addListener(marker, "click", function() {
		//marker.openInfoWindowHtml(info, opts);

		marker.openExtInfoWindow(
			map,
			"iwindow",
			info,
			info_opts
		);

		map.getExtInfoWindow().resize();

		$('#marker_list li').removeClass("here");
		$('#marker_'+ marker.id).addClass("here");

	});

	markers[id] = marker;

	//i++;

	return marker;
};

function show_mission(id) {

	//alert('id: '+ id);

	$('#content div.left ul li').removeClass('here');

	$('#content div.left ul #link_'+ id).addClass('here');

	$('#content div.right').hide(200, function() {

		$('#content #mission_'+ id).show(200);

	});

};

function show_location(id) {

	//alert('id: '+ id);

	GEvent.trigger(markers[id], 'click');

	mgr.triggerClick(id);

};

function trace(text) {
	$('#test').append(text +'<br/>');
};