/*
var frontImg = new Array(
    "images/slides/North_Shore_2895-slide.jpg",
    "images/slides/ST070825-2531-slide.jpg",
    "images/slides/ST071023-2864-slide.jpg",
    "images/slides/ST071027-3159-slide.jpg",
    "images/slides/blackbird_six-0389-slide.jpg",
    "images/slides/bodie-church-slide.jpg",
    "images/slides/cypress_fog-3130093-slide.jpg",
    "images/slides/fences-01051g-slide.jpg",
    "images/slides/lantern_1383-slide.jpg",
    "images/slides/make_a_splash-slide.jpg",
    "images/slides/plankbridge_2149-slide.jpg",
    "images/slides/pre-ponderance-0362-slide.jpg",
    "images/slides/rockabye_1306-slide.jpg",
    "images/slides/row_your_boat-proc-3319-slide.jpg",
    "images/slides/touch_down-2469-slide.jpg",
    "images/slides/window_on_the_light-2512-slide.jpg"
);
*/
var messageBlocks = new Array(
    "mainMsg",
    "stockMsg"
);
    
function doSlides() {
    // randomize the array to keep it interesting
    frontImg.sort(function() {return 0.5 - Math.random()});
    setImageArray(frontImg);
    
    // set a random image for the opening image and make it visible after it's set
    iDiv = document.getElementById('slideImg');
    iDiv.src = frontImg[Math.floor(Math.random() * frontImg.length)];
    iDiv.style.visibility = "visible";
    
    // set another random element to be the final image that stays steady
    randIndex = Math.floor(Math.random() * frontImg.length);
    lastImg = frontImg[randIndex];
    
    delay = 8000;       // delay for the slideshow
    
    // run the show after a 3 second pause
    setTimeout("fadeToNext()", 3000);
}

var elTop = 0;
var oTimeout;
var msgOffsets = Array();
    msgOffsets['m1'] = 0;
    msgOffsets['m2'] = -60;
    msgOffsets['m3'] = -120;
var curTop;
var targetTop;
var slideEl;

function slideUp() {
    slideEl = document.getElementById('msgInner');
    
    if(curTop >= targetTop) {
        slideEl.style.marginTop = curTop +'px';
        curTop -= 2;
        oTimeout = setTimeout("slideUp()", 2);
    }
    else {
        clearTimeout(oTimeout);
    }
    
    
}

function slideDown() {
    if(curTop <= targetTop) {
        slideEl.style.marginTop = curTop +'px';
        curTop += 2;
        oTimeout = setTimeout("slideDown()", 3);
    }
    else {
        clearTimeout(oTimeout);
    }
    
    
}

function slideTo(ndx) {
    slideEl = document.getElementById('msgInner');
    curTop = slideEl.offsetTop;
    targetTop = msgOffsets[ndx];
    
    document.getElementById('m1').style.backgroundColor = null;
    document.getElementById('m2').style.backgroundColor = null;
    document.getElementById('m3').style.backgroundColor = null;
    document.getElementById(ndx).style.backgroundColor = '#ffcc66';
    
    
    if(targetTop < curTop) {
        slideUp();
    }
    else if(targetTop > curTop) {
        slideDown();
    }
    else {
        return;
    }
    
}

function msgInit() {
    o1Interval = setInterval("slideTo('m1')", 100);
    o2Interval = setInterval("slideTo('m2')", 6000);
    o3Interval = setInterval("slideTo('m3')", 12000);
    
    setTimeout("clearInterval(o1Interval)", 1000);
    setTimeout("clearInterval(o2Interval)", 6000);
    setTimeout("clearInterval(o3Interval)", 12000);
    
    setTimeout("slideTo('m1')", 16000);
}

/**
 * Make sure the contents column is as high as the sidebar nav column so that
 * footer is not overdrawn. 
 */
function checkSidebarHeight() {
    if(document.getElementById('frontSidebar')) {
        sideEl = document.getElementById('frontSidebar');
        
        if(sideEl.offsetHeight < '525') {
            sideEl.style.height = '525px';
        }
    }
}

function hideHomeLink(state) {
    if(!state) {
        document.getElementById('homenav').style.display = 'block';
    }
    else {
        document.getElementById('homenav').style.display = 'none';
    }
}

preLoad(frontImg);

