﻿// Simple JavaScript Rotating Banner Using jQuery
// www.mclelun.com
var jqb_vCurrent = 0;
var jqb_vTotal = 0;
var jqb_vTimeOfAnimation = 1000;
var jqb_vDuration = 5000;
var jqb_intInterval = 0;
var jqb_vItemHeight = 140;
var jqb_vGo = 1;
var jqb_tmp = 20;
var jqb_title;

$(document).ready(function () {

    $("#news_object").find(".featureditems").each(function () {
        $(this).addClass('absolute');
    });

    jqb_vTotal = $(".featureditems").children().size() - 1;

    $("#news_object").find(".featureditems").each(function (i) {
        jqb_tmp = ((i - 1) * jqb_vItemHeight) + (jqb_vItemHeight);
        $(this).animate({ "top": jqb_tmp + "px" }, 5);
    });

    $("#btn_prev").click(function () {
        jqb_fnChange();
        jqb_vGo = -1;
        jqb_fnLoop();
    });
    $("#btn_next").click(function () {
        jqb_fnChange();
        jqb_vGo = 1;
        jqb_fnLoop();
    });
    
    if (jqb_vTotal > 1) {

        jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);
        $("#btn_prev").show();
        $("#btn_next").show();
    }
    else {
        $("#btn_prev").hide();
        $("#btn_next").hide();
    }


});

function jqb_fnChange() {
    clearInterval(jqb_intInterval);
    jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);

}

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--;
    }

    $("#news_object").find(".featureditems").each(function (i) {
    
        //Horizontal Scrolling
        jqb_tmp = ((i - 1) * jqb_vItemHeight) - ((jqb_vCurrent - 1) * jqb_vItemHeight);
        $(this).animate({ "top": jqb_tmp + "px" }, jqb_vTimeOfAnimation);
  
    });


}







