/* ==== Showing Cols on Location and FAQ Pages ============================================================ */
var activeID = null;

jQuery(document).ready(function(){
	$(".sub-arrow").hide();
});

function showMe(pId){	
	$("#results").hide();	
	//add on arrow...
	if(activeID != null){		
		$("#arrow-" + activeID).hide();
	}	
	activeID = pId;
	$("#arrow-" + activeID).show();	
	$("#results").html($("#" + activeID).html());
	$("#results").fadeIn("fast");	
}


/* ==== Location Google Map ============================================================ */
function initialize() {
	if (GBrowserIsCompatible()) {
		
		var map = new GMap2(document.getElementById("map_canvas"));
		map.setCenter(new GLatLng(40.746923,-73.988457), 12);
		map.addControl(new GSmallMapControl());
		//map.addControl(new GMapTypeControl());
		
		GDownloadUrl("/locations.xml", function(data) {
	  
			var xml = GXml.parse(data);
			var locations = xml.documentElement.getElementsByTagName("location");
			
			for (var i = 0; i < locations.length; i++) { 	
						
				map.addOverlay(createMarker(xml, i));	    
			 
			}
		});
	}
}    
   
function createMarker(xml, i) {

	var ekIcon = new GIcon(G_DEFAULT_ICON);
	ekIcon.image = "/img/ek-marker.png";
	ekIcon.shadow = "/img/markershadow.png";
	ekIcon.iconSize = new GSize(45, 45);
	ekIcon.shadowSize = new GSize(65, 40);
	ekIcon.iconAnchor = new GPoint(25, 47);
	ekIcon.infoWindowAnchor = new GPoint(20,45);

	markerOptions = { icon:ekIcon };
	title = xml.getElementsByTagName("title")[i].childNodes[0].nodeValue;
	add1 = xml.getElementsByTagName("add1")[i].childNodes[0].nodeValue;
	add2 = xml.getElementsByTagName("add2")[i].childNodes[0].nodeValue;
	cross = xml.getElementsByTagName("cross")[i].childNodes[0].nodeValue;
	phone = xml.getElementsByTagName("phone")[i].childNodes[0].nodeValue;
	hours = xml.getElementsByTagName("hours")[i].childNodes[0].nodeValue;
	lat = xml.getElementsByTagName("lat")[i].childNodes[0].nodeValue;
	lng = xml.getElementsByTagName("lng")[i].childNodes[0].nodeValue;
		
	var point = new GLatLng(parseFloat(lat), parseFloat(lng));		    
	var marker = new GMarker(point, markerOptions);
	var information = "<big><strong>" + title + "</strong></big><br />";
	information += add1 + "<br />" + cross + "<br />";
	information += add2;
	information += "<p>" + phone + "</p>";
	information += "<p>" + hours.replace(/,/gi, "<br />") + "</p>";
	
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(information);
	});
 
	return marker;
}