 /* ------------------------------------------------------------
 * PROJECT        : FHSC Interface Standard
 * FILENAME       : jqfilternav.js
 * ------------------------------------------------------------
 * DATE CREATED   : 21 Sep 2006
 * LAST UPDATED   : 24 Jul 2007
 * ------------------------------------------------------------
 * AUTHOR(S)      : Kevin Scholl (http://www.ksscholl.com/)
 * ------------------------------------------------------------ */

/* ------------------------------------------------------------
 * SIDE FILTER NAVIGATION
 * ------------------------------------------------------------ */

$(document).ready(function(){

  // This hides and shows the side navigation block
	$("#fnBlock,#fnOpenIndicator")
	  .css("display","none")
		
	$("#fnOpenIndicator").click(function() {
		$('#fnBlock,#fnOpenIndicator').animate({opacity: 'hide'}, 500);
		$('#fnClosedIndicator').animate({opacity: 'show'}, 500);
		$('#fnFilters').each(function(){
			if ($(this).css("display") == "block")
				$(this).animate({opacity: 'hide'}, 500);
			});
		});
	$("#fnClosedIndicator").click(function() {
		// Close all open secondary nav lists
		$("div.fn li:has(ul)").each(function(){ 
		  if ($(this).attr("class") == "filterable collapsible")
			  $(this).attr("class","filterable expandable");
		  if ($(this).attr("class") == "collapsible")
			  $(this).attr("class","expandable");
			})
		// Show the side nav
		$('#fnBlock,#fnOpenIndicator').animate({opacity: 'show'}, 500);
		$('#fnClosedIndicator').animate({opacity: 'hide'}, 500);
		});

  // This sets the initial styles of the collapsible Menu items
	$("div.fn")
		.find("li:has(ul)")
			.addClass("expandable")
			.prepend("<div class=\"toggleCtrl\">")
			.end()
		.find("li ul")
			.addClass("secondary")
			.end()

  // This is the Collapse/Expand onClick function
	$("div.fn div.toggleCtrl").click(function() {
    // Close the open secondary nav list
		$(this).parent("li").siblings("li:has(ul)").each(function(){ 
		  if ($(this).attr("class") == "collapsible" || $(this).attr("class") == "filterable collapsible") {
			  $(this).removeClass("collapsible");
			  $(this).addClass("expandable");
				}
			})
		  .end()
		// Set parent LI class
    $(this).parent("li:has(ul)").each(function(){ 
		  if ($(this).attr("class") == "expandable" || $(this).attr("class") == "filterable expandable") {
			  $(this).removeClass("expandable");
			  $(this).addClass("collapsible");
				}
			})
			.end()
		// Control the filtering block display
		if (($(this).parent("li:has(ul)").attr("class") == "collapsible") && ($("#fnFilters").css("display") == "block"))
				$("#fnFilters").animate({opacity: 'hide'}, 1000)
		if ($(this).parent("li:has(ul)").attr("class") == "filterable collapsible") {
//  		if (($("#fnFilters").css("display") == "block")) {
//			  $("#fnFilters")
//					.animate({opacity: 'hide'}, 1000)
//				}
			$("#fnFilters")
				.css("top",$(this).offset({scroll: false}).top - 1 +'px')
  			.animate({opacity: 'show'}, 1000);
			}
		});	

	}); // end ready function