$(document).ready(function() {
	
	/* HIGHLIGHT THE CURRENT TAB */
	var a_url = window.location.pathname.split('/');
	$('a[href='+ a_url[1] +']:first').addClass('current');
	
	/* SHOW/HIDE DROPDOWN MENUS */
	$('nav ul > li').hover(
		function() {
			$('ul', this).css({'display':'block'});
		},
		function() {
			$('ul', this).css('display', 'none');
		}
	);
	
	/* CALENDAR EVENT POPUP */
	$('#events li').click(function() {
		window.open($(this).find('a').attr('href'), 'gcalevent', 'width=700,height=600');
		return false;
	});

	/* LIGHTBOX */
	$("a[rel^='lightbox']").click(function() {
		
		if($("#lightbox-panel").length===0) {
			
			var lightbox = '<div id="lightbox-panel">\
							<img src="'+ $(this).attr('href') +'" alt="photo" /><br />\
							<a id="close-panel" href="[~[*id*]~]#">Click anywhere or press Escape to close the image</a>\
						</div>\
						<div id="lightbox"></div>';
						
			$(lightbox).appendTo('body');
		}
		else {
			$("#lightbox-panel img").attr('src',$(this).attr('href'));
		}
		
		$("#lightbox, #lightbox-panel").fadeIn(300);
		
		$("#lightbox-panel img").show();
		return false;
	});
	
	$("a#close-panel").live('click', function() {
		$("#lightbox, #lightbox-panel").fadeOut(300);
		return false;
	});
	
	$("body").live('click', function() {
		$("#lightbox, #lightbox-panel").fadeOut(300);
	});
	
	$(this).keydown(function(e) {
		if(e.keyCode===27) { //Escape
			$("#lightbox, #lightbox-panel").fadeOut(300);
		}
	});
	
}); // DOM ready

var map = null;
var geocoder = null;

$(window).load(function(){
	initialize_map();
})

function initialize_map() {
	if (GBrowserIsCompatible()) {
		map = new GMap2( $("#map_canvas").get(0) );
		var point = new GLatLng(55.947609,-3.046847);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());        
		var marker = new GMarker(point);
		map.addOverlay(marker);
		map.setCenter(point, 13);
  }
}