/*
 * Homepage specific JavaScript actions
 */

$(document).ready(function() {
	
	// daily preview AJAX navigation
	$('#daily-preview-navigation a').click(function() {

		
		loadDailyPreviewEvents($(this).attr('class'));
		
		return false;
	});
	
	// hover popups for the daily preview
	$('#daily-preview-events li a').not('#daily-preview-more a, #daily-preview-less a').tooltip({
		top:		10,
		left: 		-120,
		delay: 		0,
		showURL: 	false,
		extraClass: "daily-preview", 
    	fixPNG: 	true,
		bodyHandler: function() {
     		return $(this).next().html();
   		}
	});
	
	// display more events 
	$('#daily-preview-more a').live("click", function() {
		$('#daily-preview ul.more-events').show('slow');
		$(this).hide();
		$('#daily-preview-less a').show();
		return false;
	});
	
	$('#daily-preview-less a').live("click", function() {
		$('#daily-preview ul.more-events').hide('slow');
		$(this).hide();
		$('#daily-preview-more a').show();
		return false;
	});
	
});

function loadDailyPreviewEvents(date_direction)
{
	$("#loading").show(); // ajax indicator
	$.getJSON("/dayEvents/"+ $('#daily-preview-year').val() +"/"+ $('#daily-preview-month').val() +"/"+ $('#daily-preview-day').val(), {
		type:		'daily-preview',
		direction: 	date_direction
	}, function(json) {
		$("#loading").hide(); // ajax indicator
		
		// update the daily preview title
		$('#daily-preview-date').html(json.title);
		
		// update the current date fields
		$('#daily-preview-day').val(json.day);
		$('#daily-preview-month').val(json.month);
		$('#daily-preview-year').val(json.year);
		
		// replace the daily preview list with the new data
		$('#daily-preview-events').html(json.events);
		
		// add tooltips to all daily preview items
		$('#daily-preview-events li a').not('#daily-preview-more a, #daily-preview-less a').tooltip({
			top:		10,
			left: 		-120,
			delay: 		0,
			showURL: 	false,
			extraClass: "daily-preview", 
	    	fixPNG: 	true,
			bodyHandler: function() {
	     		return $(this).next().html();
	   		}
		});
	});
}
