$(document).ready(function(){
	//display #1 upon init						
	$('#questions > div').not('#question1').not('.questionHeader').hide();

	//event listeners for questions
	$('#questions .questionHeader').each(function() {
		var current = this;
		
		$(this).bind('click', function(event) {
			toggleQuestion($(current).attr('custom'));
			});
	});								
 }); //end document.ready

function toggleQuestion(questionToDisplay) {
	var question = '#' + questionToDisplay;

	if($(question).is(':hidden')) {
		$(question).fadeIn('slow', function(){toggleCloseImage(questionToDisplay)});
		return false;
	} else {
		$(question).fadeOut('fast', function(){toggleCloseImage(questionToDisplay)});
		return false;
	}
}

function toggleCloseImage(questionReference) {
	//get the reference to the image of the question that was clicked.
	var questionItem = $("#questions div[custom = '" + questionReference + "'] img");

	if($('#' + questionReference).is(':hidden')) {
		$(questionItem).attr("src","/global/images/secondary-nav/plus-box-bullet.png");
		return false;
	} else {
		$(questionItem).attr("src","/global/images/secondary-nav/minus-box-bullet.png");
		return false;
	}
}

//overwrite core functions to fix IE7 cleartype font glitch
jQuery.fn.fadeIn = 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.fadeOut = function(speed, callback) { 
	return this.animate({opacity: 'hide'}, speed, function() { 
		if (jQuery.browser.msie)  
			this.style.removeAttribute('filter');  
		if (jQuery.isFunction(callback)) 
			callback();  
	}); 
}; 
