function navigation()
{
	$('#nav-main li a').mouseover( function(){
		$(this).addClass('selected');
		$(this).siblings('ul').css('display','block');
	});
	$('#nav-main ul').mouseover( function(){
		$(this).siblings('a').addClass('selected');
		$(this).css('display','block');
	});
	$('#nav-main li a').mouseout( function(){
		$(this).siblings('ul').css('display','none');
		$(this).removeClass('selected');
	});
	$('#nav-main ul').mouseout( function(){
		$(this).css('display','none');
		$(this).siblings('a').removeClass('selected');
	});
}

function ro()
{
	$('.ro').mouseover( function()
	{
		rep = ".";
		ext = $(this).attr('src').substr(-4, 4);
		src = $(this).attr('src').replace(rep, "-on.");
		$(this).attr('src', src);
		
	});
	$('.ro').mouseout( function()
	{
		rep = "-on.";
		ext = $(this).attr('src').substr(-4, 4);
		src = $(this).attr('src').replace(rep, ".");
		$(this).attr('src', src);
		
	});
}
function toggleLogin()
{
	$('#nav-aux .account a.loggedOut').click(
		function(){
			$('#flyoutLogin').toggle();
			return false;
		}
	);
}

function cognitiveTooltips()
{
	$('.cognitiveResults li').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		top: -170,
		left: -68
	});
}

function slideshow()
{
	$("#slide-show").cycle({
		easing: 'easeOutExpo',
		timeout: 6000,
		speed: 3000,
		pause: 1,
		autostop: 1,
		prev: "#callToAction .controls a.prev",
		next: "#callToAction .controls a.next",
		nowrap: 1
	});
}

function randomPolaroid()
{
	i = Math.ceil(Math.random()*4);
	src = "/images/main/pol-"+i+".jpg";
	$('img#who-polaroids').attr('src',src);
}

function toggleReturningVisitors(){
	if( $('#returningUsers').length > 0 ){
		$('.h-returningUsers a').click( function(){
			$('#returningUsers').slideToggle();
			return false;
		});
	}
}

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

$(document).ready(function(){
	navigation();
	toggleLogin();
	ro();
	toggleReturningVisitors();
	
	
//	$.preloadImages("/images/slide-show/dot1.png", "/images/slide-show/dot2.png", "/images/slide-show/dot3.png", "/images/slide-show/dot4.png", "/images/slide-show/dot5.png");
});