
// initial values - don't change:
$j = jQuery.noConflict();
var $homepageRotatingTimer = 0;
var $homepageFeatureImageOnTop = 1;


// functionality which creates an animation effect on the homepage rotating images area
$j(function() {
	// this is the page onload() function.... do initialisation routines, then start the timer
	$j('#banner .ms-WPBody .box').each(function(index) {
		$j(this).addClass('box-'+(index+1));
		$linkUrl = $j(this).children('.link-item').children('.linkurl').text();
		if ($linkUrl.indexOf('/') >= 0) {
			$j(this).children('.link-item').children('img').wrap('<a href="'+$linkUrl+'"></a>');
		}
	});
	$j('#banner .ms-WPBody').prepend('<div class="homepage-image-feature-bg homepage-image-feature-bg-left">&nbsp;</div>');
	$j('#banner .ms-WPBody').prepend('<div class="homepage-image-feature-bg homepage-image-feature-bg-right">&nbsp;</div>');
	$j('#banner .ms-WPBody').prepend('<div class="homepage-image-feature-buttons"></div>');
	
	if ($j('#banner .ms-WPBody .box').length > 1) {
		for ($i=1; $i<=$j('#banner .ms-WPBody .box').length; $i++) {
			$j('.homepage-image-feature-buttons').append('<a href="#" onclick="animateHomepageFeatureImage('+$i+'); return false">&nbsp;</a>');
		};
		$j('.homepage-image-feature-buttons a:first-child').addClass('selected');
		$homepageRotatingTimer = setTimeout('animateHomepageFeatureImage(2)', $initialAnimationDelay);
	}
});

// animation function - switch z-indexes around, animate the margin-left value, and restart the timer for the next iteration
function animateHomepageFeatureImage($boxNumber) {
	if ($boxNumber != $homepageFeatureImageOnTop) {
		clearTimeout($homepageRotatingTimer);
		$j('.homepage-image-feature-buttons a').removeClass('selected');
		$j('#banner .ms-WPBody .box-'+$homepageFeatureImageOnTop).css('z-index', 500);
		$j('#banner .ms-WPBody .box-'+$boxNumber).css('z-index', 510);
		$j('#banner .ms-WPBody .box-'+$boxNumber).css('marginLeft', '0px');
		$j('#banner .ms-WPBody .box-'+$boxNumber).css('opacity', 0);
		$j('#banner .ms-WPBody .box-'+$boxNumber).animate({'opacity': 1}, $animationSpeed, 'linear', function () {
			$j('#banner .ms-WPBody .box-'+$homepageFeatureImageOnTop).css('margin-left', '-930px');
			$j('.homepage-image-feature-buttons a:eq('+($boxNumber-1)+')').addClass('selected');
			$homepageFeatureImageOnTop = $boxNumber;
			$nextBoxNumber = $boxNumber + 1;
			if ($nextBoxNumber > $j('#banner .ms-WPBody .box').size()) {
				$nextBoxNumber = 1;
			}
			$homepageRotatingTimer = setTimeout('animateHomepageFeatureImage('+$nextBoxNumber+')', $followingAnimationDelay);
		});
	}
}

