var div_top;
var div_bottom;

var pic_top;
var pic_bottom;

var current_pic = 1;
var new_pic = 2;

var div_myOpacity = 1;
var opacity_goal = 0;

var div_opacity_change = 0.05;
var rotation_running = 1;
var rotation_timing = 4000;//6000;
var rotation_interval;
var div_interval;

var pic_picNumber = 1;


// ********************** CHANGE THESE IMAGE NAMES *******************************
var myPictureArray = new Array('', 'slide1.jpg', 'slide2.jpg', 'slide3.jpg', 'slide4.jpg', 'slide5.jpg', 'slide6.jpg', 'slide7.jpg', 'slide8.jpg', 'slide9.jpg', 'slide10.jpg', 'slide11.jpg', 'slide12.jpg', 'slide13.jpg', 'slide14.jpg', 'slide15.jpg');


function fadeImage()
    {
    var is_done;
    
    if ( (opacity_goal == 0) && (div_myOpacity <= 0) )
        {
        is_done = 1;
        div_myOpacity = 0;
        }
    else if ( (opacity_goal == 1) && (div_myOpacity >= 1) )
        {
        is_done = 1;
        div_myOpacity = 1;
        }
    else
        is_done = 0;
        
    if (is_done == 0)
        {
        if (opacity_goal == 0)
            div_myOpacity = div_myOpacity - div_opacity_change;
        else
            div_myOpacity = div_myOpacity + div_opacity_change;

        if (div_myOpacity <= 0)
            div_myOpacity = 0;
        else if (div_myOpacity >= 1)
            div_myOpacity = 1;
        if (navigator.userAgent.indexOf('MSIE') > 0)
            div_top.style.filter = "alpha(opacity:" + (div_myOpacity * 100) + ")";
        else
            div_top.style.opacity = div_myOpacity;
        }
    else
        {
        clearInterval(div_interval);

        current_pic = new_pic;
        new_pic = new_pic + 1;
        if (new_pic > total_pics)
            new_pic = 1;
        var new_image = my_directory+myPictureArray[new_pic];
        if (opacity_goal == 0)
            {
            document.getElementById('main_pic_1').src = new_image;
            }
           else
            {
            document.getElementById('main_pic_2').src = new_image;
            }
        opacity_goal = opacity_goal == 1 ? 0 : 1;
        
        rotation_interval = setInterval("startRotation()", rotation_timing);    
        }
    }
    
function startRotation()
    {
    div_top = document.getElementById('main_div_1');
    div_bottom = document.getElementById('main_div_2');
    div_interval = setInterval("fadeImage()", 50);
    clearInterval(rotation_interval);
    
    div_bottom.style.display = "block";
    }

rotation_interval = setInterval("startRotation()", rotation_timing);    
