
$j = jQuery.noConflict();
$j(document).ready(function(){

	// ensure backgorund image appears on content page banner area
	if ($j('.ttl_img img').size() > 0) {
		$j('.ttl_h1 h1 span').html($j('.ttl_img').html());
		$j('.ttl_img').remove();
	}
	
	// if "Forms & links" area doesn't contain any content, hide it
	if (($j('.vit-highlight').size() > 0) && ($j('.vit-highlight .ms-formfieldcontainer').size() < 1)) {
		if ($j('.vit-highlight h3 > div').text() == '') {
			$j('.vit-highlight').hide();
		}
	}
	
	// add "alt" class to even/odd rows in content tables
	$j('.contenttable tr:nth-child(odd) td').addClass('alt');
	
	// for event calendar pages, ensure the calendar uses the maximum horizontal width area available
	if ($j('#MontlyViewDefault_CalendarView').size() > 0) {
		$j('#vit-content .vit-content').css('width', '98%');
	}
	
	// insert search keyword into search box, remove it on focus
	$j('.vit-search input:first').val('Search').focus(function() {
		if ($j(this).val() == 'Search') { $j(this).val(''); }	
	}).blur(function() {
		if ($j(this).val() == 'Search' || $j(this).val() == '') { $j(this).val('Search'); }
	});
	
	// if we're on the homepage, and we've navigated to an anchor link, if that anchor link is a tab, activate that tab
	$anchor = document.location.hash.replace('#', '');
	if (($j('.vit-tabbed-navigation-main').size() > 0) && ($anchor != '') && ($j('.vit-tabbed-navigation a[href$="'+$anchor+'"]').size() > 0)) {
		var div1 = $j('.vit-tabbed-navigation a[href$="'+$anchor+'"]').parent().parent();
		var index = div1.parent().find('.topnav_bg').index(div1.get(0));
		$j('.vit-left-content').hide();
		$j('.vit-tabbed-navigation-main .vit-left-content').eq(index).show();
		$j('.vit-tabbed-navigation .topnav_bg').removeClass('active');
		div1.addClass('active');
		syncCssHomepageHeights();
	} else if ($j('.vit-tabbed-navigation-main').size() > 0) {
		$j('.vit-left-content').hide();
		$j('.vit-left-content-home').show();
		$j('.vit-tabbed-navigation-home a').parent().parent().addClass('active');
		syncCssHomepageHeights();
	}
	
	// if we're on a content page, add click handlers to the tabs so that they actually go to the homepage instead, with that anchor link
	$j('#vit-navigation-main li a').click(function(e) {
		if (($j(this).attr('href').indexOf('http://') == -1) && ($j(this).attr('href').indexOf('https://') == -1)) {
			$navigateUrl = '/Pages/default.aspx#' + $j(this).attr('href').replace('/Pages/default.aspx', '').replace('/', '');
			document.location.href = $navigateUrl;
			e.preventDefault();
		}
	});
	
});

