jQuery(document).ready(function() {
	jQuery(".labelize input:text").clearingInput();
});

Cufon.replace('.frank-book', {hover: true, fontFamily: 'ITC Franklin Gothic Book'})('.frank-demi', {hover: true, fontFamily: 'ITC Franklin Gothic Demi'})('.synchro', {hover: true, fontFamily: 'Synchro LET'});

function side_nav(){
  // Hide all subnavigation
  jQuery('#section-nav ul ul').hide();

  var path = location.pathname;
  if (path == '/') {
    jQuery('#section-nav a[href$="' + location + '"]').parent().addClass('nav_active'); // check path as typed exactly
    jQuery('#section-nav a[href$="' + location + '/"]').parent().addClass('nav_active'); // check path with an extra trailing slash added
  } else {
    jQuery('#section-nav a[href$="' + path + '"]').parent().addClass('nav_active'); // check path as typed exactly
    jQuery('#section-nav a[href$="' + path + '/"]').parent().addClass('nav_active'); // check path with an extra trailing slash added
  }
  // show all parent sibling
  jQuery('#section-nav li.nav_active').parent().show();
  // show child
  jQuery('#section-nav li.nav_active').children('ul').show();

  var here = jQuery('#section-nav li.nav_active a:first').addClass('current-page');
}

jQuery(function($j) {side_nav();});

function toggleCollapsible(id)
{
	if (document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == '') {
		document.getElementById(id).style.display = 'block';
	} else {
		document.getElementById(id).style.display = 'none';
	}
}

function track(link, category, action) {
  try {
    var pageTracker = _gat._getTracker("UA-4208897-5");
    pageTracker._setDomainName(".sundance.org");
    pageTracker._trackEvent(category, action);
    setTimeout('document.location = "' + link.href + '"', 100)
  }catch(err){}}

searchIndex = 0;

function navigateSearchDown() {
	if (document.getElementById("search-suggestion" + (searchIndex + 1))) {
		if (document.getElementById("search-suggestion" + searchIndex)) {
			document.getElementById("search-suggestion" + searchIndex).className = '';
		}
		searchIndex++;
		document.getElementById("search-suggestion" + searchIndex).focus();
		document.getElementById("search-suggestion" + searchIndex).className = 'active';
	}
}

function navigateSearchUp() {
	if (document.getElementById("search-suggestion" + (searchIndex - 1))) {
		if (document.getElementById("search-suggestion" + searchIndex)) {
			document.getElementById("search-suggestion" + searchIndex).className = '';
		}
		searchIndex--;
		document.getElementById("search-suggestion" + searchIndex).focus();
		document.getElementById("search-suggestion" + searchIndex).className = 'active';
	}
}

function lookup(string, e)
{	
	if (string.length == 0) {jQuery('#search-suggestions').fadeOut();} else {
		jQuery.post('/search.php', {query: string}, function(data) {
			jQuery('#search-suggestions').fadeIn();
			jQuery('#search-suggestions').html(data);
			searchIndex = 0;
		});
	}
}
