var projectsArray = new Array();

var project0 = new Object();
project0.title = "Firehouse";
project0.location = "Engine Number 44, <br>San Francisco, CA";
project0.description = "Chemical Engine House 44 was originally built in 1909 and served as a San Francisco firehouse until 1959.  This historic structure has undergone a brilliant renovation including 4 levels of unique living space as well as an observatory tower, large wine cellar and tasting room; all designed for modern living.  The open floor plan is accentuated by the center staircase/elevator atrium which is washed in sunlight from the immense skylight above.";
project0.numberOfImages = "21";
project0.link = "http://www.firehouse44.com"
project0.uselogolink = "true";
projectsArray[0] = project0;

var project1 = new Object();
project1.title = "27th Street";
project1.location = "383 27th Street (Noe Valley), San Francisco, CA";
project1.description = "This meticulously renovated 1890's Victorian is a stunner! Three levels of living space including 4 bedrooms, 3.5 baths, a gourmet kitchen with top of the line appliances, formal dining room, living room, family room & office. Outside access from all levels overlooking landscaped yard. Great attention has been given to retain the original beauty of the home while upgrading for today's living, including impressive moldings, casings, refinished original fir flooring, and transomes above doorways.";
project1.numberOfImages = "19";
project1.link = "";
project1.uselogolink = "false";
projectsArray[1] = project1;

var project2 = new Object();
project2.title = "Elizabeth Street";
project2.location = "Elizabeth Street (Noe Valley), San Francisco, CA";
project2.description = "This 1890 Noe Valley Victorian renovation masterfully transformed a 1,000 square foot home to 3,500 square feet through a vertical addition.  This project added two levels to the existing house while preserving and maintaining the original architecture.  This home was featured on the Victorian Alliance home tour in 2007 to showcase its craftsmanship and attention to detail throughout the entire home.";
project2.numberOfImages = "17";
project2.link = ""
project2.uselogolink = "false";
projectsArray[2] = project2;

function loadProjectsNav() {
    var tbody = document.getElementById("projectsnav").getElementsByTagName("tbody")[0];
        
    for (var i=0; i<projectsArray.length; i++) {
        var newTR = document.createElement("TR");
        var newTD1 = document.createElement("TD");
        newTD1.innerHTML = "<img src='../images/projects/projectsarrow.gif' class='arrow' id='projectsArrow" + i + "' />";
        var newTD2 = document.createElement("TD");
        newTD2.innerHTML = "<a href='#' onclick='loadProject(" + i + ")' class='projectsnav'>" + projectsArray[i].title + "</a>";
        newTR.appendChild(newTD1);
        newTR.appendChild(newTD2);
        tbody.appendChild(newTR);
    }
    document.getElementById('projectsnav').style.display = "block";
}

function loadProject(projID) {
    document.getElementById('projectLocation').innerHTML = "<b>" + projectsArray[projID].location + "</b>";
    
    var description = projectsArray[projID].description;
    if (projectsArray[projID].link != "") {
        if (projectsArray[projID].uselogolink == 'true') {
            description = description + "<p class='projectsurl'><a href='#' onclick='javascript:window.open(\"" + projectsArray[projID].link + "\")'><img src='../images/projects/project" + projID + "/logo.jpg' border='none' height='100' /></a></p>";
        } else {
            description = description + "<p class='projectsurl'><a href='#' onclick='javascript:window.open(\"" + projectsArray[projID].link + "\")'>Go to site</a></p>";
        }
    }
    
    document.getElementById('projectDescription').innerHTML = description;

    loadBigProjectImage(projID);
    showProjectArrow(projID);
}

function loadBigProjectImage(projID) {
    var viewer = new PhotoViewer();
    if (projectsArray[projID].numberOfImages > 1) {
        for (var i=1; i<=projectsArray[projID].numberOfImages; i++) {
            viewer.add('../images/projects/project' + projID + '/' + i + '.jpg');
        }
    } else {
        viewer.add('../images/projects/project' + projID + '/1.jpg');
    }

    viewer.disableEmailLink();
    viewer.disablePhotoLink();
    viewer.disableFading();
    
    window.parent.document.getElementById('bigProjectPicture').innerHTML = "<a href='#' onclick='javascript:void(viewer.show(0))'><img height='490' src='../images/projects/project" + projID + "/1.jpg' border='none' onError='javascript:this.src=\"../images/projects/noafterimage.jpg\"' /></a>";
}

function showProjectArrow(projID) {
    var arrows = document.getElementById("projectsnav").getElementsByTagName("img");
    for (var i=0; i < arrows.length; i++) {
        arrows[i].style.visibility = "hidden";
    }
    var arrow = document.getElementById("projectsArrow" + projID);
    arrow.style.visibility = "visible";
}

function getImageNumber(imgid) {
    return parseInt(imgid.substr(3,imgid.length));
}

function getProjectID(imgid) {
    return parseInt(imgid.substr(2,1));
}
