// Simple JavaScript Rotating Banner Using jQuery
// www.mclelun.com
var jqb_vCurrent = 0; // current index of image
var jqb_vTotal = 0; // total images minus 1
var jqb_vDuration = 8000;
var jqb_intInterval = 0;
var jqb_vGo = 1; // 1 = forward, -1 = backward
var jqb_vIsPause = false;
var jqb_tmp = 20;
var jqb_title;
var distance = 1; // absolute value of number of images to skip, default = 1
var zindex = 0;

jQuery(document).ready(function($) {
	jqb_vTotal = $(".jqb_slides").children().size() -1;	
	zindex = jqb_vTotal + 1;
	jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);
	$("#jqb_object").find(".jqb_slide").each(function(i) {
		jqb_tmp = ((i - 1)*660) - ((jqb_vCurrent -1)*660);
		$(this).animate({"left": jqb_tmp+"px"}, 500);
		$(this).animate({ opacity: 'show' }, 500);
		$(this).css("z-index",zindex--);
	});
	
	$(".jqb_bar ul li").click(function() {
		var dest = parseInt($(this).attr('rel'));
		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) {
		var count = 0;
		distance = 0;
		jqb_vCurrent = 0;
		$("#jqb_object").find(".jqb_slide").each(function(i) {
			if (i < jqb_vTotal) {
				jqb_tmp = 660;
				$(this).css("left", jqb_tmp+"px");
				count++;
			} else {
				$(this).animate({"left": "-660px"}, 500);
			}
		});
		jqb_vCurrent += distance;
	} else if (jqb_vGo == -1) {
		jqb_vCurrent -= distance;
	} else {
		jqb_vCurrent += distance;
	}
	$(".jqb_bar ul li").removeClass('current');
	$(".jqb_bar ul").find("li").each(function(i) {
		if (i == jqb_vCurrent) {
			$(this).addClass('current');
		}
	});
	jqb_vGo = 1;
	distance = 1;
	$("#jqb_object").find(".jqb_slide").each(function(i) { 
		//Horizontal Scrolling
		jqb_tmp = ((i - 1)*660) - ((jqb_vCurrent -1)*660);
		$(this).animate({"left": jqb_tmp+"px"}, 500);
	});
}







