jQuery(document).ready(function($) {

	// open external links in new window
	$("a.link-external").attr('target', '_blank');
	
	// Left column navigation tree
	$('ul#navigation').addClass('treeview');
	$("ul#navigation").treeview({
		persist: "location",
		collapsed: true,
		unique: true
	});
	
	$('table.cert-table a.expand').click(function(e){
		e.preventDefault();
		$(this).toggleClass('expanded');
		$(this).siblings('ul').toggle();
	});

  var error_context = 'body.page-error #content .box p';
  
  if ($(error_context).exists()) {
    $(error_context).addClass('error');
  };

  // zebra-stripe the TABLE rows
  $('table.article-list tbody tr:first td ').css('border', 'none');
  
	search_title = $('#nav ul li.search').attr('title');
	
	$('#nav form#search input').focus(function() {
		$(this).attr('value', '');
	});
	
	$('#nav form#search input').blur(function() {
		$(this).attr('value',search_title);
	});
	
	$('div.list-articles ul li:last, div#nav-sub li:last').css('border', 'none');
	
	if ($('div#promotions').exists()) { // on homepage
	  $('div#promotions div.promo p:first-child').addClass('promo-pad');
	
    $('div#promotions div#nav-home-services ul li:last a').css({
  		'border': 'none',
  		'background-image': 'url(/images/themes/v1/ui/hdr-bl-corner-on.gif)',
  		'background-repeat': 'no-repeat',
  		'background-position': 'left bottom'
  	});
	}

  if ($('div#nav-news').exists()) { // on homepage
    var links = $('div#nav-news a');
    var href = window.location.href.replace(/.+(\d{4})\/?(\d{2}\/?)?$/, "$1");
    
    links.each(function() {
      $this = $(this);
      if ($this.text() == href) {
        $this.addClass('current');
      }
    });
    
    
    
  }
});

