$(function () {
	
	var highlighticon = new GIcon(G_DEFAULT_ICON);
	highlighticon.image = "/images/markerBlank.png";
	highlighticon.printImage = "/images/markerBlank.png";
	highlighticon.mozPrintImage = "/images/markerBlank.png";
	highlighticon.shadow = "";
	highlighticon.iconSize = new GSize(20, 20);
	highlighticon.iconAnchor = new GPoint(10, 10);
	
	var highlightPoint = new GMarker(new GLatLng(0,0), {icon:highlighticon, zIndexProcess:function (marker,b){ return 101; }});
  map.addOverlay(highlightPoint);
  highlightPoint.hide();
  
	$("li.stop[stop_id][lat][lng]").each(function(index, li) {
		if ($(this).find("table").size() == 0 && $("table.stoptimes").length > 0)
			$(this).hide();
		
		li = $(li);
		if ($(this).attr('street_accessible')=='1')
		{
		  $(this).mouseover(function() {
				highlightPoint.setLatLng(new GLatLng(parseFloat($(this).attr('lat')), parseFloat($(this).attr('lng'))));
        highlightPoint.show();
			}).mouseout(function() {
				highlightPoint.hide();
			});
			
			var title = $(this).find('a').html();
			var icon = new GIcon(reddoticon);
 		  
      if (title.indexOf('Eastbound')!=-1) icon.image = "/images/red_10_dot_e.gif";
      else if (title.indexOf('Westbound')!=-1) icon.image = "/images/red_10_dot_w.gif";
      else if (title.indexOf('Northbound')!=-1) icon.image = "/images/red_10_dot_n.gif";
      else if (title.indexOf('Southbound')!=-1) icon.image = "/images/red_10_dot_s.gif";
      
			$(this)[0].marker = new GMarker(new GLatLng(parseFloat(li.attr('lat')), parseFloat(li.attr('lng'))), {icon:icon,title:title});
			$(this)[0].marker.stop_id = $(this).attr('stop_id');
			
			map.addOverlay($(this)[0].marker);
			GEvent.addListener(map, "click", function(o,l,ol) {
				if (o == null || o.stop_id == null) return;
				$('li[stop_id="' + o.stop_id + '"] a').trigger('click');
			});
		}
		
		li.find('a').click(function() {
			$(this).parents('ul').eq(0).find('li').removeClass('selected')
			$(this).blur().parents('li').eq(0).addClass('selected')
		});
	});
	
  if (document.location.hash.length > 0 && $('a[href="'+document.location.hash+'"]').length > 0)
    setTimeout("$(function(){$('a[href=\"'+document.location.hash+'\"]').eq(0).click();})", 500);
  else
    setTimeout("$(function(){$('li[stop_id] a').eq(0).click();})", 500);
});
