﻿function moveFrame(direction, timer) {

    if (timer)
        var timeout = setTimeout("", 5000);
    else
        clearTimeout();
    
    var frmEle = document.home_sale_form;
    var currentFrame = eval(frmEle.currentFrame.value);
    var totalFrames = eval(frmEle.totalFrames.value);
    
    //increment frame
    currentFrame += direction;
    if (currentFrame > totalFrames)
        currentFrame = 0;
    if (currentFrame < 0)
        currentFrame = totalFrames;
    
    //get link for current frame
    var link = frmEle.link[currentFrame].value;
    //build new html
    var html = "<a href=\"" + link + "\">";
    html += "<img src=\"images/sale/home_" + currentFrame + ".jpg\" width=\"466\" height=\"350\" alt=\"Blinds on Sale\" border=\"0\"/>";
    html += "</a>";

    //set changes
    document.getElementById("home_sale").innerHTML = html;
    frmEle.currentFrame.value = currentFrame;

    if (timer) {
        startTimer();
    }

}

function startTimer() {
    var t = setTimeout("moveFrame(1,true)", 5000);
}

