//------------------------------------
//	ENGAGE.JS
//	Author: 	Engage Interactive
//	Requires:	jquery 1.3.2
//				
//				
//------------------------------------

Cufon.replace('h2', {
	textShadow: '#fff 1px 1px'
});
Cufon.replace('nav li a', {
	textShadow: '#320708 2px 2px'
});

$(function(){
//BEGIN jQuery

	var mooseBan = false;

	var $s = $('#slider');
	var total = $s.find('img').length;
	var width = $('#slider_window').width();
	var c = 1;
	var s = 1000;
	var e = 'easeInOutExpo';
	var timer = 3500;
	var hover = false;
	
	$s.find('img:last').clone().prependTo($s).addClass('first');
	$s.find('img:eq(1)').clone().appendTo($s).addClass('last');
	
	$('#promo_nav a').click(function(e){
	
		if( mooseBan == false ) {
		
			mooseBan = true;
			
			var infinite = false;
		
			var dir = $(this).parent('li').attr('class');
			
			dir == 'next' ? c++ : c--;
			
			if( c > total || c <= 0 ) var infinite = true;
			
			goTo(c,infinite);
		
		}
		
		e.preventDefault();
		
	});
	
	function goTo(num,infinite) {
	
		$s.stop([]).animate({left: 0 - ( width * ( num - 1 ) )},s,e,function() {
		
			if( infinite && c > total ) {
				$s.css({left: 0});
				c = 1;
			}else if( infinite && c <= 0 ){
				$s.css({left: 0 - ( width * ( total - 1 ) )});
				c = total;
			}
		
			mooseBan = false;
		});
		
	}
	
	$('#slider_window,#promo_nav').hover(function() {
		hover = true;
	},function() {
		hover = false;
	});
	
	function slideshow() {
		setTimeout(nextSlide,timer);
		
		function nextSlide(){
			if( !hover ) {
				$('#promo_nav li.next a').click();
			}
			slideshow();
		}
		
	}
	
	slideshow();
	
//END jQuery
});


// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	}
});
