function regenerateFeaturedList(s, d, imageSize) {
	
	var height = $('featured_summary').getHeight();
	$('featured_document').setStyle({'height':height + 'px'});
	
	new Effect.Opacity('featured_document', {
		
		duration:.5,
		from:1.0,
		to:0.0,
		
		afterFinish: function () {
			
			new Ajax.Updater('featured_document', '/ajaxShowFeaturedDocuments.php', {
				
				parameters: {s: s, d: d, imageSize: imageSize},
				onComplete: function() {
					
					if (!$('featured_summary_image')) {
						
						fadeinFeaturedDocument();
						
					}
					
				}
				
			});
			
		}
		
	});
	
}

function fadeinFeaturedDocument() {
	
	height = $('featured_summary').getHeight();
	$('featured_document').setStyle({'height':height + 'px'});
	
	new Effect.Opacity('featured_document', {

		duration:.5,
		from:0.0,
		to:1.0
		
	});
	
}

function regenerateFocusedDocuments(maxPerRow, imageSize) {
	
	new Ajax.Updater('focused_documents_container', '/ajaxShowFocusedDocuments.php', {
		
		parameters: {maxPerRow: maxPerRow, imageSize: imageSize}
		
	});
	
}

function regenerateFocusedSubjects() {
	
	new Ajax.Updater('subject_focus_container', '/ajaxShowFocusedSubjects.php');
	
}

function changeFocusedCategoryDate(focusedCategory, selectedDate, allCategoriesType) {
	
	$('focused_category_loader').show();
	
	new Ajax.Updater('focused_category_container', '/ajaxShowFocusedCategory.php', {
		
		parameters: {focusedCategory: focusedCategory, selectedDate: selectedDate, allCategoriesType: allCategoriesType},
		evalScripts: true,
		onComplete: function() {
			
			if ($('focused_category_date_options')) {
				
				removeOld = $('focused_category_date_options').select('a.focused_category_date_option_selected');
				addNew = 'focused_category_option_' + selectedDate;
				$(removeOld[0]).removeClassName('focused_category_date_option_selected');
				$(addNew).addClassName('focused_category_date_option_selected');
				
			}
			
			$('focused_category_loader').hide();
			
		}
		
	});
		
}

function toggleSummary(elementId, id, action, limit, type) {
	
	new Ajax.Updater(elementId, '/ajaxToggleSummary.php', {
		
		parameters: {elementId: elementId, id: id, action: action, limit: limit, type: type}
		
	});
	
}

function removeFocusedDocument(id, maxPerRow, imageSize) {
	
	new Ajax.Request('/ajaxRemoveFocusedDocument.php', {
		
		parameters: {id: id, maxPerRow: maxPerRow, imageSize: imageSize}
		
	});
	
}

function removeSubjectFocus(id) {
	
	new Ajax.Request('/ajaxRemoveSubjectFocus.php', {
		
		parameters: {id: id}
		
	});
	
}

function removeDocumentTypeFocus(id) {
	
	new Ajax.Request('/ajaxRemoveDocumentTypeFocus.php', {
		
		parameters: {id: id}
		
	});
	
}

function regenerateEventList(s, d, maxDisplay, imageSize, showSummary) {
	
	new Ajax.Updater('upcoming_events_container', '/ajaxShowUpcomingEvents.php', {
		
		parameters: {s: s, d: d, maxDisplay: maxDisplay, imageSize: imageSize, showSummary: showSummary}
		
	});
	
}

document.observe('dom:loaded', function() {
	
	if ($('announcements_container')) {
		
		Accordion = new accordion('announcements_container', {
		    classNames : {
		        toggle : 'accordion_toggle',
		        toggleActive : 'accordion_toggle_active',
		        content : 'accordion_content'
		    },
		    direction : 'vertical'
		});
		
	}
	
	if ($('focused_category_menu')) {
		
		new ProtoFish('focused_category_menu', '500', 'hover', false, false, false);
		zIndexWorkaround();
		
	}
	
});

//brute force z-index mod for IE7
function zIndexWorkaround() {
	
	//add option to check if the browser is IE here
		
		//for each div with class menu (i.e., the thing we want to be on top),
		$$("ul.menu").each(function(menu) {
			
			//for each of its ancestors
			menu.ancestors().each(function (a) {
				
				var pos = a.getStyle("position");
				
				//if it's positioned,
				if(pos == "relative" || pos == "absolute" || pos == "fixed") {
					
						a.addClassName("menu_on_top");
													
				}
				
			});
			
		});
		
	//close optional browser check here
	
}

//show the spinner whenever anything ajax is happening 
Ajax.Responders.register({
	onCreate: function() { $('spinner').show(); },
	onComplete: function() {
			
			if (0 == Ajax.activeRequestCount) {
				
				$('spinner').hide();
								
			}
			
		}
});
