var pics1 = Array();
var pics2 = Array();

pics1[0] = '/view/img/hp/imag.1.jpg';
pics1[1] = '/view/img/hp/imag.2.jpg';
pics1[2] = '/view/img/hp/imag.3.jpg';
pics1[3] = '/view/img/hp/imag.4.jpg';
pics1[4] = '/view/img/hp/imag.5.jpg';

pics2[0] = '/view/img/hp/imag.1b.jpg';
pics2[1] = '/view/img/hp/imag.2b.jpg';
pics2[2] = '/view/img/hp/imag.3b.jpg';
pics2[3] = '/view/img/hp/imag.4b.jpg';
pics2[4] = '/view/img/hp/imag.5b.jpg';

var currentAlpha = 100;
var currentPic = 0;
var alphaDir = -1;
var nextPic = Array();
nextPic[1] = 0;
nextPic[2] = 0;
nextPic[3] = 0;
nextPic[4] = 0;
nextPic[5] = 0;

function start_animate(delay)
{  
    currentPic = Math.floor(Math.random() * 5) + 1;
    if(currentPic < 1) currentPic = 1;
    if(currentPic > 5) currentPic = 5;
    
    currentAlpha = 100;
    alphaDir = -1;
    
    setTimeout('animate_pic()', delay);
}

function animate_pic()
{
    currentAlpha += alphaDir * 35;
    if(currentAlpha <= 0) 
    {
        currentAlpha = 0; alphaDir = 1;
        update_alpha(currentPic);
        switch_pic(currentPic);
        setTimeout('animate_pic()', 150);
        return;
    }
    if(currentAlpha > 100)
    {
        currentAlpha = 100; alphaDir = -1;
        update_alpha(currentPic);
        setTimeout("start_animate(250)", 500);
        return;
    }
    update_alpha(currentPic);
    setTimeout("animate_pic()", 150);
}

function update_alpha(pid)
{
    try {
     var pdiv = document.getElementById('hpic' + pid);
     pdiv.style.opacity = currentAlpha / 100;
     pdiv.style.MozOpacity = currentAlpha / 100;
     if(pdiv.filters)
         pdiv.filters[0].opacity = currentAlpha;
    } catch(E) { }
}

function switch_pic(pid)
{
    var pdiv = document.getElementById('hpic' + pid);    
    nextPic[pid] = 1 - nextPic[pid];
    np = nextPic[pid];
    if(np == 0) np = pics1[pid-1];
    else np = pics2[pid-1];
    
    pdiv.innerHTML = "<img src='" + np + "' border='0' width='122' alt=''/>";
}
