(function ($) {
	
	Drupal.behaviors.sas2Block = {
	  attach: function (context, settings) {
			
			slider_timer = 7000;
			if($('#slider_timer').html()) {
				slider_timer = $('#slider_timer').html();
			}
			//alert('timer :'+ slider_timer);
			
			count = $('#carousel .layer').size();
			
			$('#carousel .layer').each(function () {
				//$(this).hide();
				if($(this).hasClass('first')) {
					$(this).css({ opacity: 1 }).show();
	      }
				else {
					$(this).css({ opacity: 0 }).hide();
	      }
			});

			var timer = 0;
			timer = setInterval( function() { Drupal.rotateImage() }, slider_timer);
		}
	}

	Drupal.rotateImage = function () {
		//Get the current selected item (with selected class), if none was found, get the first item
		var current_image = $('#carousel .selected').length ? $('#carousel .selected') : $('#carousel .first');
		var next_image = (current_image.next().length) ? current_image.next() : $('#carousel .first');

		//clear the selected class & hide the image
		$('#carousel .layer').removeClass('selected').css({ opacity: 0 }).fadeOut('slow', function() {});

		next_image.addClass('selected').css({ opacity: 1 }).fadeIn('slow', function() {});
	}
	
})(jQuery);
;

