﻿var artCount = 0;
var current = 0;
var interval;
var rotateTime = '8000';

$(function(){
	initRotate();
});

function initRotate()
{
	artCount = $(".home-article").length;
	
	$('#home-rotate-link-0').addClass('on');
	$('#home-rotate-link-0').removeClass('off');
	
	
	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();
		
		$('#home-article-' + e).show();
		
		
		$('#home-rotate-link-' + e).addClass('on');
		$('#home-rotate-link-' + e).removeClass('off');
	};
}

function loadArticle(e)
{
	clearInterval(interval);
	
	interval = setInterval('artRotate()', rotateTime);
	
	hideAll();
	
	current = e;
		
	$('#home-article-' + e).show();
		
		
	$('#home-rotate-link-' + e).addClass('on');
	$('#home-rotate-link-' + e).removeClass('off');
}

function hideAll()
{
	for(var a = 0; a < artCount; a++)
	{
		$('#home-article-' + a).hide();
		
		$('#home-rotate-link-' + a).addClass('off');
		$('#home-rotate-link-' + a).removeClass('on');
	}
}


function artRotate()
{
	hideAll();
	
	if(current == artCount-1)
	{
		current = -1;
	}
	current++;
	
	$('#home-article-' + current).show();
	
	$('#home-rotate-link-' + current).addClass('on');
	$('#home-rotate-link-' + current).removeClass('off');
	
}


/*
 * original code: rewritten to utulize Jquery 2011-05-20
 * 
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);

*/
