﻿$(document).ready(function() {
	$('div.homeSpotlight.hidden').fadeTo(0, 0);

	RedRockTS.CreateHomepageRotatorTimer();

	$('a.rotatorNavItem').hover(function() {
		RedRockTS.HomePageRotatorNavChange(this);
		$(document).stopTime("homepageRotator");
	}, function() {
		RedRockTS.CreateHomepageRotatorTimer();
	});

	$('a.rotatorNavItem').blur(function() {
		RedRockTS.CreateHomepageRotatorTimer();
	});

	$('a.rotatorNavItem').focus(function() {
		RedRockTS.HomePageRotatorNavChange(this);
		$(document).stopTime("homepageRotator");
	});
});

var RedRockTS = new function() {
	this.HomePageRotatorDelay = 10;
	this.HomepageRotatorAnimInProgress = false;
	this.RightBarPanelAnimationInProgress = false;

	this.CreateHomepageRotatorTimer = function() {
		$(document).everyTime(RedRockTS.HomePageRotatorDelay * 1000, "homepageRotator", RedRockTS.HomepageRotatorRotate);
	}

	this.HomePageRotatorNavChange = function(obj) {
		if (!$(obj).hasClass('active')) {
			$('a.rotatorNavItem.active').removeClass('active');
			$(obj).addClass('active');
			var content = $(obj).attr('rel');
			$('div.homeSpotlight').stop(true, false);
			$('div.homeSpotlight').fadeTo("def", 0, function() { $(this).hide(); });
			$('div.homeSpotlight.' + content).stop(true, false);
			$('div.homeSpotlight.' + content).show();
			$('div.homeSpotlight.' + content).fadeTo('def', 1);
		}
	}

	this.HomepageRotatorRotate = function() {
		if ($('a.rotatorNavItem.active').next('a').length > 0) {
			RedRockTS.HomePageRotatorNavChange($('a.rotatorNavItem.active').next('a').get());
		} else {
			RedRockTS.HomePageRotatorNavChange($('a.rotatorNavItem:first-child').get());
		}
	}
}
