$(document).ready(function() {
	
	$("#logo-slider").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
				auto: true,
				speed: 3000,
				visible: 4,
				circular: true
    });
		
	 $('.image_thumb li a').each(function() {
	 	$(document.body).append('<img src="'+$(this).attr('href')+'" style="display: none" alt="hidden"/>')
	   }
	 ) 		

$(".image_thumb ul li:first").addClass('active'); //Add the active class (highlights the very first list item by default)
$(".image_thumb ul li").click(function(){
	window.clearInterval(timer);
    //Set Variables
    var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
    var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL

    if ($(this).is(".active")) {  //If the list item is active/selected, then...
        return false; // Don't click through - Prevents repetitive animations on active/selected list-item
    } else { //If not active then...
        //Animate the Description
		$('.main_image img').fadeOut(400, function() { $(".main_image img").attr({ src: imgTitle , alt: imgAlt}); }).fadeIn(400)
    }
    //Show active list-item
    $(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all list-items
    $(this).addClass('active');  //Add class of 'active' on the selected list
    return false;

})

	function sliderTimeOut() {
      timer = window.setInterval( function()
      {
         slideToNext();
      }, 5000);
	}
	  
	 sliderTimeOut()
	 
	 function slideToNext() {
	 	var item = $('.image_thumb ul').find('li.active');
		var next = $(item).next().length ? $(item).next().find('a').attr('href') : $('.image_thumb ul li:first').find('a').attr('href');
		var nextItem = $(item).next().length ? $(item).next(): $('.image_thumb ul li:first');
		
		$('.main_image img').fadeOut(400, function() { $(".main_image img").attr({ src: next}); }).fadeIn(400);
		$(".image_thumb ul li").removeClass('active');
		$(nextItem).addClass('active');
	 }
});
