$(function() {
	var hasRotate = false;
	var rotateComplete = false;
	var splash_autostop = 1;
	var splash_autostopCount = 4;
	var rotateCount = 0;
	
	if (splash_rotateonce == 1)
	{
		hasRotate = true;
		
		var rotateStatus = jQuery.cookie("splash_rotate");
		rotateComplete = rotateStatus == 1;
		
		if (!rotateComplete)
		{
			splash_autostop = 1;
			splash_autostopCount = $('div.splash > div').size() + 1;
			jQuery.cookie("splash_rotate", 1);
		}
	}
	
	var startAt = jQuery.cookie("splash_slide");
	if (startAt == "" || startAt == null)
	{
		startAt = 0;
	}
	
	var startTab = jQuery.cookie("home_tab");
	if (startTab == "" || startTab == null)
	{
		startTab = 0; // this sets the default tab, 3 = news
	}
	
	$('.splash').cycle({
		fx:			'fade',
		speed: 		splash_transition_speed,
		timeout:	(hasRotate && !rotateComplete) || !hasRotate ? splash_timeout : 0,
		cleartype:  0,
		continuos:	0,
		random: splash_random,
		pager:  '#splash-nav',
		startingSlide: startAt,
		pause: 1,
		pauseOnPagerHover: 1,
		autostop: splash_autostop,
		autostopCount: splash_autostopCount,
		pagerAnchorBuilder: function(idx, slide) { 
				// return selector string for existing anchor 
				return '#splash-nav li:eq(' + idx + ') a'; 
			},
		after: function(currSlideElement, nextSlideElement, options, forwardFlag) {
				jQuery.cookie("splash_slide", $('div.splash > div').index(nextSlideElement));
			},
		pagerClick: function(zeroBasedSlideIndex, slideElement) {
				if (splash_timeout != 0) {	
					splash_timeout = 0;
					$('.splash').cycle({timeout:0});
				}
			}
	});

	$("#tabs").tabs({ 
		selected: startTab,
		select: function (event, ui) {
				jQuery.cookie("home_tab", ui.index);
			}
	});
	
	$('.rcs').cycle({
		fx:			'fade',
		speed: 		rcs_transition_speed,
		timeout:	rcs_timeout,
		cleartype:  0,
		random: rcs_random,
		pause: 1
	});
	
	$('.loading').removeClass('loading');
});
