/*
	Share Our Strength scripts (utilizing jQuery 1.2.6)
	Spring 2009 homepage
	Developed by Saforian
*/


// Other global variables
var news_timer = null;				// Rotation timer ID
var news_animating = false;			// Flag if rotating (to avoid overlapping)
var swapTextBoxes = [];					// Store original values for cleared text fields

var $j = jQuery.noConflict();

/* --- Initialize page --- */
$j(document).ready(function(){

	// Homepage: Top news switching
	initLatestNews();
});
// Homepage: Top news switching
function initLatestNews(){

	if (!document.getElementById("latest-news")) { return; }
	// Inject 1-2-3 cycle controls list
	var newcyclecode = '';
	$j("#latest-news > .newsdiv").each(function(i){
		$j(this).attr("id", "news" + (i+1));
		newcyclecode += '<a href="#' + $j(this).attr("id") + '">' + (i+1) + '</a>';
	});
	
	$j('.newsdiv > div:first-child').addClass('first-news');

	$j("#news-controls").append(newcyclecode);

	$j("#news-controls a:first").addClass("active");
	$j("#news-controls a:last").addClass("last");

	// Click event
	$j("#news-controls a").click(function(){

		// Skip if number already showing
		if ($j(this).hasClass("active")) { return false; }

		// Hide visible news
		$j(".newsdiv:visible").hide();
		$j("#news-controls a.active").removeClass("active");

		// Show new news
		$j(this.hash).fadeIn("slow");
		$j(this).addClass("active");

		return false;
	});

}


// Rotation function
function newsRotate() {

	// Find next news
	var $jnext = $j("#news-controls a.active").parent("li").next().children("a");

	// Or loop to #1 if at end
	if ($jnext.size() == 0) {
		$jnext = $j("#news-controls > li:first > a");
	}

	// Click the number link
	$jnext.click();
}
