// JavaScript Document

// From orginal Schawk site build, updated with new tags

if (Drupal.jsEnabled) {
	$(document).ready(function(){
		//collapse all blocks including first one
		$("div.team_member > div.member_content").hide();
		//collapse all images including first one	  
		$("div.team_member > div.member_content > div.image").hide();
		
		//OR:
		
		//colapse all blocks except the first one
		//$("div.team_member > div.member_content:not(:first)").hide();
		//colapse all image execpt the first one ... keey the animation smooth.
		//$("div.team_member > div.member_content > div.image:not(:first)").hide();
		
		
		$("div.team_member > h2.closed").click(function(){
			//is the block open? 
			if($(this).hasClass("open")){			  
				//switch the arrow class, hide the image first ... then when it's done fire the callback to rollup the block
				$(this).removeClass("open").addClass("closed").siblings("div.member_content").children("div.image").hide("slow", function(){
					$(this).parent("div.member_content").slideUp("slow");
				})	  
			}else if($(this).hasClass("closed")){
				//Is there any other block open?
				if($("div.team_member > h2.open").length > 0){
					//Set a reference to the clicked block 
					clicked = this;
					//switch the arrow class, hide the image first ... then when it's done fire the callback 
					$("div.team_member > h2.open").removeClass("open").addClass("closed").siblings("div.member_content").children("div.image").hide("slow", function(){
						//hide the open block ... then when it's done
						$(this).parent("div.member_content").slideUp("slow", function(){
							//switch the arrow class rolldown the box .. then after it's done show the image
							$(clicked).removeClass("closed").addClass("open").siblings("div.member_content").slideDown("slow", function(){
								$(this).children("div.image").show("slow");
							});
						});
					})
				}else{
					$(this).removeClass("closed").addClass("open").siblings("div.member_content").slideDown("slow", function(){
						$(this).children("div.image").show("slow");
					});							  
				}
			}
		})
		//need first one to no longer have arrow pointing down as it is now closed so I am just commenting out the command to open it
		//add the class so the first one has the arrow pointing down
		//$("div.team_member > h2:first").removeClass("closed").addClass("open");
	});
}
