
(function($){
	$(function(){
//		$('#banner .section:first-child .caption').show();
		$('#banner').each(function(index, domElm){
			setInterval( "slideSwitch("+index+")", 15000);
		});
	});
})(jQuery);
function slideSwitch(inputIndex) {
	var baseBlock;
	(function($){
		$('#banner').each(function(index, domElm){
			if(inputIndex === index){
				baseBlock = domElm;
				return false;
			}
		});
		
		if ($(baseBlock).find('.section').length < 2){
			// single item willnot proceed.
			return false;
		}
		var $active = $(baseBlock).find('.active');
		if ( $active.length > 1 ){
			$(baseBlock).children().removeClass('active last-active');
			$active = $(baseBlock).find('.section:first');
		}
		if ( $active.length === 0 ){
			$active = $(baseBlock).find('.section:first');
		}
		var $next = $active.next().length ? $active.next() : $(baseBlock).find('.section:first');
		$active.addClass('last-active');
		$active.children(".caption").hide();
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				$active.removeClass('active last-active');
				$next.children(".caption").show();
			});
	})(jQuery);
}

