var map;

function initialize() {
  if (GBrowserIsCompatible()) {
  
  	//Creating a new instance of the map and centering it.
  
    map = new GMap2(document.getElementById("map_canvas"));
    
    //Setting up the user interface.
    
    map.addControl(new GMenuMapTypeControl());
    map.addControl(new GSmallZoomControl3D());
    
  }
}

//function center(path){
//	if(path == undefined){
//		map.setCenter(new GLatLng(54.482805, -2.944336), 5);
//	}
//	if(path == 'Wales'){
//		map.setCenter(new GLatLng(52.402419, -4.010010), 7);
//	}
//	if(path == 'Northumberland'){
//		map.setCenter(new GLatLng(55.933818, -2.389526), 7);
//	}
//	if(path == 'Fife'){
//		map.setCenter(new GLatLng(56.273861, -3.482666), 7);
//	}
//	if(path == 'Cleveland'){
//		map.setCenter(new GLatLng(54.412537, -0.747070), 7);
//	}
//	if(path == 'South West'){
//		map.setCenter(new GLatLng(50.637268, -3.927612), 7);
//	}
//	if(path == 'Arran'){
//		map.setCenter(new GLatLng(55.584555, -5.251465), 10);
//	}
//}

$(document).ready(function(){

//	initialize();

	$('span.hidden').hide();
	
	$('div#map_image a.map').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});
	
	var current = window.location.pathname;
	var index = current.lastIndexOf('/') + 1;
	current = current.substr(index);
	if(current == undefined || current == '' || current == 'index.html'){
		$('ul#sitemap').html();
	}
	else{
		var crumb = current;
		crumb = crumb.replace(/\W/g, ' ');
		crumb = crumb.replace(/\d/g, '');
		crumb = crumb.replace(/html/i, '');
		$('ul#sitemap').html('<li><a href="index.html" title="Back to the map of the UK">Home</a> ></li>');
		$('ul#sitemap').append('<li>' + crumb + '</li>');
	}
	
	$('ul#coursetypes li a').hover(function(){
		var this_id = "." + $(this).attr('id');
		$('a.map').filter(this_id).addClass('hover');
	}, function(){
		var this_id = "." + $(this).attr('id');
		$('a.map').filter(this_id).removeClass('hover');
	});
	
	$('ul#coursetypes li a').click(function(){
		$('a.map').removeClass('hover');
	});
	
	$('div.container').each(function(){
		var _top = $(this).children('a.tourist').css('top');
		var _left = $(this).children('a.tourist').css('left');
		_length = _left.length - 2;
		_left = _left.substr(0, _length);
		_left = parseInt(_left) + 60;
		$(this).children('span.hidden').css({'top':_top, 'left':_left});
	});
	
	$('a.tourist').toggle(function(){
		$(this).parents('div.container').children('span.hidden').fadeTo(200, 1);
	}, function(){
		$(this).parents('div.container').children('span.hidden').fadeTo(200, 0);
	});
	
//	$('div.info div.hidden').each (function() {
//		$(this).css("height", $(this).height());
//	});
	$('div.info div.hidden').hide();
	
	$('div.info a.revealer').toggle(function(){
		$(this).addClass('selected');
		$(this).parents('div.info').children('div.hidden:first').slideDown();
	}, function(){
		$(this).removeClass('selected');
		$(this).parents('div.info').children('div.hidden:first').slideUp();
	});
	
});
