/*
jQUERY
--------------------------------------------------*/
$(document).ready(function() {
	
	$('a[href=#]').click(function() {
		alert('Whoa there!\nThat link hasn\'t been implemented.');
		
		return false;
	});
		
	// SET BASIC VARIABLES
	var $nextPos = 0, $pos = 0, $transition = 500, $pause = 5000;
	
	$('ul#slideshow').after('<div id="slideshow-caption">');
	
	$('ul#slideshow li').css('display','none');
	$('ul#slideshow li:eq(' + $pos + ')').fadeIn($transition,function() {
		
		$('div#site-navigation ul li:eq(' + $pos + ')').addClass('selected');
		
		$('ul#slideshow li:eq(' + $pos + ')').css('z-index',200);
		$('ul#slideshow li:eq(' + ($pos+1) + ')').show().css('z-index',100);
	});
	
	// ROTATE FUNCTIONS
	function rotate() {
		
		$('div#slideshow-caption').slideUp();
		$('ul#slideshow li:eq(' + $pos + ')').fadeOut($transition,function() {
			
			$('div#site-navigation ul li').removeClass('selected');
			
			$pos++;
			if ($pos >= 3) {
				$pos = 0;
			}
			
			if (($pos + 1) >= 3) {
				$nextPos = 0;
			} else {
				$nextPos = ($pos + 1);
			}
			
			$('div#site-navigation ul li:eq(' + $pos + ')').addClass('selected');
			$('ul#slideshow li:eq(' + $pos + ')').css('z-index',200);
			$('ul#slideshow li:eq(' + $nextPos + ')').show().css('z-index',100);

		});
	}
	
	// PAUSE/START TIMER ON HOVER
	$('ul#slideshow').hover(
		function() {
			clearInterval(rotatePromos);
		},
		function() {
			rotatePromos = setInterval(rotate,$pause);
		}
	);
	$('div#site-navigation ul li').hover(
		function() {
			clearInterval(rotatePromos);
			
			$('div#slideshow-caption').html( $('ul#slideshow li#' + $('a', this).attr('rel') + ' img').attr('alt') ).slideDown('fast');
			
			$('div#site-navigation ul li').removeClass('selected');
			$(this).addClass('selected');
			
			$('ul#slideshow li#' + $('a', this).attr('rel')).css('z-index',200).show();
			$('ul#slideshow li').not('ul#slideshow li#' + $('a', this).attr('rel')).css('z-index',100).hide();
			
			$pos = $('li').index(this) - 13;
		},
		function() {
			$('div#slideshow-caption').hide();
			
			if (($pos + 1) >= 3) {
				$nextPos = 0;
			} else {
				$nextPos = ($pos + 1);
			}
			$('ul#slideshow li:eq(' + $nextPos + ')').show().css('z-index',100);
			
			rotatePromos = setInterval(rotate,$pause);
		}
	);
	
	rotatePromos = setInterval(rotate,$pause);
		
});