$(document).ready(function() {
	
	// If this is a request for a specific location, open it up

	var myID = window.location.href;
	
	if(myID.indexOf('#') != -1) {
		highlightLocation();
	}
	
	// or from the click map
	$('map area').click(function() {
		myID = $(this).attr('href');
		highlightLocation();
	});
	
	function highlightLocation(){
		var length = myID.length; //get length of the url string
		var pos = myID.indexOf("#", 1); //get position of the instance of #
		myID = myID.substring(pos,length) //cut a new string using 2 values above.
		$(myID).addClass('highlight'); // highlight the chosen location
		window.location.href = myID;
	}
	
	// Set Website links to open in new window
	$('.loc_list dl a').each(function() {
		$(this).attr('target','_blank');
	});
			
	// Click to open Google Map
	$('.loc_list .loc_content h2 a').click(function() {
		$(this).parents('li').addClass('highlight');
		return false;
	});
	
	/*$('.loc_list .loc_content').each(function() {
		
		 var hrefEle = $(this).find('h2 a').attr('href');

		 $(this).click(function(){
			// Click to open Google Map
		 	$(this).parents('li').addClass('highlight');
			return false;
		 });
	 	$(this).css("cursor","pointer");

	});*/
	
	/*$('.loc_list h2 a').click(function() {
		
		$(this).parents('li').css('background','url(/img/locations/bg.png) repeat left top');
		$(this).parents('li').css('color','#fff');
		$(this).parents('li').css('margin-left','-340px');
		$(this).parents('li').find('a').css('color','#fff');
		$(this).parents('li').find('.loc_googlemap').fadeIn('slow');
		
		
		return false;
	});*/
	
	// Click to close Google Map
	$('.loc_list .close').click(function() {
		$(this).parents('li').removeClass('highlight');
		return false;
	});
	
});

function initLocations(){
    if (GBrowserIsCompatible()) {
        $('.gmap').each(function() {
            var address = $(this).children('span').text();
            var latlong = address.split(',');
            var map = new GMap2($(this).get(0));
            var coords = new GLatLng(latlong[0], latlong[1]);
            map.setCenter(coords,13);
            map.addOverlay(new GMarker(coords));
		    map.addControl(new GSmallMapControl());
        });
    }
};
	
$(document).ready(function(e){
    if(isIE6){
        $('.locations a').mouseover(function(){
            $(this).children('b').show();
        });
        $('.locations a').mouseout(function(){
            $(this).children('b').hide();
        });
    }
    
});


