// Simple JavaScript Rotating Banner Using jQuery
// Original code from http://www.mclelun.com/blog/2010/01/jquery-rotating-banner/
// Modified January 2011 by Ali Khan (akhan@flux-development.com) for hover pause
// and concurrent list change
var jqb_vCurrent = 0;
var jqb_vTotal = 0;
var jqb_vDuration = 5000; //length of time before slide changes
var jqb_intInterval = 0;

var restartInterval = 0;
var jqb_vGo = 1;
var jqb_vIsPause = false;
var jqb_tmp = 20;
var jqb_title;
var boxWidth = 691;
jQuery(document).ready(function() {
   
    jqb_vTotal = $(".jqb_slides").children().size() -1;
    jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);
			
    $("#jqb_object").find(".jqb_slide").each(function(i) {
        jqb_tmp = ((i - 1)*691) - ((jqb_vCurrent -1)*691);
        $(this).animate({
            "left": jqb_tmp+"px"
        },0);
    });


    $('.jqb_slide').mouseenter(function() {
        clearInterval(jqb_intInterval);
        clearInterval(restartInterval);
        jqb_vIsPause = true;
    });
    $('.jqb_slide').mouseleave(function() {
        clearInterval(restartInterval);
        restartInterval = setInterval(restartChange, 20000); //length of time before slideshow resumes after mousing over main content
        jqb_vIsPause = false;
    });


    $("li.infoDefault").mouseenter(function(){

        if(jqb_vCurrent != $(this).index())
        {
            
            while($(this).index() != jqb_vCurrent) {
                jqb_vGo = 1;
                jqb_fnChange();
            }

        }
        clearInterval(jqb_intInterval);
        clearInterval(restartInterval);
        jqb_restart = false;
        jqb_vIsPause = true;
        jqb_noHover = false;
        jqb_restart = 0;
    }).mouseleave(function(){
        jqb_noHover = true;
        jqb_vIsPause = false;
        clearInterval(restartInterval);
        restartInterval = setInterval(restartChange, 5000); //length of time before slideshow resumes after mousing over info navigation
    });
});

function restartChange() {
    clearInterval(restartInterval);
    if(!jqb_vIsPause) {
        clearInterval(jqb_intInterval);
        jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);
        jqb_fnLoop();
    
    }
        
    
}


function jqb_fnChange(){
    clearInterval(jqb_intInterval);
    jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);
    jqb_fnLoop();
}

function jqb_fnLoop(){
    if(!jqb_vIsPause) {
        $('#infoBox_' + jqb_vCurrent).removeClass('infoHighlighted');
        if(jqb_vGo == 1){
            jqb_vCurrent == jqb_vTotal ? jqb_vCurrent = 0 : jqb_vCurrent++;
        } else {
            jqb_vCurrent == 0 ? jqb_vCurrent = jqb_vTotal : jqb_vCurrent--;
        }

        $('#infoBox_' + jqb_vCurrent).addClass('infoHighlighted');
        $("#jqb_object").find(".jqb_slide").each(function(i) {



            //Horizontal Scrolling
            jqb_tmp = ((i - 1)*691) - ((jqb_vCurrent -1)*691);
            $(this).animate({
                "left": jqb_tmp+"px"
            }, 0);

        /*
		//Fade In & Fade Out
		if(i == jqb_vCurrent){
			$(".jqb_info").text($(this).attr("title"));
			$(this).animate({ opacity: 'show', height: 'show' }, 500);
		} else {
			$(this).animate({ opacity: 'hide', height: 'hide' }, 500);
		}
		*/

        });

    }
}
