/*********** Images *************/
//count
var n_count = 4;
//images
var a_names = new Array( 

"/img/screenshots/mainwnds.jpg",  
"/img/screenshots/recorders.jpg", 
"/img/screenshots/optionss.jpg",
"/img/screenshots/players.jpg"

);

var a_alts = new Array(

"",
"",
"",
"",
"",
"",
"",
"",
""

);

//pause
var n_sec = 3;
//speed
var n_speed = 30;

/*********************** nilaz *********************/
//load images
var a_image = new Array();
for ( i = 0; i < n_count; i++ )
{
    a_image[i] = new Image;
    a_image[i].src = a_names[i];
}

var n_work_sec = n_sec * 1000;
var n_current = 0;
var n_opacity = 100;

var div_place = document.getElementById( "gallery" );
if ( null != div_place )
{
	div_place.innerHTML = "<div class='first'></div> <div class='back'></div>";
	showFirst();
}

function showFirst()
{
    if ( null == div_place )
        return;
        
    n_current = Math.round( Math.random() * ( n_count - 1 ) );
    n_prev = n_current - 1;
    if ( 0 > n_prev )
        n_prev = n_count - 1;
    
    setImage( n_prev, n_current );
        
    setTimeout( "hideFirst()", n_work_sec );
}

function showNext()
{
    if ( null == div_place )
        return;

    n_prev = n_current;
    n_current++;
    
    if ( n_count <= n_current )
        n_current = 0;

    setImage( n_prev, n_current );      

    n_opacity = 100;
    setTimeout( "hideFirst()", n_work_sec );
}


function hideFirst()
{
    n_opacity -= 1;
    if ( 0 > n_opacity )
        setTimeout( "showNext()", n_work_sec );
    else
    {
        var div_first = document.getElementById( "gal-first" );
        div_first.style.opacity = n_opacity / 100;
        
        //IE
        div_first.style.filter = "alpha(opacity:" + n_opacity + ")";
        
        setTimeout( "hideFirst()", n_speed );
    }
}

function setImage( prev, cur )
{
    div_place.innerHTML = "<div id='gal-first'><a href='/screenshots/'><img src='" + a_image[prev].src + "' alt='" + a_alts[prev] + "' /></a></div> <div id='gal-back'><a href='/screenshots/'><img src='" + a_image[cur].src + "' alt='" + a_alts[cur] + "' /></a></div>";
}
