function updateCalendar( newDate ) {
	var ajaxUrl = docrootPath + "gato/mini-calendar.jsp";
	
	new Ajax.Updater( "txst-mini-calendar-container", ajaxUrl, {
		parameters: { date: newDate }
	});					
}

function showDetail( id ) {
	$$('.txst-featuredeventslist').each( function( listItem ) {
		if ( listItem.visible() ) {
			Effect.Fade( listItem, { queue: 'end' } );
		}
	});
	
	Effect.Appear( id , { queue: 'end' } );
}

function showListing() {
	$$('.txst-eventdetail').each( function( detailItem ) {
		if ( detailItem.visible() ) {
			Effect.Fade( detailItem, { queue: 'end' } );
		}
	});
	
	$$('.txst-featuredeventslist').each( function( listItem ) {
		if ( ! listItem.visible() ) {
			Effect.Appear( listItem, { queue: 'end' } );
		}
	});
}

function showPage( pageNumber ) {
	$$('.txst-featuredeventslist-items').each( function( page ) {
		if ( page.visible() ) {
			Effect.Fade( page, { queue: 'end' } );
		}
	});
	$$('.txst-featuredeventslist-paginator').each( function( page ) {
		if ( page.visible() ) {
			Effect.Fade( page, { queue: {position: 'end', scope: 'paginator' } } );
		}
	});
	Effect.Appear( 'txst-events-page-' + pageNumber, { queue: 'end' } );
	Effect.Appear( 'txst-featuredeventslist-paginator-' + pageNumber, { queue: {position: 'end', scope: 'paginator' } } );
}

Event.observe( document, "dom:loaded", function() {

	// Remove sample text when user clicks in search field
	var originalSearchFieldText = $F("calendarSearchTerm");
	Event.observe( "calendarSearchTerm", "focus", function() {
	    if ( $F("calendarSearchTerm") == originalSearchFieldText ) $("calendarSearchTerm").value = "";
	});

	space_event_types();
	add_breaks_between_fe_item_rows();

    // Activate the pop-up Other Calendars navigation
    Event.observe( "other-calendars-popup", "change", function() {
        var url = $F("other-calendars-popup");
        if ( url.substring( 0, 4 ) == "http" ) {
            window.location = url;
        }
     } );
     
});


function add_breaks_between_fe_item_rows() {
	$$('.txst-featuredeventslist-item:nth-child(3n)').each(function(item) {
		item.insert({ after: "<div style=\"clear: both\"></div>" });
	});
}

function space_event_types() {
	$$('.txst-featuredevents-types').each(function(types_box) {
		var types = types_box.select('a');
		types.each(function(type,typeindex) {
			var set_width = Math.floor(753/types.length);
			
			if ( typeindex == types.length-1 ) {
				var total_width = set_width*(types.length-1);
				set_width = 753-total_width;
			}
						
			type.setStyle({
				width: (set_width-1) + 'px',
				paddingLeft: '0px',
				paddingRight: '0px'
			});
		});
			
	});
}
