// preloading for navigation bar rollover________________________________________

if (document.images) {
contactlenses_F1 = new Image(159,81); contactlenses_F1.src = "contactlenses.gif";
contactlenses_F2 = new Image(159,81); contactlenses_F2.src = "contactlenses_F2.gif";
contactlenses_F3 = new Image(159,81); contactlenses_F3.src = "contactlenses_F3.gif";
contactlenses_F4 = new Image(159,81); contactlenses_F4.src = "contactlenses_F4.gif";
eyecondition_F1 = new Image(163,90); eyecondition_F1.src = "eyecondition.gif";
eyecondition_F2 = new Image(163,90); eyecondition_F2.src = "eyecondition_F2.gif";
eyecondition_F3 = new Image(163,90); eyecondition_F3.src = "eyecondition_F3.gif";
eyecondition_F4 = new Image(163,90); eyecondition_F4.src = "eyecondition_F4.gif";
index_F1 = new Image(170,97); index_F1.src = "home.gif";
index_F2 = new Image(170,97); index_F2.src = "home_F2.gif";
index_F3 = new Image(170,97); index_F3.src = "home_F3.gif";
index_F4 = new Image(170,97); index_F4.src = "home_F4.gif";
lasercorrection_F1 = new Image(200,76); lasercorrection_F1.src = "lasercorrection.gif";
lasercorrection_F2 = new Image(200,76); lasercorrection_F2.src = "lasercorrection_F2.gif";
lasercorrection_F3 = new Image(200,76); lasercorrection_F3.src = "lasercorrection_F3.gif";
lasercorrection_F4 = new Image(200,76); lasercorrection_F4.src = "lasercorrection_F4.gif";
thedoctor_F1 = new Image(200,74); thedoctor_F1.src = "thedoctor.gif";
thedoctor_F2 = new Image(200,74); thedoctor_F2.src = "thedoctor_F2.gif";
thedoctor_F3 = new Image(200,74); thedoctor_F3.src = "thedoctor_F3.gif";
thedoctor_F4 = new Image(200,74); thedoctor_F4.src = "thedoctor_F4.gif";
location_F1 = new Image(200,77); location_F1.src = "location.gif";
location_F2 = new Image(200,77); location_F2.src = "location_F2.gif";
location_F3 = new Image(200,77); location_F3.src = "location_F3.gif";
location_F4 = new Image(200,77); location_F4.src = "location_F4.gif";
links_F1 = new Image(200,99); links_F1.src = "links.gif";
links_F2 = new Image(200,99); links_F2.src = "links_F2.gif";
links_F3 = new Image(200,99); links_F3.src = "links_F3.gif";
links_F4 = new Image(200,99); links_F4.src = "links_F4.gif";
}

/* Function that swaps images.___________________________________________ */

function di20(id, newSrc) {
    var theImage = FWFindImage(document, id, 0);
    if (theImage) {
        theImage.src = newSrc;
    }
}

/* Functions that track and set toggle group button states. */

function FWFindImage(doc, name, j) {
    var theImage = false;
    if (doc.images) {
        theImage = doc.images[name];
    }
    if (theImage) {
        return theImage;
    }
    if (doc.layers) {
        for (j = 0; j < doc.layers.length; j++) {
            theImage = FWFindImage(doc.layers[j].document, name, 0);
            if (theImage) {
                return (theImage);
            }
        }
    }
    return (false);
}


function setCookie(name, value) {
    document.cookie = name + "=" + escape(value);
}

function getCookie(Name) {
    var search = Name + "=";
    var retVal = "";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            end = document.cookie.indexOf(";", offset);
            offset += search.length;
            if (end == -1) {
                end = document.cookie.length;
            }
            retVal = unescape(document.cookie.substring(offset, end));
        }
    }
    return (retVal);
}

function InitGrp(grp) {
    var cmd = false;
    if (getCookie) {
        cmd = getCookie(grp);
    }
    if (cmd) {
        eval("GrpDown(" + cmd + ")");
        eval("GrpRestore(" + cmd + ")");
    }
}

function FindGroup(grp, imageName) {
    var img = FWFindImage(document, imageName, 0);
    if (!img) {
        return (false);
    }
    var docGroup = eval("document.FWG_" + grp);
    if (!docGroup) {
        docGroup = new Object();
        eval("document.FWG_" + grp + " = docGroup");
        docGroup.theImages = new Array();
    }
    if (img) {
        var i;
        for (i = 0; i < docGroup.theImages.length; i++) {
            if (docGroup.theImages[i] == img) {
                break;
            }
        }
        docGroup.theImages[i] = img;
        if (!img.atRestSrc) {
            img.atRestSrc = img.src;
            img.initialSrc = img.src;
        }
    }
    return (docGroup);
}

function GrpDown(grp, imageName, downSrc, downOver) {
    if (!downOver) {
        downOver = downSrc;
    }
    var cmd = "'" + grp + "','" + imageName + "','" + downSrc + "','" + downOver + "'";
    setCookie(grp, cmd);
    var docGroup = FindGroup(grp, imageName, false);
    if (!docGroup || !downSrc) {
        return;
    }
    obj = FWFindImage(document, imageName, 0);
    var theImages = docGroup.theImages;
    if (theImages) {
        for (i = 0; i < theImages.length; i++) {
            var curImg = theImages[i];
            if (curImg && curImg != obj) {
                curImg.atRestSrc = curImg.initialSrc;
                curImg.isDown = false;
                obj.downOver = false;
                curImg.src = curImg.initialSrc;
            }
        }
    }
    obj.atRestSrc = downSrc;
    obj.downOver = downOver;
    obj.src = downOver;
    obj.isDown = true;
}

function GrpSwap(grp) {
    var i, j = 0, newSrc, objName;
    var docGroup = false;
    for (i = 1; i < (GrpSwap.arguments.length - 1); i += 2) {
        objName = GrpSwap.arguments[i];
        newSrc = GrpSwap.arguments[i + 1];
        docGroup = FindGroup(grp, objName);
        if (!docGroup) {
            continue;
        }
        obj = FWFindImage(document, objName, 0);
        if (!obj) {
            continue;
        }
        if (obj.isDown) {
            if (obj.downOver) {
                obj.src = obj.downOver;
            }
        } else {
            obj.src = newSrc;
            obj.atRestSrc = obj.initialSrc;
        }
        obj.skipMe = true;
        j++;
    }
    if (!docGroup) {
        return;
    }
    theImages = docGroup.theImages;
    if (theImages) {
        for (i = 0; i < theImages.length; i++) {
            var curImg = theImages[i];
            if (curImg.atRestSrc && !curImg.skipMe) {
                curImg.src = curImg.atRestSrc;
            }
            curImg.skipMe = false;
        }
    }
}

function GrpRestore(grp) {
    var docGroup = eval("document.FWG_" + grp);
    if (!docGroup) {
        return;
    }
    theImages = docGroup.theImages;
    if (theImages) {
        for (i = 0; i < theImages.length; i++) {
            var curImg = theImages[i];
            if (curImg.atRestSrc) {
                curImg.src = curImg.atRestSrc;
            }
        }
    }
}
