﻿var features = new Array();
var speed = 6000;
var transitionSpeed = 2000;
var showClass = 'showFeature';
var interval;
var dPrefix = '#feature_';

function setRotation(count) {
    var i;
    var id;
    var show;
    for (i = 1; i <= count; i++) {
        id = dPrefix + i;
        if ($(id).length) {
            features.push(i);
            if ($(id).hasClass(showClass)) {
                show = $(id);
            }
            $(id).hide(0);
        }
    }
    show.show(0);
    if (features.length > 1) {
        interval = setInterval(rotate, speed);
    }
    $("span.featureLabelBG").css({ opacity: 0.8 });
    $("span.featureLabel").css({ opacity: 1.0 });
    $("span.featureLead").css({ opacity: 1.0 });
}

function rotate() {
    var i;
    var cur;
    var toShow;
    for (i = 0; i < features.length; i++) {
        cur = dPrefix + features[i];
        if ($(cur).hasClass(showClass)) {
            if ((i + 1) == features.length) {
                toShow = features[0];
            } else {
                toShow = features[i + 1];
            }
            $(cur).toggleClass(showClass);
            $(cur).fadeOut(transitionSpeed);
        }
    }
    if (toShow != '') {
        cur = dPrefix + toShow;
        $(cur).toggleClass(showClass);
        $(cur).fadeIn(transitionSpeed);
    }
}


function swapContent(id, bid) {
    clearInterval(interval);
    if ($(id).length && $(id).attr('id') != $('.' + showClass).attr('id')) {
        $('.' + showClass).delay(100).fadeOut(transitionSpeed);
        $('.' + showClass).toggleClass(showClass);
        $(id).fadeIn(transitionSpeed);
        $(id).toggleClass(showClass);
    }
    interval = null;
    interval = setInterval(rotate, speed);
}
