// Global Scripts
//toggle function for editor
function toggle(id){ 
    tarID = document.getElementById(id);
    tarID.style.display = (tarID.style.display == 'block') ? 'none' : 'block';
}
//easing
	jQuery.easing['swingOld'] = jQuery.easing['swing']; //rename the swing function
	jQuery.extend(jQuery.easing,{
		easingFunc: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	}
	});
	//Preload Images
	jQuery.preloadImages = function(){
		for(var i = 0; i<arguments.length; i++){
			jQuery("<img>").attr("src", arguments[i]);
		}
	};

// Actions
$(document).ready(function(){
	
	// Turn off current link
	var noClick = 'dt a, #tabNav a';
	$(noClick).click(function() {
			return false;														 
	});		
	
	// slidedown and fade in												 
	jQuery.fn.slideDownFade = function(speed, easing) {
			return this.animate({height: 'show'}, speed, easing);	
		};
	
	// Healer Links
	var hoverConfig = {sensitivity: 3, interval: 50, over: showMenu, timeout: 300, out: hideMenu };
	function showMenu() {
		$(this).children('dt').children('a').children('span').fadeOut(250);
		//$(this).children('dd').slideDownFade(500, 'swing');
		$(this).children('dd').slideDown(500);
	};
	function hideMenu() {
		$(this).children('dt').children('a').children('span').fadeIn(250);
		$(this).children('dd').slideUp(500);
	};
	$('#healerMenu').hoverIntent(hoverConfig);
	
	// Healer Details
	var hoverConfigHealer = {sensitivity: 3, interval: 70, over: showHealer, timeout: 50, out: hideHealer };
	function showHealer() {
		var healerDetailName = $(this).children('i').text(); // identify comment
		var healerDetailText = $(this).children('img').attr('alt'); // identify name
		var detailHTML = '<span>' + healerDetailText + '</span><h5>' + healerDetailName + '</h5>'; // concatonate HTML
		$('#healerDetails div').append(detailHTML); // write solution
		$('#healerDetails div').fadeIn(150);
		$(this).blur();
		
	};
	function hideHealer() {
		$('#healerDetails div').html('');
		$('#healerDetails div').fadeOut(150);
	};
	$('#healerWrap ul li a').hoverIntent(hoverConfigHealer);
	
	// Site Menu	
	$('#siteMenu').hoverIntent(hoverConfig);

	// Cycle Images
	$('#pgImg').cycle({
		timeout: 6000,
		speed: 2000
	});
	
	//tabbed page
	$('#tabNav a:first').addClass('current');
	$('#pgTabContentWrap .pgTabContent:first').show();
	$('#tabNav a span').hover(function(){
			$(this).css('cursor','pointer');
		},
		function() {
			$(this).css('cursor','default');
		});
	$('#tabNav a').click(function(){									 
		var tabIndex = $('#tabNav a').index(this);
		var contentIndex = '.pgTabContent:eq('+tabIndex+')';
		var contentNotIndex = '.pgTabContent:not(:eq('+tabIndex+'))';
		$(this).blur();
		$('#tabNav a.current').removeClass('current');
		$(this).addClass('current');
		$(contentNotIndex).hide();
		$(contentIndex).show();
	});
	
	//Governing Boards
	$('#govBoards li:first').addClass('currentMenu');
	$('#govBoardsWrap dl:first').show();
	$('#govBoards li a').hover(function(){
		$(this).parent('li').addClass('currentHover');																	
	},function(){
		$(this).parent('li').removeClass('currentHover');
	});
	$('#govBoards li a').click(function(){
		var boardID = $(this).attr('href');
		$('#govBoards li.currentMenu').removeClass('currentMenu');
		$(this).parent('li').addClass('currentMenu');
		$('#govBoardsWrap dl').hide();
		$('#'+boardID).show();
		$(this).blur();
		return false;																		
	});
	
	// Charity Boards
	$('#charityBoards li:first').addClass('currentMenu');
	$('#charityBoardsWrap dl:first').show();
	$('#charityBoards li a').hover(function(){
		$(this).parent('li').addClass('currentHover');																	
	},function(){
		$(this).parent('li').removeClass('currentHover');
	});
	$('#charityBoards li a').click(function(){
		var boardID = $(this).attr('href');
		$('#charityBoards li.currentMenu').removeClass('currentMenu');
		$(this).parent('li').addClass('currentMenu');
		$('#charityBoardsWrap dl').hide();
		$('#'+boardID).show();
		$(this).blur();
		return false;																		
	});
	
	//video player open and close
	//open player
	$('.healerVignette a').click(function(){
		var targetID = $(this).attr('href');
		$(targetID).fadeIn(250);
		return false;
	});
	//close player
	$('.vidClose').click(function(){
		$('#vignetteVid').fadeOut(250);
		return false;
		//Turn off player
	});	
	
	//Email
	$('#emailThis').click(function(){
		//mail_str = "mailto:?subject=Please read: " + document.title;
		//mail_str += "&body=I thought you might be interested in the " + document.title;
		//mail_str += ". You can view it at, " + location.href; 
		//Report Version 1
		mail_str = "mailto:?subject=Please read - Intermountain Healthcare's Annual Report to the Community for 2008";
		mail_str += "&body=I thought you might be interested in Intermountain Healthcare's Annual Report to the Community for 2008.  You can view it at http://intermountainhealthcare.org/annualreport/";
		location.href = mail_str;
		return false;		
	});
});