(function($) {
$.fn.featSlider = function() {
	if ($(this).find('.health_feat_item').length > 6) {
		panels = $(this).find('.health_panel').length;
		$(this).find('#health_feat_area').wrapInner('<div id="health_container" style="width:'+(panels*600)+'px;height:370px;position:absolute;top:0;left:0;"></div>');
		$(this).find('.health_panel').each(function(){$(this).attr('id','health_panel_'+($('.health_panel').index(this)+1));});
		newControls = '<div id="health_feat_controls"><span class="rt_arrow"><!-- --></span><span class="lt_arrow"><!-- --></span>';
		for(i=panels;i>0;i--) newControls+='<span class="ctrl_dot" id="ctrl_dot_'+i+'"><!-- --></span>';
		newControls+='</div>';
		$(this).find('#health_feat_top').append(newControls);
		$('.ctrl_dot').hover(function(){$(this).addClass('ctrl_dot_hover');},function(){$(this).removeClass('ctrl_dot_hover');}).click(function(){swingPanel($(this).attr('id').replace('ctrl_dot_',''));});
		buildControls(1,panels);
	}
};

$.fn.getTip = function() {
	tipElement = this;
	$.get('http://www.wnct.com/nct/health_connections/tip-of-day?url=http://www.livestrong.com/api/tips/fitness/1/', function(d) {
		$(d).find('tip').each(function() {$(tipElement).text($(this).find('description').text());});
	});
};

})(jQuery);

function buildControls(c,t) {
	$('.ctrl_dot_on').removeClass('ctrl_dot_on');
	$('.rt_arrow_on').removeClass('rt_arrow_on').unbind('click').unbind('mouseover').unbind('mouseout').removeClass('rt_arrow_hover');
	$('.lt_arrow_on').removeClass('lt_arrow_on').unbind('click').unbind('mouseover').unbind('mouseout').removeClass('lt_arrow_hover');
	$('#ctrl_dot_'+c).addClass('ctrl_dot_on');
	if (t>c) $('.rt_arrow').addClass('rt_arrow_on').mouseover(function(){$(this).addClass('rt_arrow_hover');}).mouseout(function(){$(this).removeClass('rt_arrow_hover');}).click(function(){swingPanel(c+1);});
	if (c>1) $('.lt_arrow').addClass('lt_arrow_on').mouseover(function(){$(this).addClass('lt_arrow_hover');}).mouseout(function(){$(this).removeClass('lt_arrow_hover');}).click(function(){swingPanel(c-1);});
}
function swingPanel(np) {
	buildControls(np,$('.ctrl_dot').attr('id').replace('ctrl_dot_',''));
	$('#health_container').animate({left: '-' + ((np-1)*600) + 'px'},400,"linear");
}



