/* PRIMARY NAV */

	$('#header .nav > ul > li').hover(function () {
		
		var $this = $(this),
			links = $this.find('ul');
		if (links.length) {
			var link = $this.children('a').clone(false).wrap('<span>').parent();
			links.wrap('<div class="over"></div>').parent().prepend(link);
		}

	}, function () {

		var $this = $(this),
			wrapper = $this.find('.over');
		if (wrapper.length) {
			$(this).find('span').remove().end().find('ul').unwrap('');
		}

	});

/* SECTION NAV */

	// hack to account for posts not highlighting section nav
	$('#secondary .nav.budget-blog .page-item-12739').addClass('current_page_item');
	$('#secondary .nav.budget-updates .page-item-12853').addClass('current_page_item').parent().closest('li').addClass('current_page_ancestor');

	$('#secondary .nav .current_page_item').append('<span>').children('a').click(function () {
		return false;
	});
	var openLink;
	$('#secondary .nav > ul > li:not(.current_page_item, .current_page_ancestor) .children').closest('li').hover(function () {
		openLink = $(this).addClass('open');
	}, function () {
		openLink.removeClass('open');
	}).children('a').click(function (e) {
		var $this = $(this);
		if (e.pageX - $this.offset().left > 205) {
			$this.siblings('.children').toggle();
			return false;
		}
	});

/* SPOTLIGHT BOX */

(function () {
	var spotlight = $('.spotlight');

	spotlight.find('.nav li').eq(0).addClass('on');
	spotlight.find('div.quote').eq(0).addClass('on');

	spotlight.find('.nav li a').click(function () {
		var $this = $(this);
		if ($this.parent().hasClass('on')) {
			return;
		}

		spotlight.find('.on').removeClass('on');

		$this.parent().addClass('on');
		$('#' + this.href.split('#')[1]).addClass('on');

		return false;
	});

})();

/* PLUM BOOK */

$('#ddlAllDepartments').change(function () {
      if (this.selectedIndex == 0) {
        return;
      }
      window.location = '/plum-book/?cat=' + this.options[this.selectedIndex].value;
});

/* CANDIDATES */

(function () {
	
	$('#candidateChooser').change(function () {
	      if (this.selectedIndex == 0) {
	        return;
	      }
	      window.location = this.options[this.selectedIndex].value;
	});

	var headers = $('#primary .content h2');
	if (headers.length > 2) {
	  var cnt = 0,
	      sectionChooser = $('<select id="sectionChooser">').prependTo('#primary .content').change(function () {
	        if (this.selectedIndex == 0) {
	          return;
	        }
	        window.location.hash = this.options[this.selectedIndex].value;
	      }).append('<option value="">Jump to a Section</option>');
	  headers.each(function () {
	    if ($(this).text() !== 'Did You Know?') {
	      cnt++;
	      $(this).attr('id', 'section' + cnt);
	      sectionChooser.append('<option value="section' + cnt + '">' + $(this).text() + '</option>');
	    }
	  });
	} 

})();

/* EMAIL SIGNUP PLACEHOLDER */

$("#sidebarSignupEmail").textPlaceholder();
