// Simple JavaScript Rotating Banner Using jQuery
// www.mclelun.com
var jqb_vCurrent = 0;
var jqb_vTotal = 0;
var jqb_vDuration = 5000;
var jqb_intInterval = 0;
var jqb_vGo = 1;
var jqb_vIsPause = false;
var jqb_vIsAlternate = false; // custom param for create alternate rotate style

jQuery(document).ready(function() {	
	jqb_vTotal = $(".jqb_slides").children().size() -1;
	$(".jqb_info").text($(".jqb_slide").attr("title"));	
	$(".jqb_slide:first > div").addClass("one");  
	jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);
	
	$("#btn_pauseplay").click(function() {
		if(jqb_vIsPause){
			jqb_fnChange();
			jqb_vIsPause = false;
			$("#btn_pauseplay").removeClass("jqb_btn_play");
			$("#btn_pauseplay").addClass("jqb_btn_pause");
		} else {
			clearInterval(jqb_intInterval);
			jqb_vIsPause = true;
			$("#btn_pauseplay").removeClass("jqb_btn_pause");
			$("#btn_pauseplay").addClass("jqb_btn_play");
		}
	});
	$("#btn_prev").click(function() {
		jqb_vGo = -1;
		jqb_fnChange();
	});
		
	$("#btn_next").click(function() {
		jqb_vGo = 1;
		jqb_fnChange();
	});
});

function jqb_fnChange(){
	clearInterval(jqb_intInterval);
	jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);
	jqb_fnLoop();
}

function jqb_fnLoop(){
	if(jqb_vGo == 1){
		jqb_vCurrent == jqb_vTotal ? jqb_vCurrent = 0 : jqb_vCurrent++;
	} else {
		jqb_vCurrent == 0 ? jqb_vCurrent = jqb_vTotal : jqb_vCurrent--;
	}
  
  keywords = [ "one", "two", "three", "four" ]
  if (jqb_vIsAlternate) $(".jqb_slide").hide();
  var j = 0;
	var z = 1;
	
	$("#jqb_object").find(".jqb_slide").each(function(i) { 
		j+=1;				
		if(i == jqb_vCurrent){
			$(".jqb_info").text($(this).attr("title"));
			if (jqb_vIsAlternate) {
			  if (j%2 == 0) {
			    $(this).animate({ opacity: 'show', width: 'show' }, 1500);
			    $(this).find('div').addClass(keywords[z]);
			  }else{
			    $(this).animate({ opacity: 'show', height: 'show' }, 1500);
			    $(this).find('div').addClass(keywords[z]);
			  }
			}else{
			  $(this).animate({ opacity: 'show', height: 'show' }, 1500);
			  $(this).find('div').addClass(keywords[z]);
			}						
		} else {
			if (jqb_vIsAlternate) {
  			if (j%2 == 0) {
			    $(this).animate({ opacity: 'hide', width: 'hide' }, 1500);
			    $(this).find('div').removeClass();
			  }else{
			    $(this).animate({ opacity: 'hide', height: 'hide' }, 1500);
			    $(this).find('div').removeClass();
			  }						
			}else{
			  $(this).animate({ opacity: 'hide', height: 'hide' }, 1500);
			  $(this).find('div').removeClass();
			}  
		}
		z+=1;
		if (z==4) z=0;
	});
}