﻿//Map List
function createMapList(ulID) {
    //Get the JSON Data
    var dataPoints = createDataPoints("", "");
    var myDataSource = createDataSource(dataPoints);
    var myData = myDataSource.liveData;

    var li = "";
    var liNoPrice = "";
    var liCondos = "";
    var liUnderTwo = "";
    var liUnderThree = "";
    var liOverThree = "";

    var lisForAllMapList = "";

    var feature = "";
    var NumberForHTML = "";

    for (i = 0; i < myData.length; i++) {
        NumberForHTML = "<p>" + (i + 1) + ")"
        CommunityNameAndLink = createURLString(myData[i].link, myData[i].CommunityName) + "</p>";

        var priceRange = myData[i].LowPriceRange
        
        li = "<li id='CommunityID" + myData[i].CommunityID + "'>" + NumberForHTML + CommunityNameAndLink + "</li>";

        if (Number(priceRange) != 0) {
            if (priceRange > 300000) {
                liOverThree += li
            } else if (priceRange > 200000) {
                liUnderThree += li
            } else {
                liUnderTwo += li
            }

        } else {
            liNoPrice += li
        }
    }

    lisForAllMapList += MakeLIForMapList(liNoPrice, "No price", "NoPrice");
    lisForAllMapList += MakeLIForMapList(liUnderTwo, "Under $200,000", "UnderTwo");
    lisForAllMapList += MakeLIForMapList(liUnderThree, "Under $300,000", "UnderThree");
    lisForAllMapList += MakeLIForMapList(liOverThree, "Over $300,000", "OverThree");

    var ndeULMap = YAHOO.util.Dom.get(ulID);

    ndeULMap.innerHTML = lisForAllMapList

    var ndelstLIs = YAHOO.util.Selector.query('li a', ndeULMap);

    for (i = 0; i < ndelstLIs.length; i++) {

        YAHOO.util.Event.addListener(ndelstLIs[i], "mouseover", ShowInfoWindow, [i]);
    }

}

function MakeLIForMapList(lis, header, className) {
    var liWithUL = "";

    if (lis != '') {
        liWithUL = "<li class='" + className + "'><h5>" + header + "</h5><ul>" + lis + "</ul></li>"
    }

    return liWithUL;
}

