// beginning of to link for google directions
var to = "http://maps.google.com/maps?daddr=";


// beginning of from link for google directions
var from = "http://maps.google.com/maps?saddr=";





// constructor
function league(name, url, park, address, latt, long)
{
	this.name = name;					// name of league



	if( url != '' ) {
		this.url = url;
	} // end if
	else {
		this.url = '';
	} // end else


	// if no park present
	if(park != '')
	{
		this.park = park + "<br/>";		// name of park
	} // end if
	else
	{
		this.park = '';					// when no name of a park
	} // end else
		
	this.latt = latt;					// latt of league
	this.long = long;					// long of league
	
	this.address = address;					// address of league
	
	this.toLeague = "<a href='" + to + addressParse(address) + "'>get directions</a>";		// google directions to address
	this.fromLeague = "<a href='" + from + addressParse(address) + "'>get directions from here</a>";		// google directions from address

	// output for the infowindow
	this.bubble = '<a href="' + this.url + '">' + this.name + "</a><br/>" + this.park + this.address + "<br/>" + this.toLeague + "<br/>"; //+ this.fromLeague;
	
} // end constructor



// takes in address and parses it to remove spaces and add a plus sign where spaces were, to make google directions link
function addressParse(address)
{


	begin = 0;
	space = address.indexOf(' ', begin);
	parseAddress = "";


	// parses each segment of address by adding a plus sign and removing spaces
	while(space != -1)
	{
		// parses section of address
		parseAddress = parseAddress + address.substring(begin, space) + '+';

		begin = space + 1;	// increments beginning pos past previous space

		space = address.indexOf(' ', begin);	// assigns new pos for space
	} // end while

	// adds in last section of address not parses by while loop
	parseAddress = parseAddress + address.substring(begin, address.length);


	return parseAddress;

} // end function addressParse




