/*  
*	REQUIRES: /min/g=phoenix.js.utilities
*
*	LAST MODIFIED: 2009-07-20
*/

$(document).ready(function(){

/*
*	Cycle Campus News
*
* 	DESCRIPTION: Steps through the available news items top to bottom returning to the top
*/

// At the given time interval advance the campus news features

function cycleCampusNews () {

	// Set indices

		var $currentImage = $(".widget-alumni-news .image-tnails ul li.active a img").attr("alt").substr(5);
		var $nextImage = 0;
		
		switch($currentImage){
		
			case '1':
				$nextImage = 2;
				break;
			case '2':
				$nextImage = 3;
				break;
			case '3':
				$nextImage = 1;
				break;
	
		}
	
	// Swap class names, and perform transitions
	
		// Tnail
		
			// Deselect Current Image
			//$(".widget-alumni-news .image-tnails ul li a img").attr("alt", "item-"+$currentImage).removeClass("active").fadeTo(300, 0.65);
			$(".widget-alumni-news .image-tnails ul li a img[alt='item-"+$currentImage+"']").parent().parent().removeClass("active").fadeTo(300, 0.65);
		
			// Select Next Image
			//$(".widget-alumni-news .image-tnails ul li a img").attr("alt", "item-"+$nextImage).addClass("active").fadeTo(300, 1.00);
			$(".widget-alumni-news .image-tnails ul li a img[alt='item-"+$nextImage+"']").parent().parent().addClass("active").fadeTo(300, 1.00);
		
		// Image Main
		
			// Hide the current image-main
			$(".widget-alumni-news .image-main .active").slideUp(1000);
			$(".widget-alumni-news .image-main .active").addClass("ui-helper-hidden-accessible");
			$(".widget-alumni-news .image-main .active").removeClass("active");
			
			// Create selector string
			var $selectorString = ".widget-alumni-news .image-main .item-" + $nextImage;
			
			// Show next image
			$($selectorString).slideDown(300, function(){$($selectorString).children(".image-main-copy").fadeIn(300);}).children(".image-main-copy").hide();
			$($selectorString).addClass("active");
			$($selectorString).removeClass("ui-helper-hidden-accessible");


}

/*
*	Mouse Over Tnails
*
* 	DESCRIPTION: When a user hovers over a thumbnail swap the main image by editing the classnames
*/

$(".widget-alumni-news .image-tnails ul li").mouseover(function(){

	// Adjust image-tnail classnames
	
		var $curTnail = $(this).hasClass("active");
	
		// Avoid transition to the current tnail
		if(!$curTnail){
		
			// Remove all active classnames
			$(".widget-alumni-news .image-tnails ul li").each(function(i){
				
				$(this).removeClass("active");
				$(this).fadeTo(300, 0.65);
				
			});
			
			// Add active class name to the hovered item
			$(this).addClass("active");
			$(this).fadeTo(300, 1.00);
		
		}
	
	// Adjust image-main classnames
	
		// Determine alt information of tnail image
		var $altIndex = $("img", this).attr("alt");
		
		var $curImage = $(".widget-alumni-news .image-main .active").hasClass($altIndex);
		
		// Avoid transition to the current image
		if(!$curImage){
		
			// Hide the current image-main
			$(".widget-alumni-news .image-main .active").fadeOut(200);
			$(".widget-alumni-news .image-main .active").addClass("ui-helper-hidden-accessible");
			$(".widget-alumni-news .image-main .active").removeClass("active");
			
			// Create selector string
			var $selectorString = ".widget-alumni-news .image-main ." + $altIndex;
			
			// Show image-main that matches tnail
			$($selectorString).fadeIn(800, function(){$($selectorString).children(".image-main-copy").fadeIn(300);}).children(".image-main-copy").hide();
			$($selectorString).addClass("active");
			$($selectorString).removeClass("ui-helper-hidden-accessible");
		
		}
		
});


/*
*	Mouse Over Widget
*
* 	DESCRIPTION: When a user hovers over the body of the widget pause the image sequence
*/

$(".widget-alumni-news .ui-widget-content").hover(

	function(){
		
		// Stop the image sequence
		$(".widget-alumni-news .ui-widget-content").stopTime('cycleNews');
	
	}
	,function(){
		
		// Restart sequence
		$(".widget-alumni-news .ui-widget-content").everyTime('6s', 'cycleNews', cycleCampusNews);
	}

);


// Set a time interval for cycling through the widget's content

$(".widget-alumni-news .ui-widget-content").everyTime('6s', 'cycleNews', cycleCampusNews);


});
