//  Sub Nav Slider

function closeEverything() {
	$(".sub-nav").hide();
	$("#left-nav ul ul:visible").hide();
	$("#nav ul li a").css("background-position","top center");
	$(".more-nav").css("background-position","top center");
};

function closeSingle() {
	$(".sub-nav").slideUp(200);
	$("#nav ul li a").css("background-position","top center");
};	
	
$(function() {

	$("#city-county-admin-btn").click(function() {
		if ($("#city-county-admin").css("display") == "block") {
			closeSingle();
			return false;
		} else {
			closeEverything();
			$("#city-county-admin").slideToggle(300);
			$(this).css("background-position","bottom center");
			return false;
		};
	});
	
	$("#courts-laws-btn").click(function() {
		if ($("#courts-laws").css("display") == "block") {
			closeSingle();
			return false;
		} else {
			closeEverything();
			$("#courts-laws").slideToggle(300);
			$(this).css("background-position","bottom center");
			return false;
		};
	});

	$("#culture-recreation-btn").click(function() {
		if ($("#culture-recreation").css("display") == "block") {
			closeSingle();
			return false;
		} else {
			closeEverything();
			$("#culture-recreation").slideToggle(300);
			$(this).css("background-position","bottom center");
			return false;
		};
	});
	
	$("#education-jobs-btn").click(function() {
		if ($("#education-jobs").css("display") == "block") {
			closeSingle();
			return false;
		} else {
			closeEverything();
			$("#education-jobs").slideToggle(300);
			$(this).css("background-position","bottom center");
			return false;
		};
	});
	
	$("#neighborhood-services-btn").click(function() {
		if ($("#neighborhood-services").css("display") == "block") {
			closeSingle();
			return false;
		} else {
			closeEverything();
			$("#neighborhood-services").slideToggle(300);
			$(this).css("background-position","bottom center");
			return false;
		};
	});
	
	$("#public-safety-btn").click(function() {
		if ($("#public-safety").css("display") == "block") {
			closeSingle();
			return false;
		} else {
			closeEverything();
			$("#public-safety").slideToggle(300);
			$(this).css("background-position","bottom center");
			return false;
		};	
	});
	
	$("#taxes-budgets-btn").click(function() {
		if ($("#taxes-budgets").css("display") == "block") {
			closeSingle();
			return false;
		} else {
			closeEverything();
			$("#taxes-budgets").slideToggle(300);
			$(this).css("background-position","bottom center");
			return false;
		};
	});
	
	$("#voting-public-records-btn").click(function() {
		if ($("#voting-public-records").css("display") == "block") {
			closeSingle();
			return false;
		} else {
			closeEverything();
			$("#voting-public-records").slideToggle(300);
			$(this).css("background-position","bottom center");
			return false;
		};
	});

});


//  Left Navigation  //


$(function() {

    $("#left-nav ul li ul").hide();

    if ($("#left-nav a").hasClass("current")) {
    
        $("#left-nav a.current").parents("ul").show();
        $("#left-nav a.current").parents("ul").parents("li").children(".more-nav").css("background-position","top");
        
    };


    $("#left-nav ul li").click(function(e){
    
        closeSingle();

        // hide the sub-menu of the clicked item
        if ($(this).children("ul").is(':visible')) {
        
            $(this).find("ul").hide(); //find all <ul>'s and child <ul>s in the clicked item and hide them
            
            $(this).find(".more-nav").css("background-position","bottom"); //find all arrows in the clicked item and it's children and adjust them to the closed position
        
        // open the sub-menu for the clicked item
        } else {
        
            $(this).siblings().find("ul").hide(); //find all of the <ul>s and child <ul>s of the clicked item's sibling dom elements and hide them
            $(this).siblings().find(".more-nav").css("background-position","bottom"); //find all arrows in the siblings and their children and adjust them to the closed position
            
            $(this).children("ul").show(); //show the clicked item's child <ul>s
            
            $(this).children(".more-nav").css("background-position","top"); //adjust the arrow on the clicked item to the open position
        };
    
        e.stopPropagation(); //stop the click event from bubbling up to the parent <li>
    
    });

});


//  Remove last 3 Border Bottoms of the Sub Nav  //

$(function() { 

	$("#city-county-admin ul li a").slice(-3).css("border","none");
	$("#city-county-admin ul li a").slice(-3).css("margin-bottom","1px");
	
	$("#courts-laws ul li a").slice(-3).css("border","none");
	$("#courts-laws ul li a").slice(-3).css("margin-bottom","1px");
	
	$("#culture-recreation ul li a").slice(-3).css("border","none");
	$("#culture-recreation ul li a").slice(-3).css("margin-bottom","1px");
	
	$("#education-jobs ul li a").slice(-3).css("border","none");
	$("#education-jobs ul li a").slice(-3).css("margin-bottom","1px");
	
	$("#neighborhood-services ul li a").slice(-3).css("border","none");
	$("#neighborhood-services ul li a").slice(-3).css("margin-bottom","1px");
	
	$("#public-safety ul li a").slice(-3).css("border","none");
	$("#public-safety ul li a").slice(-3).css("margin-bottom","1px");
	
	$("#taxes-budgets ul li a").slice(-3).css("border","none");
	$("#taxes-budgets ul li a").slice(-3).css("margin-bottom","1px");	
	
	$("#voting-public-records ul li a").slice(-3).css("border","none");
	$("#voting-public-records ul li a").slice(-3).css("margin-bottom","1px");

});


$(function() {
		    $('#slider').cycle({
				fx: 'scrollLeft', 
			    speed:    1000, 
			    timeout:  7000,
			    next: '#next-slide',
			    prev: '#prev-slide'
			});
		});

//  Make Content Container the width of the contents inside it
$(function() {

    var originalWidth = $("#content-sidebar").width();
    
    var newWidth = $("#sectionContent").find("table").width() ;
    
    /*ert(originalWidth );
    alert(newWidth );  */
        
    if (newWidth > originalWidth){ 
    	newWidth = newWidth + 45;   
   		$('#content-container').width(newWidth + 'px');    
    }

});






