month = "feb";

events = {
	"northeast":[
		 {"city" : "new jersey - central", "state" : "", "month": month, "date" : "28"},
		 {"city" : "new york", "state" : "ny", "month": month, "date" : "29"},
		 {"city" : "long island", "state" : "ny", "month": "mar", "date" : "1"}
	],
	"southeast":[
		 {"city" : "miami - ft. lauderdale", "state" : "fl", "month": month, "date" : "22"}
	],
	"mid-atlantic":[
		 {"city" : "baltimore", "state" : "md", "month": month, "date" : "14"},
		 {"city" : "philadelphia", "state" : "pa", "month": month, "date" : "16"}
	],
	"midwest":[
		 {"city" : "dallas", "state" : "tx", "month": 'feb', "date" : "8"},
		 {"city" : "denver", "state" : "co", "month": 'feb', "date" : "21"},
		 {"city" : "kansas city", "state" : "", "month": 'feb', "date" : "22"},
		 {"city" : "st. louis", "state" : "mo", "month": 'feb', "date" : "23"}
	]
}	


	
function formatDate(date){
	
	if(date == '1' || date == '21' || date == '31'){
		format = "st";
	}else if(date == '2' || date == '22'){
		format = "nd";				
	}else if(date == '3' || date == '23'){
		format = "rd";				
	}else{
		format = "th";
	}
	
	return date + format;
}

$(function(){
	//Get all the regions
	$.each(events, function(region){
							
		$("#regions").append("<h4>" + region + " region</h4>");
		
		//Loop over each region to get the cities
		$.each(this, function(i, obj){
			
			eventCity  = this.city;
			eventState = this.state;
			eventMonth = this.month;
			eventDate  = formatDate(this.date);
			comma 	   = ', ';
			
			//don't put comma in if no state.
			if(eventState == ""){
				comma = "";				
			}
									
			linkText = eventCity + comma + eventState + ' - ' + eventMonth + ' ' + eventDate;
			
			$("#regions").append('<a target="_blank" href="city/' + eventCity + '.htm">' + linkText + '</a><br />');
		})
		
	})
})
