 $(document).ready(function(){
	//display A upon init						
	$('#services > div').not('#servicesA').not('.servicesHeader').hide();

	//event listeners for index links
	$('#servicesIndex > a').each(function() {
		var current = this;
		var currentItem = $(current).attr('custom');
		
		$(this).bind('click', function(event) {
			if($('#' + $(current).attr('custom')).is(':hidden')) //index links can ONLY turn on glossary entries
				toggleServiceCategory($(current).attr('custom'));

			$.scrollTo('#' + $(current).attr('custom'), 800, {offset:{top:-20}});
			});
	});
			
	//event listeners for glossary grey headers
	$('#services .servicesHeader').each(function() {
		var current = this;
		
		$(this).bind('click', function(event) {
			toggleServiceCategory($(current).attr('custom'));
			});
	});
					
 }); //end document.ready

function toggleServiceCategory(itemToDisplay) {
	var categoryItem = '#' + itemToDisplay;

	if($(categoryItem).is(':hidden')) {
		$(categoryItem).fadeInAZ('slow', function(){toggleCloseImage(itemToDisplay)});
		return false;
	} else {
		$(categoryItem).fadeOutAZ('fast', function(){toggleCloseImage(itemToDisplay)});
		return false;
	}
}

function toggleCloseImage(categoryItemReference) {
	//get the reference to the image of the glossary item that was clicked.
	var itemReference = $("#services div[custom = '" + categoryItemReference + "'] img");

	if($('#' + categoryItemReference).is(':hidden')) {
		$(itemReference).attr("src","/global/images/secondary-nav/plus-box-bullet.png");
		return false;
	} else {
		$(itemReference).attr("src","/global/images/secondary-nav/minus-box-bullet.png");
		return false;
	}
}

//overwrite core functions to fix IE7 cleartype font glitch
jQuery.fn.fadeInAZ = function(speed, callback) { 
	return this.animate({opacity: 'show'}, speed, function() { 
		if (jQuery.browser.msie)  
			this.style.removeAttribute('filter');  
		if (jQuery.isFunction(callback)) 
			callback();  
	}); 
}; 
 
jQuery.fn.fadeOutAZ = function(speed, callback) { 
	return this.animate({opacity: 'hide'}, speed, function() { 
		if (jQuery.browser.msie)  
			this.style.removeAttribute('filter');  
		if (jQuery.isFunction(callback)) 
			callback();  
	}); 
}; 
