window.onload = kickOff;

var picQuantity = 20;
var picObj;
var picCounter = 0;
var projectId =  "pho";

function kickOff() {
    picObj = document.getElementById("pic");
    //make event handlers for mouse events within js file, allowing for separation of behavior from content file
    var allA = document.getElementsByTagName("a");
    for (var i=0; i<allA.length; i++) {
        //if href of a matches URL, set text to indicate "here" status
        if (allA[i] == window.location.href || window.location.href.indexOf("?") == -1 && allA[i].id == "cla") {
            allA[i].style.color = "#cc6600";
            allA[i].style.borderBottom = "none";
        }
        allA[i].onfocus = doBlur;
        allA[i].onclick = doLinkClick;
    }
    var allImg = document.getElementsByTagName("img");
    //find all srcs with off in their names -- they have a corresponding overs
    for (i=0; i<allImg.length; i++) {
        if (allImg[i].src.indexOf("_off") != -1) { 
            //if id of tab image is contained in the URL, set tab image to indicate "here" status
            if (window.location.href.indexOf(allImg[i].id) != -1 || window.location.href.indexOf("html") == -1 && allImg[i].id == "index") {
                allImg[i].src = "images/" + allImg[i].id + "_over.gif";
            }
            allImg[i].onmouseover = doMouseover;
            allImg[i].onmouseout = doMouseout;
            allImg[i].onclick = doImgClick;
            //preload any over images
            var imgObj = new Image(); 
            imgObj.src = "images/" + allImg[i].id + "_over.gif";
        }
    }
    //begin for photo section
    if (window.location.href.indexOf("photos") != -1) {
        showProject();
    }
    //protect email address from spambots
    if (window.location.href.indexOf("contact") != -1) {
        writeMe();
    }
}
function doMouseover() {
    this.src = "images/" + this.id + "_over.gif";
}
function doMouseout() {
    //disable mouseout swap for current section
   if (window.location.href.indexOf(this.id) != -1 || window.location.href.indexOf("html") == -1 && this.id == "index") {
        return false;
    }
    this.src = "images/" + this.id + "_off.gif";
    return true;
}
function doBlur() {
    //get rid of focus highlight from clicked links
        this.blur();
}
function doImgClick() {
    //detect left/right arrow clicks and route
    if (this.id.indexOf("arrow") != -1) {
        (this.id.indexOf("right") != -1) ? doNext() : doPrevious();
    }
}
function doLinkClick() {
    //disable load click for current section
    if (window.location.href.indexOf(this) != -1 || window.location.href.indexOf("?") == -1 && this.id == "cla" || window.location.href.indexOf("html") == -1 && this.firstChild.id == "index") {
        return false;
    }
}
function doNext() {
    if (picCounter < picQuantity-1) {
        picCounter += 1;
        showPic();
    }
}
function doPrevious() {
    if (picCounter > 0) {
        picCounter -= 1;
        showPic();
    }
}
function showPic() {
    picObj.src = "pics/" + projectId + picCounter + ".jpg";
    document.getElementById("statuslayer").firstChild.nodeValue = picCounter+1 + " of " + picQuantity;
}
function showProject() {
    //URL substrings sidebar links are used to pass project ID and pic quantity here 
    picQuantity = (!location.search.indexOf("?")) ? location.search.substr(5) : picQuantity;
    showPic();
}
function writeMe() {
    //protect email address from spambots
    var name = "ecutler";
    var domain = "att.net";
    document.getElementById("writeme").firstChild.nodeValue = name + "@" + domain;
}









