$(document).ready(function() {
	SCP.initTabs();
 	SCP.displayContent('views/scp/home');
	SCP.doBulletAnimation();
});

var SCP = {}; // namespace
SCP.animationRunning = false;
SCP.animationTimer = null;
SCP.bulletPoints = ['<p class="quote smallquote">Assessement</p>',
					'<p class="quote smallquote">Customized Care Plan and Care Coordination</p>',
					'<p class="quote smallquote">Medicaid Planning</p>',
					'<p class="quote smallquote">Finanacial Management/Bill Paying</p>',
					'<p class="quote smallquote">Wide Array of Eldercare Services</p>',
					'<p class="quote">I recommend the assessment to help clients identify immediate and long term needs. It is a valuable service for my clients.</p><p class="quote-author">-Attorney</p>'];
					
SCP.doBulletAnimation = function(){
	SCP.animationRunning = true;
	SCP.animationTimer = setInterval(doFades, 3000);
	var index = 0;
	function doFades(){
		var bullet = '<p class="quote">'+SCP.bulletPoints[index]+'</p>';
		$('#sub-header-left-block').css("display", "none");
		
		if(index === 0){
			$('#sub-header-left-block').html(bullet);
		}
		if(index > 0 && index < 5){
			$('#sub-header-left-block').append(bullet);
		}		
		
		$("#sub-header-left-block").fadeIn(800);
	
		if(index === 5){
			$('#sub-header-left-block').html(bullet);
			clearInterval(SCP.animationTimer);
		}
		index += 1;
	}
}

SCP.stopBulletAnimation = function(){
	clearInterval(SCP.animationTimer);
}

SCP.displayContent = function(content_path){
	if(SCP.animationRunning === true){
		SCP.stopBulletAnimation();
	}
	$.get(content_path+"/content.html", function(data){
		$("#content").html(data);
	});
	$.get(content_path+"/subheader.html", function(data){
		$("#sub-header").html(data);
	});
	$("#sub-header").css("display", "none");
	$("#sub-header").fadeIn(800);	
}

SCP.initTabs = function(){
	$(".tab").each(function(){
		
		$(this).click(function(){
			SCP.resetTabs();
			$(this).removeClass('scp-deselected-tab');
			$(this).removeClass('scp-hover-tab');
			$(this).addClass('scp-selected-tab');
			SCP.displayContent(this.id);
		});
		
		if ( !$(this).hasClass("scp-selected-tab") ){
			$(this).hover(
		      function () {
		        $(this).addClass('scp-hover-tab');
		      }, 
		      function () {
		        $(this).removeClass('scp-hover-tab');
		      }
		    );
		}
	    		
	});
}

SCP.resetTabs = function(){
	$(".tab").each(function(){
		$(this).removeClass('scp-selected-tab');
		$(this).addClass('scp-deselected-tab');		
	});
}


