﻿var articles = getElementsByClass('home-article', $('main-content'), 'div');
var links; 
var artCount = articles.length;
var current = 0;
var interval;
var rotateTime = '8000';
//var rotateTime = '10000'; // 10 seconds

function initRotate() {
    if(!$('home-rotate-nav')) return; 

    links = $('home-rotate-nav').getElementsByTagName('a');
    $('home-rotate-link-0').className = 'on';
    
    for(var x = 0; x < artCount; x++) {
        $('home-rotate-link-' + x).onclick = showElem(x);
    }
    
    interval = setInterval('artRotate()', rotateTime);
}

function showElem(e) {
    return function () {
        clearInterval(interval);
        hideAll();
        articles[e].style.display = 'block';
        links[e].className = 'on';
    };
}

function hideAll() {
    for(var a = 0; a < artCount; a++) {
        articles[a].style.display = 'none';
        links[a].className = 'off';
    }
}


function artRotate() {
    hideAll();
    if(current == artCount-1) {
        current = -1;
    }
    current++;
    articles[current].style.display = 'block';
    links[current].className = 'on';

    
}

addEvent(window, 'load', initRotate);