
/* Functions to fix IE8 rendering bug
 * http://stackoverflow.com/questions/1865806/jquery-fadeto-causing-pixelated-text-in-ie8-when-font-weight-bold
 * http://www.kevinleary.net/jquery-fadein-fadeout-problems-in-internet-explorer/
 * ^ Solutions 2 & 3 do not seem to work so we must change the bg colors
 */


function FadeOutIn (outElt, outSpeed, inElt, inSpeed, bgColor)
{
	if(jQuery.browser.msie) {
		var outBG = outElt.css("background-color");
		var inBG = inElt.css("background-color");
		outElt.css("background-color", bgColor);
		inElt.css("background-color", bgColor);
		outElt.fadeOut(outSpeed, function(){
				outElt.css("background-color", outBG);
				inElt.fadeIn(inSpeed, function (){
					inElt.css("background-color",inBG);
				});		
		});
	} else {
		outElt.fadeOut(outSpeed, function(){
			inElt.fadeIn(inSpeed, function (){
			});		
	});		
	}
	
}






/* Only show one group of news summaries at a time
 * cycle/fade between groups
 * Each group contains a max number of entries as defined below
 * LGN, 3/29/11
 */

var gNewsCycleOn = false;
var gNewsSummariesPerGroup = 3;	// <--- update as desired
var gCurrentNewsGroupShown = 1;
var gNumOfNewsGroups = 0;
var gNewsCyclingTimerId;
var gNewsTabContentId = "news_tab_content";
var gNewsGroupPrefixId = "news_tab_content_group";

function Get_News_Group (groupNum)
{
	return $("#"+gNewsTabContentId).find("."+gNewsGroupPrefixId+"_"+groupNum);
}

function Start_Cycling_News () {
	if (gNumOfNewsGroups > 1) gNewsCyclingTimerId = setInterval("Cycle_News()" , 7000);
}

function Cycle_News () {
	//alert("do scroll for group...\nOld: ."+gNewsTabContentId+"_"+gCurrentNewsGroupShown);
	var oldGroup = Get_News_Group(gCurrentNewsGroupShown);
	// incremenet to next group
	if (gCurrentNewsGroupShown >= gNumOfNewsGroups) gCurrentNewsGroupShown = 1;
	else gCurrentNewsGroupShown++;
	var newGroup = Get_News_Group(gCurrentNewsGroupShown);
	
	// Hide old news group, show new group
	FadeOutIn(oldGroup, 800, newGroup, 1000, "#D2B27A");
	
	/*oldGroup.fadeOut(800, function(){
			newGroup.fadeIn(1000);		
	});*/
				
}

function Stop_Cycling_News () {
	clearInterval(gNewsCyclingTimerId);
}


$(document).ready(function(){
	
	if (gNewsCycleOn)
	{
		var numOfNewsSummaries = 0;
		var newsElts = $("#"+gNewsTabContentId).find("li");
		
		// Loop through news summaries -- get counts and set a class for each group
		newsElts.each(function(event){
			numOfNewsSummaries++;
			var m = (numOfNewsSummaries-1) % gNewsSummariesPerGroup;
			if (m == 0) gNumOfNewsGroups++;
			$(this).addClass(gNewsGroupPrefixId + "_" + gNumOfNewsGroups);
			//alert("Summary "+numOfNewsSummaries+"\nGroup: "+gNumOfNewsGroups+"\n"+$(this).html());
			if (gNumOfNewsGroups > 1) $(this).fadeOut(10);
		});
		
		// Loop through links in tab area to find tab link to news
		$(".tabs-area").find("a").each(function(){
			if ($(this).attr("href") == "#news_tab_content") {
				
				// When news tab is clicked, we want to make sure that only the current news group is shown; hide all others
				$(this).click(function() {
					for (i = 1; i <= gNumOfNewsGroups; i++) {
						if (i != gCurrentNewsGroupShown) Get_News_Group(i).fadeOut(0);
					}			
				});
			}
		});
	
		
		//alert("# of News Summaries = " + numOfNewsSummaries + "\nNews Summaries per news group = "+gNewsSummariesPerGroup+"\n # of news groups = "+gNumOfNewsGroups);
		
		Start_Cycling_News();
	}
	
});


