 (function($) {
 
	$.fn.carousel = function(options) {
	
		var defaults = {
			speed: -500
		};
		var $pict;
		var $leftButton = null;
		var $rightButton = null;

		//merge options and defaults
		options = jQuery.extend(defaults, options);
        var element = this;
	//Get objects, style divs.
        $(element).ready(function(){
       			//Initialize variables.
			$pict = $(element).children('ul').children('li');
			$leftButton = $(element).children('div.buttons').children('a.previous');
			$rightButton = $(element).children('div.buttons').children('a.next');
			//Styles.
			var height = 0;
			$(element).children('div.buttons').children('a.next').css('cursor','pointer');
			$pict.css({'display':'none'});
			$pict.first().css('display','block');
			$leftButton.addClass('previous-hidden');	
			$leftButton.css('display','block');
			$rightButton.css('display','block');
			
			//Add class to indentify first, last and active images.
			$pict.first().addClass('first active');
			$pict.last().addClass('last');
		});
		
		//Transitions, Fadein and FadeOut images
 		//$actual= visible image.
		//$next= the next image to show.
		function doFade($actual, $next)
		{
			if ($pict.hasClass('active')){

				$actual.children('div').css('display','none');
				$actual.stop(true, true).fadeOut(options.speed, function(){$actual.children('div').css('display','block');} );
				$pict.removeClass('active');
				$next.addClass('active');
				$next.children('div').css('display','none');
				$next.stop(true, true).delay(900).fadeIn(options.speed, function(){$next.children('div').css('display','block')});
			}
		}
		//This function gets the visible image and the next image to be displayed, 
		//and then send them to doFade function.
		$leftButton.click(function(event){
					var $active = $(element).children('ul').children('li.active');	//active image.
			var $previous = $active.prev(); //previous image in the DOM tree
			if (!$pict.hasClass('first active')){
				
				
				doFade($active,$previous);
			}
			
			$rightButton.css('cursor','pointer');
			$rightButton.removeClass('next-hidden');
			
			$active = $(element).children('ul').children('li.active');
			
			if ($pict.hasClass('first active')){
				$leftButton.css('cursor','default');	
				$leftButton.addClass('previous-hidden');				
			}
			event.preventDefault();
		});
		
		//This function gets the visible image and the next image to be displayed, 
		//and then send them to doFade function.
		$rightButton.click(function(event){
					var $active = $(element).children('ul').children('li.active');	//active image.
			var $next = $active.next(); //next image in the DOM tree.
			if (!$active.hasClass('last active')){
				doFade($active,$next);
			}
			
			$leftButton.css('cursor','pointer');
			$leftButton.removeClass('previous-hidden');	
			
			$active = $(element).children('ul').children('li.active');
			
			if ($pict.hasClass('last active')){
				$rightButton.css('cursor','default');
				$rightButton.addClass('next-hidden');
			}
			event.preventDefault();
		});
    };
	$.fx.off = false;
 })(jQuery);

function disableLink(){
	$('.pict-list >li a').each(function(index){
		$learnAnchor = $(this).parent().find('.carouselanc');
		if($($learnAnchor).length){
		}
		else{
			$(this).click(function(event){
				event.preventDefault();	
			});
		}
	});
}


