// JavaScript Document

$(document).ready(function() {
	//Search Input
	$('input#keywordSearch').focus(function() {
		if(this.value == "Search") {
			this.value = "";
		}
	});
	$('input#keywordSearch').blur(function() {
		if(this.value == "") {
			this.value = "Search";
		}
	});

	//Drop-downs for global navigation
	$('#globalNav li').hover(function() {
		$(this).find('ul.level2 li').hover(function() {
			$(this).parents('li').addClass('hover');
		},
		function() {
			$(this).parents('li').removeClass('hover');
		});
	});
	// a little love for ie7 & lower
	if ($.browser.msie && $.browser.version <= '7.0') {
		$('#globalNav li').hover(function() {
			$(this).find('ul.level2 li').hover(function() {
				$(this).find('ul.level3').parent('li').css({'z-index': 150});
				//for weirdness with css hover state
				$(this).find('ul.level3').show();
			},
			function() {
				$(this).find('ul.level3').parent('li').css({'z-index': 'auto'});
				$(this).find('ul.level3').hide();
			});
		});
	}
	// a little love for ie6
	if ($.browser.msie && $.browser.version <= '6.0') {
		$('#globalNav li').hover(function() {
			$(this).find('ul.level2').show();
		},
		function() {
			$(this).find('ul.level2').hide();
		});
	}
	
	$('#globalNav li a').each(function() {
		var thisHref = $(this).attr('href');
		var thisHref = thisHref.replace('/page', '');
		var thisHrefArr = thisHref.split('/');
		var thisHrefLength = thisHrefArr.length;
		// last alias in the array.  This is checked to get the active parent
		var aliasToMatch = thisHrefArr[thisHrefArr.length-1];
		
		var aliasBreadCrumbArr = AliasBreadcrumb.split('/');
		var aliasBCLength = aliasBreadCrumbArr.length;
		// first alias in the array - 0 is blank
		var parentPageAlias = aliasBreadCrumbArr[1];
		
		//set current page li class to active
		if(thisHref == AliasBreadcrumb) {
			$(this).parent('li').addClass('active');
		}
		//set parent li class to active
		if(aliasToMatch == parentPageAlias) {
			$(this).parent('li').addClass('active');
		}
		if(aliasBCLength == 4) {
			if(AliasBreadcrumb.indexOf(thisHref) >= 0 ) {
				$(this).parent('li').addClass('active');
			}
		}
	});
	
	
	//Hide/Show tab navigation
	$('#featureTabs .tabNav a').click(function() {
		$('#featureTabs .tabNav a').each(function() {
			$(this).removeClass('active');
		});
		$(this).addClass('active');
		var ttShow = $(this).attr('rel');
		$('#featureTabs .featureTab').each(function() {
			if($(this).attr('id') == ttShow) {
				$(this).addClass('active');
			}
			else{
				$(this).removeClass('active');
			}
		});
	});

	//Equal columns
	$(window).load(function() {
		var colArray1 = new Array($('#leftCol'), $('#centerCol'));
		var colArray2 = new Array($('.contentWrapper'), $('#rightCol'));
		var maxHeight1 = Math.max(colArray1[0].height(), colArray1[1].height());
		var maxHeight2 = Math.max(colArray2[0].height(), colArray2[1].height());
		for(i=0; i<colArray1.length; i++) {
			if(colArray1[i].height() < maxHeight1) {
				colArray1[i].css({'min-height': maxHeight1});
			}
		}
		for(i=0; i<colArray2.length; i++) {
			if(colArray2[i].height() < maxHeight2) {
				colArray2[i].css({'min-height': maxHeight2});
			}
		}
	});	
	
	// Accordion Content
	$('a.openShow').click(function() {
		var accClass = $(this).attr('class');
		var accNum = accClass.replace('openShow ', '');
		$('#' + accNum).slideToggle();
		if($(this).text() == '+') {
			$(this).text('-');
		}
		else {
			$(this).text('+');
		}
	});
	
	if($('.calHead .evtCapt').height() > 0) {
		captH = $('.calHead .evtCapt').height();
		$('.calHead .featuredInfo').css({'padding-bottom': captH + 10});
	}

});

if(navigator.appName == "Microsoft Internet Explorer") {
  httpSimple = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  httpSimple = new XMLHttpRequest();
}


