// Simple JavaScript Rotating Banner Using jQuery
// www.mclelun.com
var banner_vCurrent = 0;
var banner_vTotal = 0;
var banner_vDuration = 5000;
var banner_intInterval = 0;
var banner_vGo = 1;
var banner_vIsPause = false;

jQuery(document).ready(function() {	
	banner_vTotal = $(".banner_slides").children().size() -1;
	$(".banner_info").text($(".banner_slide").attr("title"));	
	banner_intInterval = setInterval(banner_fnLoop, banner_vDuration);
	
	$("#btn_pauseplay").click(function() {
		if(banner_vIsPause){
			banner_fnChange();
			banner_vIsPause = false;
			$("#btn_pauseplay").removeClass("banner_btn_play");
			$("#btn_pauseplay").addClass("banner_btn_pause");
		} else {
			clearInterval(banner_intInterval);
			banner_vIsPause = true;
			$("#btn_pauseplay").removeClass("banner_btn_pause");
			$("#btn_pauseplay").addClass("banner_btn_play");
		}
	});
	$("#btn_prev").click(function() {
		banner_vGo = -1;
		banner_fnChange();
	});
		
	$("#btn_next").click(function() {
		banner_vGo = 1;
		banner_fnChange();
	});
});

function banner_fnChange(){
	clearInterval(banner_intInterval);
	banner_intInterval = setInterval(banner_fnLoop, banner_vDuration);
	banner_fnLoop();
}

function banner_fnLoop(){
	if(banner_vGo == 1){
		banner_vCurrent == banner_vTotal ? banner_vCurrent = 0 : banner_vCurrent++;
	} else {
		banner_vCurrent == 0 ? banner_vCurrent = banner_vTotal : banner_vCurrent--;
	}
		
	$("#banner_rotator").find(".banner_slide").each(function(i) { 
		if(i == banner_vCurrent){
			$(".banner_info").text($(this).attr("title"));
            $(this).fadeIn({ opacity: 'show', height: 'show' }, 2000);
            } else {
            $(this).fadeOut({ opacity: 'hide', height: 'hide' }, 2000);
		}
	});
}






