$(document).ready(function() {
	$(".showhide-title").attr('title','Expand Topic');
	
	//remove the class so the only code that controls the slide downs is in this file and not in the hig.jquery file
	$(".showhide-title").removeClass('show-hide-next');
	
	$(".showhide-title").click(function (event) {

		if($(this).next().css('display') == 'none'){
				$("div.show-active-only").slideUp("normal").prev().removeClass('opened');
				$(this).next().slideDown("normal");
				$(this).addClass('opened');
			}
		else if ($(this).next().css('display') == 'block'){
				$(this).next().slideUp("normal",function(){
					if ($.browser.msie && $.browser.version == "8.0") {
						$(".show-hide-item").css('position','relative');
						$(".show-hide-item").css('position','static');
					}
				});
				$(this).removeClass('opened');
				
			}


		numItems = $(".show-hide-item > div.showhide-title").size();
		numOpenedItems= $(".show-hide-item > div.opened").size();

		if( $(this).hasClass('opened') ){
			$(this).attr('title','Expand Topic');
		}
		else {
			$(this).attr('title','Collapse Topic');
		}

		if (numItems == numOpenedItems ) { //they are all open, mark expand inactive and collapse active
			$(".expand-all a").attr('class', 'inactive');
			$(".collapse-all a").attr('class','active');
		}
		else if (numOpenedItems == 0) { //they are all closed, mark expand active and collapse inactive
			$(".expand-all a").attr('class', 'active');
			$(".collapse-all a").attr('class', 'inactive');
		}
		else { //both expand and collapse are active
			$(".expand-all a").attr('class', 'active');
			$(".collapse-all a").attr('class', 'active');
		}





	});




	//adds exapand all and collapse all link to show hide component
	$(".show-hide-wrapper").prepend('<div class="expand-all"><a class="active" href="javascript:void(0)"><span>Expand All</span></a></div><div class="collapse-all"><a class="inactive" href="javascript:void(0)"><span>Collapse All</span></a></div>');

	$(".expand-all").click(function () {
		if( $(this).find('a').hasClass('active') ){
			$(".showhide-title").next().slideDown("normal");		
			$(".showhide-title").addClass('opened');
			$(".showhide-title").attr('title','Collapse Topic');
			$(this).find('a').removeClass('active').addClass('inactive');
			$(".collapse-all").find('a').removeClass('inactive').addClass('active');

		}

	});

	$(".collapse-all").click(function () {
		if( $(this).find('a').hasClass('active') ) {
			$(".showhide-title").next().slideUp("normal",function(){
				if ($.browser.msie && $.browser.version == "8.0") {
					$(".show-hide-item").css('position','relative');
					$(".show-hide-item").css('position','static');
				}
			});			
			$(".showhide-title").removeClass('opened');
			$(".showhide-title").attr('title','Expand Topic');
			$(this).find('a').removeClass('active').addClass('inactive');
			$(".expand-all").find('a').removeClass('inactive').addClass('active');

		}

	});
	
});




