var TICKER = {
	container: 	'#programs-ticker',
	url: 		'/scripts/programs.ajax.php',
	goToLink:	'',
	
	load: function(date) {
		var _ticker = this;
		if (!date) {
			var date = new Date();
			var today = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
		} else {
			var today = date;
		}
		
		$.ajax({
			type:	"get",
			url: 	"/scripts/programs.ajax.php?date=" + today,
			//url: 	"/scripts/programs.ajax.php?date=9/2/2010",
			beforeSend: function() {
				$(_ticker.container)
				.find('#programs-ticker-list, #programs-ticker-content')
				.fadeOut('fast', function() {
					$(this).remove();	
				}).stop(true, true);
				
				$('<div></div>')
				.attr('class', 'spinner')
				.hide()
				.appendTo(_ticker.container)
				.fadeTo('fast', 0.6);
			},
			success: function(data) {
				$(_ticker.container)
				.append(data)
				.hide()
				.fadeIn('fast');
			},
			complete: function() {
				/*$('.spinner').fadeOut('fast', function() {
					$(this).remove();
				});*/
				$('.spinner').remove();
				
				$('a.dayNum').hover(function(){
					_ticker.goToLink = $(this).parent().attr('title');
					$(this).parent().removeAttr('title');
				}, function(){
					$(this).parent().attr('title', _ticker.goToLink);
					_ticker.goToLink = '';
				}).click(function(e) {
					e.preventDefault();
					var date = _ticker.goToLink;
					_ticker.load(date);
				});
				
				$('a#cal-month-prev, a#cal-month-next').hover(function(){
					_ticker.goToLink = $(this).attr('title');
					$(this).removeAttr('title');
				}, function(){
					$(this).attr('title', _ticker.goToLink);
					_ticker.goToLink = '';
				}).click(function(e){
					e.preventDefault();
					var date = _ticker.goToLink;
					_ticker.load(date);
				});
				
			}
		});
	}
}

$(document).ready(function() {
	TICKER.load();
});
