// JavaScript Document

$(document).ready(function() {
	$("div.expandDiv").each(function() { // find specific elements
		
		var _hiddenHeight = parseInt($(this).prev("div").css("height")); // Set in individual pages
		
		if (parseInt($(this).css("height")) > _hiddenHeight) {
			var _startHeight = parseInt($(this).css("height"));
			$(this).css("height", _hiddenHeight+"px")
				.wrap("<div class=\"wrapDiv\">")
				.parents("div.wrapDiv")
				.append("<div class=\"ceexpand\">read more [+]</div>") 
				.find("div.ceexpand")
				.hover( // add a hover class
					function() { $(this).toggleClass("cehover") },
					function() { $(this).toggleClass("cehover") }
				)
				.toggle( // toggle the click action of the div
					// Open It
					function () { 
						// swap the class and change the HTML
						$(this).toggleClass("cecollapse").html("collapse [-]") 
						// select the div and animate it open
						.siblings("div").animate({height: _startHeight}); 
					},
					// Close It
					function () { 
						// swap the class and change the html
						$(this).toggleClass("cecollapse").html("read more [+]") 
						// select the div and animate it closed
						.siblings("div").animate({height: _hiddenHeight}); 
					}
				);
			}	
			
	  });
	
	$("h4.expandDiv2").each(function() { // find specific elements

		$(this).prepend("<span class=\"expandSpan\">[+]</span>") 
			.find("span.expandSpan")
			.hover( // add a hover class
				function() { $(this).toggleClass("cehover") },
				function() { $(this).toggleClass("cehover") }
			)
			.toggle( // toggle the click action of the div
				// Open It
				function () { 
					// swap the class and change the HTML
					$(this).toggleClass("cecollapse").html("[-]") 
					// select the div and animate it open
					.parents("h4.expandDiv2").next("div").slideDown("normal"); 
				},
				// Close It
				function () { 
					// swap the class and change the html
					$(this).toggleClass("cecollapse").html("[+]") 
					// select the div and animate it closed
					.parents("h4.expandDiv2").next("div").slideUp("normal"); 
				}
			);
		$(this).next("div").css("display", "none");
	  });
	
	
	$("h4.menuItem").click(function() {
		$("h4.clicked").removeClass("clicked");
		$(this).addClass("clicked");
		$("#content ul.active").slideUp('normal', function() {
			$("#content ul.active").removeClass("active");
			$("h4.clicked").next("ul").slideDown('normal');
			$("h4.clicked").next("ul").addClass("active");
		});
	});
	
	
	
	$("h4.h4Details").click(function() {
		$("h4.clicked").removeClass("clicked");
		$(this).addClass("clicked");
		$("#content p.active").slideUp('normal', function() {
			$("#content p.active").removeClass("active");
			$("h4.clicked").next("p").slideDown('normal');
			$("h4.clicked").next("p").addClass("active");
		});
	});
	
		
});