/*
* jQuery Carousel Compilation by Ryan Barr
* http://spookyismy.name
* v1.0.0
*/
$(document).ready(function() {

/* Show default content within .carousel-content */
$(".carousel-content").show();
$(".carousel-content .carousel-content-image").animate({ opacity: 1 }, 1 );

/* Set the first menu item as active. */
$("#carousel-menu li:first").addClass('selected');

/* If menu item is clicked, switch content properly. */
$("#carousel-menu li.menu-item").click(function(){

var altText = $(this).find('.carousel-content-image img').attr("alt");
var imgSrc = $(this).find('a.carousel').attr("href");
var imgDesc = $(this).find('.info').html();

if ($(this).is(".selected")) {
return false;
} else {
$(".carousel-content").animate({ opacity: 0 }, 250 , function() {
$(".carousel-content-info").html(imgDesc).animate({ opacity: 1, marginBottom: "0" }, 400 );
$(".carousel-content-image img").attr({ src: imgSrc , alt: altText }).animate({ opacity: 1 }, 400 );
$(".carousel-content").animate({ opacity: 1 }, 250 );
});
}

$("#carousel-menu li").removeClass('selected');
$(this).addClass('selected');
return false;

});

/* Pause Rotation if Hovering #carousel-menu Item */
carouselNext = false;
$("#carousel-menu li").hover(
function () {
carouselNext = true;
},
function () {
carouselNext = false;
}
);

/* Rotate Carousel, Move from :last to :first if necessary. */
var carouselNextClick = function(){
if(!carouselNext) {

var $nextElement = $(".selected").next("li.menu-item");

if($("li.selected").hasClass("menu-last") ){
$("#carousel-menu li:first").trigger("click");
} else {
$nextElement.trigger("click");
}

}
};

/* Pause between rotations in milliseconds. (3500 is 3.5 seconds) */
setInterval(carouselNextClick, 12000);

});

