// JavaScript Document

var loading = '/images/loading_spokes_lg.gif';

function get_data( day, month, year){
	
	// get the current date
	var dows = ['Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ];
	var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
	var selecteddate = new Date(year, month -1, day);
	
	$('#dow').html(dows[selecteddate.getUTCDay()]);
	$('#day').html(selecteddate.getUTCDate());
	$('#month').html(months[selecteddate.getUTCMonth()]);
	// put in a loading image
	
	$("#caldata").html("<p><img src='" + loading +"' alt='loading' /></p>");
	
	$.get("/calendar/data.jsp?dsd=" + day + "&dsm=" + month + "&dsy=" + year + "&act=TDL-SYM-CSW-FVD-MPM-YTH-FAM-SCH-COM-OTH-WEB-TCH&gal=731",
  		function(data){
		
		// remove loading image
    	var cal = eval("(" + data + ")");

		if( cal[0].activities.length > 0 ){
			$("#caldata").html("<ul></ul>");
		} else {
			$("#caldata").html("<p>No events on this day. See the <a href='eventseducation.shtm'>events page</a> for full listings</p>");
		}

		for(i=0; i < cal[0].activities.length; i++){

			a = cal[0].activities[i];
			$("#caldata ul").append("<li><a href='" + a.url + "'>" + a.title + "</a><br />" + a.startTime + "&ndash;" +  a.endTime +"<br/>" + a.description + "</li>");
		} // end for each event
		
		return true;

	});
}// end get_data()

// process the calendar once the page has loaded
$(document).ready( function(){
	//load the height & width utils first
	//$.getScript("/javascripts/jquery.tate.hwxy.js", function(){
  		calendar_init();
		//});
} ); // end document onload


// replace the links in the calendar with AJAX requests
function calendar_init(){
	// get the current date
	// get today's events
	var href = $('.caltable a.selected').attr("href");
	var pattern = /dsd=(\d+).*dsm=(\d+).*dsy=(\d+)/;
	var result = href.match(pattern);
	if(result != null){
		var dsd = result[1];
		var dsm = result[2];
		var dsy = result[3];
			//alert(dsd + ":" +  dsm+ ":" + dsy);
		get_data( dsd, dsm, dsy);
	}
	
	$('.caltable a').click(function () { 
      	//$(this).slideUp(); 
	 	var href = $(this).attr("href");
		var pattern = /dsd=(\d+).*dsm=(\d+).*dsy=(\d+)/;
		var result = href.match(pattern);
		if(result != null){
			var dsd = result[1];
			var dsm = result[2];
			var dsy = result[3];
			//alert(dsd + ":" +  dsm+ ":" + dsy);
			get_data( dsd, dsm, dsy);
			$('.caltable a').removeClass('selected');
			$(this).addClass('selected');
			
		}
		
	  	return false;
    });
	
}


// twitter stuff here:

$(document).ready(function() {
	$("#twitter").getTwitter({
		userName: "tateliverpool",
		numTweets: 1,
		loaderText: "",
		slideIn: true,
		showHeading: false,
		headingText: "",
		showProfileLink: false
	});
});




