$('html').addClass('js-enabled');

$(document).ready(function() {
	/*
	 * HOME PAGE enhancements
	 */
	 $('.rollover-link').each(function() {
		var _offImg = $(this).children()[0];
			_offImg.style.zIndex = '2';
		var _offImgSrc = _offImg.src;
		var _onImg = _offImgSrc.replace('_off','_on');
		$(this).append('<img src="'+_onImg+'" style="z-index: 1;" />');
		$(this).hover(
	      function () {
	        var _child = $(this).children()[0];
			$(_child).fadeOut(100);
	      }, 
	      function () {
	       	var _child = $(this).children()[0];
			$(_child).fadeIn(100);
	      }
		);	
	});
	/*
	 * VIDEO links
	 */
	$('#home-intro-video-link').click(function(e){
		openVideo(this.href,'index.jsp?show=video&xhr=true');
		e.preventDefault();
	});
	$('#news-features-video-link').click(function(e){
		openVideo(this.href,'features_buschina.jsp?show=video&xhr=true');
		e.preventDefault();
	});
	$('#feature-healthdisparity-video-link').click(function(e){
		openVideo(this.href,'features_healthcare_disparity.jsp?show=video&xhr=true');
		e.preventDefault();
	});
	/*
	 * AUDIO links
	 */
	$('a.audio-link').click(function() {
		loadAudio(this);
		return false;
	});
	/*
	 * PERSPECTIVE boxes
	 */
	enhancePerspectives();
	/*
	 * TABS
	 */	
	//set default tab state and hide non-default content
	if($('.tabs').length != 0) {
		enhanceTabs();
	}
	

	//EXPANDER ASIDE BOXES
	$('.aside-toggle .aside-header').toggle(
		function() {
            $(this).css('backgroundPosition','0 -50px').siblings().slideDown();
		},
		function() {
			$(this).css('backgroundPosition','0 0').siblings().slideUp();
		}			
	); 
	
	
	
	/*
	 * MATRIX enhancements
	 */
	if($('body.priorities_engagement').length !== 0) {
		 if (location.search.indexOf('show=matrix') !== -1) {
			$('a#matrix-link img').hide();
		 } else if (location.hash.indexOf('matrix') !== -1) {
			$('a#matrix-link img').hide();
			$('#matrix').show();
		}
	}
	$('a#matrix-link').click(function() {
		var $matrix = $('#matrix')
		var _open = $matrix.css('display') !== 'none';
		if(_open) {
			$(this).find('img').show();
			$matrix.slideUp();
			location.hash="/";
		} else {
			$(this).find('img').hide();
			$matrix.slideDown();
			location.hash="/matrix";
		}
		return false;
	});
	
	
	
	
	
	/*
	 * PERFORMANCE METRICS enhancements
	 */
	if($('body').hasClass('performance_metrics')) {
		//hide the data table
		if(document.getElementById('metric-image') != null) {
			$('#metric-image').attr('useMap','#chart-map');
		}
		//attach select onchange event
		enhanceMetricsForm();
		// create tooltips for area map
		$('area').tooltip();
		// enable rollover images for tables
		activateTableRollovers();	
	}
	/*
	 * NEWS enhancements
	 */
	if(document.getElementById('news-articles') != null) {
		//test if landing page
		document.getElementById('releases-item') != null ? loadNewsFeed(2) : loadNewsFeed();
	}
	/*
	 * GLOBAL ENHANCEMENTS
	 */
	//add print page link
 	$("#tools-page").prepend('<a href="javascript:window.print();" id="print-page-link" class="replace_" title="Print"><span></span>Print</a>');
 	//suppress subnav current clicks
	$('#nav-sub a.current:not(.active)').click(function() {
		return false;
	});
 	//open pages in new window
	$('a.external-link, a.download-link, a.site-link, a.news-link, a.transcript-link').not('.internal-link').click(function() {
		window.open(this.href);
		return false;
	});
	//replace form reset buttons with images
	if($('input[type=reset]').length != 0) {
		replaceFormResets();
	}
	//attach the search encoding
	$('#ge_search').submit(function() {
		var tEl = $('#textToSearch');
			tVal = tEl.val();
			tEl.value = GE_encodeURIComponentNew(tVal);
			return true;	
	});	
 });
 /*
	Executes proprietary command to force IE to cache all background images 
		which prevents the browser from fetching the same image repeatedly when using CSS hover background repositioning
	(http://support.microsoft.com/?scid=kb;en-us;823727&spid=2073&sid=global)
*/
if($.browser.msie && parseInt($.browser.version) === 6) {
	try {
		document.execCommand("BackgroundImageCache",false,true);
	} catch(e) {
		// just in case
	}
}