var currentSlide = 0;
var timerBase = 6000;

$(document).ready(function() {	
	initCases();
	initSlider();
});

function initCases() {
	$('.cases .case').bind('mouseenter', function() {
		$('.overlay', this).animate({ 'bottom': '-0px' }, { 'duration': 150, 'queue': false });
	});
	$('.cases .case').bind('mouseleave', function() {
		$('.overlay', this).animate({ 'bottom' : '-180px' }, { 'duration': 150, 'queue': false });
	});
	$('.shape').bind('click', function() {
		var destination = $('.slider .container img:nth-child('+(currentSlide+1)+')').attr('role');
		if(destination) {
			location.href = destination;
		}
	});
}

function initSlider() {
	$('.slider .container').css({ 'width': (980*$('.slider .container img').length)+'px' });
	$('.header .timeline .current p').hide();
	$('.header .timeline .current p:nth-child('+(currentSlide+1)+')').show();
	$('.header .timeline .current').css({ 'width': (900/$('.slider .container img').length)+'px' });
	/*
	$('#header .slider, #header .header .shape, #header .header .payoff, #header .header .timeline').bind('mouseenter', function() {
		$('.header .timeline').animate({ 'top': '510px' }, { 'duration': 100, 'queue': false });
	});
	$('#header .slider, #header .header .shape, #header .header .payoff, #header .header .timeline').bind('mouseleave', function() {
		$('.header .timeline').animate({ 'top': '535px' }, { 'duration': 100, 'queue': false });
	});
	*/
	setTimeout('animateSlider()', timerBase);
}

function animateSlider() {
	currentSlide++;
	if(currentSlide >= $('.slider .container img').length) {
		currentSlide = 0;
	}

	$('.header .timeline .current p').hide();
	$('.header .timeline .current p:nth-child('+(currentSlide+1)+')').show();
	$('.header .timeline .current').animate({ 'left': ((900/$('.slider .container img').length)*currentSlide)+'px' }, { 'duration': 800 });
	$('.slider .container').animate({ 'left': -(currentSlide*980)+'px' }, { 'duration': 800 });
	setTimeout('animateSlider()', (timerBase+800));
}
