var timer;
var currentImage = -1;
var oldImage = -1;
var featuredImgCount = 0;
var imgInterval;

function formatText(index, panel) {
		  return index + "";
	    }

$(function(){
	if ($('.anythingSlider2').length){
		$('.anythingSlider2').anythingSlider({
					easing: "easeOutBack",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 3000,                    // How long between slide transitions in AutoPlay mode
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			animationTime: 600,             // How long the slide transition takes
			hashTags: true,                 // Should links change the hashtag in the URL?
			buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
			startText: "Go",             // Start text
			stopText: "Stop",               // Stop text
			navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
			});
	}
	
	if($('#gallery').length){
	  initImageSlider();
	  $('#gallery a').lightBox({fixedNavigation:true});
		//$('#gallery a[rel="gallery-images"]').colorbox();
	}
	
	if($('#csgallery').length){
	  $('#csgallery a').lightBox({fixedNavigation:true});
		//$('#csgallery a[rel="gallery-images"]').colorbox();
	}
	
	if($('a.anchorLink').length){
    //$("a.anchorLink").anchorAnimate();
	}
});

function initImageSlider() {
    featuredImgCount = $("#gallery li").size();
	imgInterval = setInterval(nextImage,4000);
	nextImage();

	//Pause on mouse over
	$('#gallery').hover(function() {
    clearInterval(imgInterval);
  }, function() {
    imgInterval = setInterval(nextImage,4000);
  });

}

function nextImage() {
 currentImage = (oldImage + 1) % featuredImgCount;
 $("#gallery li:eq(" + oldImage + ")").stop(true, true).fadeOut("slow");
 $("#gallery li:eq(" + currentImage + ")").stop(true, true).fadeIn("slow");

 oldImage = currentImage;
}

/*******

 *** Anchor Slider by Cedric Dugas ***
 *** Http://www.position-absolute.com ***

 Never have an anchor jumping your content, slide it.

 Don't forget to put an id to your anchor !
 You can use and modify this script for any project you want, but please leave this comment as credit.

*****/

jQuery.fn.anchorAnimate = function(settings) {

 settings = jQuery.extend({
 speed : 1100
 }, settings);

 return this.each(function(){
 var caller = this
 $(caller).click(function (event) {
 event.preventDefault()
 var locationHref = window.location.href
 var elementClick = $(caller).attr("href")

 var destination = $(elementClick).offset().top;
 $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
 window.location.hash = elementClick
 });
 return false;
 })
 })
}
/******* End of jQuery Anchor Slider ********************/
