var fcount = 1;  
var timeout;
var delay = 6000;

function selectFeature(index) {
	
	if(typeof console == 'object') {console.log('Selecting Feature '+index);}
	
	clearTimeout(timeout);
	
	$(".featureTv").not(':eq('+(index-1)+')').fadeOut(400);
	$(".featureTv:eq("+(index-1)+")").fadeIn(400);
		
	$(".featureTitle").hide();
	$("#bubbleText").empty();
	$("#clickLoc").empty();
	for (var x=1; x<=8; x++) {$("#featureNav-"+x).css("background-position","-"+x+"0px top");}
	
	$("#title-"+index).show();
	
	$("#featureNav-"+index).css("background-position","-"+index+"0px bottom");
	$("#bubbleText").html($("#bubble-"+index).html());
	$("#clickLoc").html($("#clickLoc-"+index).html());
	 
	timeout = setTimeout(changeFeatured, delay);
}
						
function changeFeatured(){
	fcount++;
	if(fcount > ftotal){
		fcount = 1;
	}
	selectFeature(fcount);
}

$(document).ready(function(){
	setTimeout(changeFeatured, delay);		
	selectFeature(1);

			$(".videoFeatureInner .tv, .featureTitle").hover(function(e) {

				$(".featureTitle").css("color","#00adef");

				$(".featureTitle div").css("background-position","left top");

				var tip = $("#bubbleText").html();

				$("body").append("<div id='jqTip3' style='display: none; position: absolute;'><span>"+tip+"<span class='white'></span></span></div>");

				$("#jqTip3").css('display','block');

				$(this).mousemove(function(e) {

				  //var left = ((e.pageX-$("#jqTip3").width())+274); var top = (e.pageY-120);

					 var left = (e.pageX-15); var top = (e.pageY-($("#jqTip3").height()+20));

				  if (left < 0) {left = 0;} if (top < 0) {top = 0;}

					$("#jqTip3").css('top',top); $("#jqTip3").css('left',left);
					
					clearTimeout(timeout);
				});

			}, function() {

				$("#jqTip3").remove();

				$(".featureTitle").css("color","#666666");

				$(".featureTitle div").css("background-position","left bottom");
				
				timeout = setTimeout(changeFeatured, delay);

			});

			

			$("#featureHit .tv, #featureHit, .featureTitle").click(function(){top.location="/news-events.php?a="+$("#clickLoc").html();});



});