// Problem with this is you can only have one slider per page
var currentSlide = 0;
$(document).ready(function() {
  theSlider();
  outboundLinks();
  smoothScroll();
});

function theSlider () {
  $("ul.controls li a").click(function(){
    var widthToMove = 465; var changeLeft = "+=0"; var action = ($(this).attr('class')); 
    var numSlides = $("ul.slides").children().size(); var currentLeft = 0 - (currentSlide * widthToMove);
    var totalWidth = 0 - (numSlides * widthToMove);
    if ('previous' == action && 0 >= (currentLeft + widthToMove)) { 
      changeLeft = currentLeft + widthToMove; currentSlide --;
    } else if ('previous' == action && 0 < (currentLeft + widthToMove)) { 
      changeLeft = totalWidth + widthToMove; currentSlide = numSlides;
    } else if ('next' == action && totalWidth < (currentLeft - widthToMove)) {
      changeLeft = currentLeft - widthToMove; currentSlide ++;
    } else if ('next' == action && totalWidth >= (currentLeft - widthToMove)) {
      changeLeft = "0"; currentSlide = 0;
    }
    $("ul.slides").animate( {left:changeLeft}, { queue: false,duration:1000,easing:'easeOutQuint' } );
    return false;
  });  
}

function outboundLinks () {
  $('a').each(function() {
    var $a = $(this);
    var href = $a.attr('href');
     // see if the link is external
    if ( (href.match(/^http/)) && (! href.match(document.domain)) ) {
      // if so, add the GA tracking code
      $(this).addClass("external-link");
      $a.click(function() {
        pageTracker._trackPageview('/outgoing/' + href);
      });
    }
  });
}

function smoothScroll() {
  $('a[href*=#]').click(function() {
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
	&& location.hostname == this.hostname) {
	  var $target = $(this.hash);
	  $target = $target.length && $target
	  || $('[name=' + this.hash.slice(1) +']');
	  if ($target.length) {
		var targetOffset = $target.offset().top;
		$('html,body')
		.animate({scrollTop: targetOffset},  1000);
	   return false;
	  }
	}
  });
}