/* Health Advisor */
var rotation = null;
jQuery(document).ready(function(){
	preload('cta_healthadvisor_home_communities_women.jpg');
	preload('cta_healthadvisor_home_communities_asthma.jpg');
	preload('cta_healthadvisor_home_communities_hearthealth.jpg');
	preload('cta_healthadvisor_home_communities_diabetes.jpg');
	jQuery("#communities .tab").click(function(){
		element = jQuery(this);
		
		jQuery(this).siblings('.tab').removeClass('selected').css('background', "url('" + images + "backgroundTabsOff.png') no-repeat").ifixpng();
		jQuery(this).addClass('selected').css('background', "url('" + images + "backgroundTabsOn.png') no-repeat").ifixpng();
		
		// Initialize Links
//		jQuery("#links div:first-child a").attr('href', healthadvisor + jQuery(this).attr('title'));
//		jQuery("#links div:last-child a").attr('href', healthadvisor + jQuery(this).attr('title') + '/discussions').trigger('click');
		jQuery("#links div a").attr('href', healthadvisor + jQuery(this).attr('title'));
		
		// Initialize Image
		jQuery("#community img").fadeOut(0, function(){
			jQuery("#community img").attr('src', images + 'cta_healthadvisor_home_communities_' + jQuery(element).attr('title') + '.jpg').fadeIn("slow", function(){
				jQuery("#community").css('background', "url('" + images + "cta_healthadvisor_home_communities_" + jQuery(element).attr('title') + ".jpg') no-repeat");
			});
		});
		
		// Initialize Text
		jQuery("#community #title").text(jQuery(this).text());
		jQuery("#community #tagline").text(jQuery(this).attr('alt'));
		clearTimeout(rotation);
	});
	
	jQuery("#communities .tab:first").trigger('click');
	rotation = setTimeout(function(){ rotateBanner(); }, 5000);
});

jQuery(function(){
	jQuery("#communities li").hover(function(){
		if(!(jQuery(this).hasClass('selected')))
			jQuery(this).css('background', "url('" + images + "backgroundTabsOn.png') no-repeat").ifixpng();
	},
	function(){
		if(!(jQuery(this).hasClass('selected')))
			jQuery(this).css('background', "url('" + images + "backgroundTabsOff.png') no-repeat").ifixpng();
	});

});

function rotateBanner()
{
	if (jQuery("#communities li.selected").text() == jQuery("#communities .tab:last").text())
		jQuery("#communities .tab:first").trigger('click');
	else
		jQuery("#communities li.selected").next().trigger('click');
		
	rotation = setTimeout(function(){ rotateBanner(); }, 3000);
}