﻿
var __heraImgSrcArray = [];
var __heraCurrentNewsDiv = null;
var __heraCurrentListLi = null;
var __heraCurrentTimer = null;
var __heraLastNum = 0;
var __heraLastNum2 = 0;
var __heraMaxItems = 5;

function __heraAddNewsItem(num, imageSrc)
{
	__heraImgSrcArray[num - 1] = imageSrc;
}

function __heraStart()
{
	__heraCurrentTimer = setTimeout("__heraRecurrSwitch();", 10);
}

function __heraStop(current)
{
	__heraLastNum = current-1;
	clearTimeout(__heraCurrentTimer);
}

function __heraRecurrSwitch()
{
	__heraLastNum++;
	if (__heraLastNum > __heraMaxItems)
		__heraLastNum = 1;
	__heraSwitchNews(__heraLastNum);
	clearTimeout(__heraCurrentTimer);
	if (__heraMaxItems <= 1) return;
	__heraCurrentTimer = setTimeout("__heraRecurrSwitch();", 5000);
}

function __heraSwitchNews(num)
{
	if (num <= 0) return;
	var index = (num - 1);

	if (__heraLastNum2 == num) return;
	__heraLastNum2 = num;

    if (__heraCurrentNewsDiv != null)
		__heraCurrentNewsDiv.style.display = 'none';
	if (__heraCurrentListLi != null)
		__heraCurrentListLi.className = '';

	__heraCurrentNewsDiv = document.getElementById('heraNews' + num.toString());
	if (__heraCurrentNewsDiv != null)
		__heraCurrentNewsDiv.style.display = 'block';
	__heraCurrentListLi = document.getElementById('heraList' + num.toString());
	if (__heraCurrentListLi != null)
		__heraCurrentListLi.className = 'selected';

	__heraBlendImage('heraImgDiv', 'heraImg', __heraImgSrcArray[index], 700);
}

function __heraOpacity(id, opacStart, opacEnd, millisec)
{
    var speed = Math.round(millisec / 100);
    var timer = 0;
    if (opacStart > opacEnd)
	{
        for (i = opacStart; i >= opacEnd; i--)
        {
            setTimeout("__heraChangeOpacity(" + i + ",'" + id + "')", (timer * speed));
            timer++;
        }
    }
    else if (opacStart < opacEnd)
    {
        for (i = opacStart; i <= opacEnd; i++)
        {
            setTimeout("__heraChangeOpacity(" + i + ",'" + id + "')", (timer * speed));
            timer++;
        }
    }
}
function __heraChangeOpacity(opacity, id)
{
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
function __heraShiftOpacity(id, millisec)
{
    if (document.getElementById(id).style.opacity == 0)
    {
        __heraOpacity(id, 0, 100, millisec);
    }
    else
    {
        __heraOpacity(id, 100, 0, millisec);
    }
}
function __heraBlendImage(divid, imageid, imagefile, millisec)
{ 
    if (imagefile=='')
	{
		document.getElementById(divid).style.display='none';
	}
	else
	{
		document.getElementById(divid).style.display='block';
	}
    var speed = Math.round(millisec / 100);
    var timer = 0;
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
    __heraChangeOpacity(0, imageid);
    document.getElementById(imageid).src = imagefile;
    for(i = 0; i <= 100; i++)
    {
        setTimeout("__heraChangeOpacity(" + i + ",'" + imageid + "')", (timer * speed));
        timer++;
    }
}
