// Simple JavaScript Rotating Banner Using jQuery
// www.mclelun.com
var jqb_vCurrent = 0;
var jqb_vTotal = 0;
var jqb_vDuration = 10000;
var jqb_intInterval = 0;
var jqb_vGo = 1;
var jqb_vIsPause = false;
var jqb_tmp = 20;
var jqb_title;
var distance = 1;
var first = 0;
jQuery(document).ready(function($) {	
	jqb_vTotal = $(".slides").children().size() -1;	
	jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);
	
	$(".slides").find(".slide").each(function(i) {
		jqb_tmp = ((i - 1)*960) - ((jqb_vCurrent -1)*960);
		if (first == 0) {
			$(this).animate({ opacity: 'show' }, 1000);
			first = 1;
		}
	});
	
	$("#controls ul li").click(function() {
		var dest = parseInt($(this).attr('class'));
		if (jqb_vCurrent > dest) {
			jqb_vGo = -1;
			distance = Math.abs(dest-jqb_vCurrent);
			jqb_fnChange();
		} else if (jqb_vCurrent < dest) {
			jqb_vGo = 1;
			distance = Math.abs(dest-jqb_vCurrent);
			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 += distance;
	} else{
		jqb_vCurrent == 0 ? jqb_vCurrent = jqb_vTotal : jqb_vCurrent -= distance;
	}
	$("#controls ul li").removeClass('current');
	$("#controls ul").find("."+jqb_vCurrent).addClass('current');
	jqb_vGo = 1;
	distance = 1;
	$(".slides").find(".slide").each(function(i) { 
		
		//Horizontal Scrolling
		jqb_tmp = ((i - 1)*960) - ((jqb_vCurrent -1)*960);
		if(i == jqb_vCurrent){
			$(this).animate({ opacity: 'show' }, 1000);
		} else {
			$(this).animate({ opacity: 'hide' }, 1000);
		}

	});


}







