﻿function Hole(holeNumber, rowIndex, holePar, holeYardage, holeTip, goldYards, blueYards, whiteYards, greenYards)
{
    this.Number = holeNumber;
    this.RowIndex = rowIndex;
    this.Par = holePar;
    this.Yardage = holeYardage;
    this.Tip = holeTip;
    this.GoldYardage = goldYards;
    this.BlueYardage = blueYards;
    this.WhiteYardage = whiteYards;
    this.GreenYardage = greenYards;
}

var holes = new Array(18);
holes[0] = new Hole(1, 2, 5, 522, "You don't need a lot of distance on this opening drive. Stay short of the fairway bunker that crosses the fairway. " +
            "Your second shot here is the important one, which will set you up for a good approach to the green. A par on this hole gets " +
            "you on the right track for the rest of the round.", 247, 229, 186, 173);
holes[1] = new Hole(2, 3, 3, 130, "Large green to hit to. Be careful about not being too aggressive here, we wouldn't want you to three putt.", 94, 67, 52, 35);
holes[2] = new Hole(3, 4, 4, 410, "Stay left of deep fairway bunker on right side of fairway. Green slopes back to front which helps you hold your approach shot.",
            246, 230, 196, 149);
holes[3] = new Hole(4, 5, 5, 555, "Swing away on this tee shot. Once you have navigated the fairway bunkers and tall pine trees, make sure your approach shot to this green stays below the hole.",
            242, 218, 186, 131);
holes[4] = new Hole(5, 6, 3, 185, "The very large tree protecting the right side of the fairway just in front of the tee box has eaten up many golf balls over the years. If you don't hit the ball high, make sure you stay to the left.", 157, 144, 127, 112);
holes[5] = new Hole(6, 7, 4, 364, "Select a club which will get you safely to the dogleg in the fairway. The risk of hitting driver over the trees is not worth it. The fairway slopes left to right, so when you are ready to play your approach to the green, aim left. The ball below your feet will tend to go right.", 178, 160, 146, 131);
holes[6] = new Hole(7, 8, 3, 198, "Very scenic par 3. Elevated tees give you a great view of the green. Remember to take off 10% yardage for downhill shots. Pay careful attention to the swirling wind by watching the tree tops.", 182, 156, 135, 123);
holes[7] = new Hole(8, 9, 4, 399, "You use to get away with hitting to anywhere on this hole. Not anymore! Bunkers guard the green and the fairway. The pine trees have grown tall and come into play now.", 278, 248, 232, 209);
holes[8] = new Hole(9, 10, 4, 392, "Because of the dogleg, you don't have to hit it long off the tee. The slope feeds the ball to the back of the green on your approach shot.", 251, 227, 202, 148);
holes[9] = new Hole(10, 14, 3, 182, "Proper distance is important, look to go left if not attacking the pin.", 138, 130, 121, 112);
holes[10] = new Hole(11, 15, 5, 443, "A solid tee shot is required here. Safest bet is to play second shot properly in order to attack the pin with your third. For uphill shots you will need to add 15% to your yardage. If your ball fails to clear the water pipe, drop area marked by black cement marker. Add penalty.", 237, 218, 192, 144);
holes[11] = new Hole(12, 16, 3, 150, "After taking in the view, play close attention to the swirling wind. The green has 3 levels, try to keep your tee shot below the pin here.", 104, 95, 81, 68);
holes[12] = new Hole(13, 17, 4, 375, "To play this hole, pick a point on the hillside to aim over. There is a lot of room to hit to. You will be tempted to hit to the green. Be careful! A birdie can be made just as easily from the fairway in front of the green.", 237, 218, 192, 144);
holes[13] = new Hole(14, 18, 3, 170, "Don't let the distance of this hole deceive you. You don't want to be long, left, or right. Play to come up short if undecided what club to use.", 109, 90, 74, 74);
holes[14] = new Hole(15, 19, 5, 521, "A good tee shot leaves you a good chance of getting home in two. Not any room for error on approach shot. A drop are is provided and marked by a black cement marker if your tee shot is not found. Add 1 stroke penalty.", 233, 200, 148, 120);
holes[15] = new Hole(16, 20, 4, 310, "Accuracy, not distance, is the key to this par 4. Keep left center on tee shot. Large green to hit to with approach shot.", 217, 208, 160, 150);
holes[16] = new Hole(17, 21, 4, 263, "Your tee shot here is critical. Use the right hillside as a place to bail out to. You cannot be left of the green on your approach shot.", 183, 173, 163, 151);
holes[17] = new Hole(18, 22, 5, 456, "Not a long par 5, but be careful. Its as easy to make a double as it is a birdie on this hole. Don't go over the green!", 230, 197, 186, 129);

function selectHole(holeNumber)
{
    // set images
    document.getElementById("hole").src = "img/holes/hole" + holeNumber + ".gif"; 
    document.getElementById("holePhoto").src = "img/holes/hole" + holeNumber + "_photo.gif"; 
        
    var hole = holes[holeNumber - 1];    
    setHighlight(hole);  

    // set details    
    document.getElementById("holeDetail").innerHTML = "Hole " + hole.Number;    
    document.getElementById("parDetail").innerHTML = "Par " + hole.Par;
    document.getElementById("yardsDetail").innerHTML = hole.Yardage + " yards";
    document.getElementById("tipDetail").innerHTML = hole.Tip;
    document.getElementById("goldDetail").innerHTML = hole.GoldYardage + " YDS";
    document.getElementById("blueDetail").innerHTML = hole.BlueYardage; 
    document.getElementById("whiteDetail").innerHTML = hole.WhiteYardage;
    document.getElementById("greenDetail").innerHTML = hole.GreenYardage;    
    var markerText = "From colored markers to ";
    markerText += hole.Par == 3 ? "center of green" : "landing area";
    document.all["markerDetail"].innerText = markerText;       
}

function setHighlight(hole)
{   
    for (i = 0; i < 18; i++)
    {
        var curHole = holes[i];         
        var cells = document.getElementById("scorecard").rows[curHole.RowIndex].cells;
        cells[0].className = curHole.Number == hole.Number ? "highlight" : "green-dark";
        cells[1].className = curHole.Number == hole.Number ? "highlight" :  "green-medium";
        cells[2].className = curHole.Number == hole.Number ? "highlight" :  "green-light";
        cells[3].className = curHole.Number == hole.Number ? "highlight" :  "green-dark";
    }
}


