//if you want to use jquery
$(document).ready( function () {	
	imageCarousel();
	
	checkCookie();
	
	$('#TB_window').delegate('.siteButton', 'click', function(event) {
		showSplashCheck();
		tb_remove();
		event.preventDefault();
	});
	
	function imageCarousel() {
		var currentAd = 0;
		
		function fadeBanner() {
			if (currentAd < $('#bannerNav a').length - 1) {
				currentAd++;
			} else {
				currentAd = 0;
			}
			goToBanner(currentAd);
		}
		
		function goToBanner(bannerNum) {
			$currentBanner = $('#homeBanner .bannerSlide:visible');
			$currentBanner.css('z-index', '1');
			
			$('#homeBanner .bannerSlide').eq(bannerNum).css('z-index', '2').fadeIn('slow', function () {
				$currentBanner.fadeOut('fast');
			});
			$('#bannerNav li').removeClass('active').animate({'top':'301px'}).eq(bannerNum).addClass('active').animate({'top':'293px'});
		}
		function animating(element) {
			if ( element.parent('li').hasClass('active') || $('#homeBanner .bannerSlide:animated').length > 0 )
				return true;
			else
				return false
		}
		
		$('.bannerSlide').not(':eq(0)').hide();
		$('#bannerNav li').eq('0').addClass('active').css('top', '293px');
		timeOut = setInterval(fadeBanner, 5000);
		
		$('#bannerNav a').click(function(event) {
			if ( !animating( $(this) ) ) {	
				clearTimeout(timeOut);
				currentAd = $('#bannerNav a').index($(this));
				goToBanner(currentAd);
				timeOut = setInterval(fadeBanner, 5000);
			}
			event.preventDefault();
		});
	}
	
	function checkCookie() {
		showSplash=getCookie('RSPCAPASplash');
		if (showSplash==""||showSplash==null) {
			setCookie('RSPCAPASplash','true',365);
			tb_show(null, '#TB_inline?height=480&width=800&inlineId=splashContent&modal=true', false);
		}
	
		if (showSplash=="true") {
			tb_show(null, '#TB_inline?height=480&width=800&inlineId=splashContent&modal=true', false);
		}
	}
	
	function getCookie(c_name) {
		if (document.cookie.length>0)
		{
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1)
			{
				c_start=c_start + c_name.length+1;
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
			}
		}
		return "";
	}
	function setCookie(c_name, value,expiredays) {
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}
	
	function showSplashCheck() {
		if (document.getElementById('splashCheck').checked) {
			setCookie('RSPCAPASplash','false',365);
		}
	}
});
