/*
 * This file is used with the left nav component
 * Requires jQuery
 */

// jQuery documnet ready function
$(function(){
	// Add triggers to the container headers
	$('#left_nav .container h1 ~ ul').prev('h1').prepend('<div class="trigger"></div>');
	
	// Show icon to indicate the ul is "open" for visible ul
	$('#left_nav .container h1 ~ ul:visible').prev().children('.trigger').addClass('nav_open');
	
	// Remove the link to the provisioning page of the packages this user already owns
	$('.premium_services .container:has(ul) h1 > a').each(function(){
		$(this).replaceWith('<span>' + $(this).text() + '</span>');
	});
	
	// Open sub menu when the trigger or non-link container header is clicked
	$("#left_nav .trigger, #left_nav .container span").click(function(){
		// toggle visiblity of the ul that is the next sibling of the trigger's parent
		$(this).parent().next('ul').slideToggle('normal');
		// toggle the trigger image
		$(this).parent().children('.trigger').toggleClass('nav_open');
	});

	$('#left_nav a').each(function(){
		if (window.location.href.indexOf($(this).attr('href')) >= 0 && $(this).attr('href').length > 1)
		{
			$(this).addClass('current');
		}
	});

});
