// donations - update the amount and item_name values
function donationsOnChange() {
	var sel = $('#d-type option:selected');
	var nameRaw = sel.text();
	var name = nameRaw.replace(/\(\$[0-9]*.00\)/,'');
	name += '(Recipient: '+$('#recipient_name').val()+')';
	var rel = sel.attr('rel');
	$('#amount').val(rel);
	$('#amount-hidden').val(rel);
	$('#item_name').val(name);
}


$(document).ready(function() {

	$('#jcalendar').jcalendar();
	$('.eventPopup').livequery('click', function() {
		var ID = this.id;
		var ids = ID.split('_');
		
		var html = '<h1>'+calEvents[ids[0]][ids[1]][ids[2]]['title']+'</h1>';
		html += '<p class="content">'+calEvents[ids[0]][ids[1]][ids[2]]['content']+'</p>';
		html += '<p class="close"><a href="#">close</a></p>';
		$('#event-details-modal').html(html);
		$('#event-details-modal').fadeIn();
	});
	
	$('#event-details-modal p.close a').livequery('click', function() {
		$('#event-details-modal').fadeOut();
		return false;
	});
	
	// Program day details
	$('.show-day-details').click(function() {
	
		$('.show-day-details').addClass('close');
		$('.show-day-details').removeClass('open');
		$('.day-details').hide();
		$(this).addClass('open');
		$('#'+$(this).attr('rel')).show();

		return false;

/*
		var rel = $(this).attr('rel');

		if($(this).hasClass('open')) {
			$(this).removeClass('open');
			$(this).addClass('close');
			$('#'+rel).hide();
			return false;
		}
		
		if($(this).hasClass('close')) {
			$(this).removeClass('close');
			$(this).addClass('open');
			$('#'+rel).show();
			return false;
		}
*/
	});
	
	// news details
	$('#news-listing li a.details').click(function() {
		var ID = $(this).attr('rel');
		if($(this).hasClass('shown')) {
			$('#news-item-'+ID).hide();
			$(this).removeClass('shown');
			$(this).html('More Details &gt;&gt;');
		} else {
			$('#news-item-'+ID).show();
			$(this).addClass('shown');
			$(this).html('Hide Details');
		}
		
		return false;
	});
	
	// select donation type
	$('#d-type').change(function() {
		donationsOnChange();
	});
	
	$('#recipient_name').keyup(function() {
		donationsOnChange();
	});
	
});