// newtabs.js
//
// generic tab script
//
// Written by Jeff Parker - jeffreyp(at)codero.com
//
// Props to the jQuery community for guidance and support
//
// banners.js
//
// javascript to handle banner animations, read-more and read-less,
// and pagination
//
// Written by Tony Snyder - tonys(at)codero.com
//

//banner timer rotation deal
var bannerCount = $(".slider li a").length || 0;
var curBanner = 1;
var newBanner=1;
var bannerCycleTimeClicked=10;//used to reset bannerCycleTime var when a user clicks a dot
var bannerCycleTimeSafe=5;//used to reset the bannerCycleTime var after the bannerCycletimeClicked has passed
var bannerCycleTime=5;
var curBannerCycleTime=0;
var bannerTimer;
var cycling = false;
if(bannerCount >1){
    $(".slider li a").click(function(){
        if(cycling == false){
            cycling=true;
            stopTimer();
            curBannerCycleTime=0;
            var hrefSplit =$(this).attr('href').split('-');
            newBanner = parseInt(hrefSplit[1]);
            cycleBanner();
            bannerCycleTime=bannerCycleTimeClicked;
            startTimer();
        }
        return false;

    });
}

function cycleBanner(){

    if(newBanner != curBanner && cycling == true){
        $('#banner-link-li-'+curBanner.toString()).removeClass('active');
        $('#banner-'+curBanner.toString()).fadeOut('slow',function(){
            $('#banner-link-li-'+newBanner.toString()).addClass('active');
            $('#banner-'+newBanner.toString()).fadeIn('slow',function(){
                curBanner = newBanner;
                cycling=false;
            });
        });
    }else if(newBanner == curBanner && cycling === true){
        cycling=false;
    }

}
function cycleTimer(){
    if(cycling===false) curBannerCycleTime++;

    if(curBannerCycleTime > bannerCycleTime && cycling ===false){
        cycling = true;
        newBanner = 1;
        if(curBanner < bannerCount){
            newBanner = curBanner + 1;
        }
        curBannerCycleTime=0;
        bannerCycleTime=bannerCycleTimeSafe;
        cycleBanner();
    }
}
function startTimer(){
    if(bannerCount >1)
        bannerTimer = setInterval(cycleTimer,1000);
}
function stopTimer(){
    if(bannerCount >1)
        clearInterval ( bannerTimer);
}
startTimer();
//end banner slider

var currentTab = $('.product-tabs li a')[0];
		

$(".product-tabs li a").click(function()
{
    var newTabID = $(this).attr('href');
    var curTabID= $(currentTab).attr('href');
    if(newTabID != curTabID){
        $(currentTab).parent().removeClass("tab-active");
        $(curTabID).addClass('hide');
        $(this).parent().addClass("tab-active");
        $(newTabID).removeClass('hide');
        currentTab = this;
    }
    return false;
});
