REQUIRED_ZOOM_LEVEL = 0;
MAXIMUM_POINTS = 250;
LOCATION_CATEGORIES = {
    0: 'Neighborhood',
    1: 'Landmark',
    2: 'Park',
    3: 'Pathway'
}

// className handling functions
function hasClass(obj, className)
{
    if (obj.className)
    {
        var arrList = obj.className.split(' ');
        var strClassUpper = className.toUpperCase();

        for (var i=0; i<arrList.length; i++)
        {
            if (arrList[i].toUpperCase() == strClassUpper)
            {
                return true;
            }
        }
    }
    return false;
}
function toggleClass(obj, className)
{
    if (hasClass(obj, className))
    {
        removeClass(obj, className);
    }
    else
    {
        addClass(obj, className);
    }
}
function addClass(obj, className)
{
    if (obj.className)
    {
        obj.className += ' ' + className;
    }
    else
    {
        obj.className = className;
    }
}
function removeClass(obj, className)
{
    if (obj.className)
    {
        var arrList = obj.className.split(' ');
        var strClassUpper = className.toUpperCase();

        for (var i=0; i<arrList.length; i++)
        {
            if (arrList[i].toUpperCase() == strClassUpper)
            {
                arrList.splice(i, 1);
                i--;
            }
        }
        obj.className = arrList.join(' ');
    }
}
// PopUp code
// showPop(event, this, 'Text');
// hidePop();
function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft;
            obj = obj.offsetParent; 
        }
    }
    else if (obj.y)
    {
        curleft += obj.x;
    }
    return curleft;
}
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curtop += obj.offsetTop;
            obj = obj.offsetParent; 
        }
    }
    else if (obj.y)
    {
        curtop += obj.y;
    }
    return curtop;
}
function showPop(evt,trigger,objectText) {
    popTrig = trigger;
    if (!(popUp = document.getElementById("popUp")))
        return false;
    xPos = findPosX(popTrig) + 25;
    yPos = findPosY(popTrig) + 15;
    if (xPos + popUp.offsetWidth > document.body.clientWidth)
    {
        xPos = xPos - popUp.offsetWidth;
        yPos = yPos + 50;
    }
    if (yPos + popUp.offsetHeight > document.body.clientHeight)
        yPos = yPos - popUp.offsetHeight - popTrig.offsetHeight;
    popUp.style.left = xPos + 'px';
    popUp.style.top = 0;
    popUp.innerHTML = objectText;
    popUp.style.top = yPos - popUp.offsetHeight + 'px';
    popUp.style.visibility = 'visible';
}
function hidePop() {
    if (!popUp)
        return false;
    popUp.style.visibility = 'hidden';
    popUp.innerHTML = '';
    popUp = '';
}
document.write('<div id="popUp" style="position: absolute; visibility: hidden; background: #ffffcc; border: 1px solid #000; color: #000; padding: 5px; font-size: 8pt; text-align: left; border-right-width: 3px; border-bottom-width: 3px; z-index: 1000;"></div>');

// Color box selector
function selectColor(str)
{
    if (!str)
        return false;

    document.getElementById('colorPreview').style.backgroundColor = '#' + str;
    document.getElementById('colorText').innerHTML = '#' + str;
}
hex = [
    'fffff00',
    'aaff00',
    '55ff00',
    '00ff00',
    'ffaa00',
    'c6c61c',
    '8de238',
    '55ff55',
    'ff5500',
    'e28d38',
    'c6c671',
    'aaffaa',
    'ff0000',
    'ff5555',
    'ffaaaa',
    'ffffff',
    '00ff00',
    '00ff55',
    '00ffaa',
    '00ffff',
    '55ff55',
    '38e28d',
    '1cc6c6',
    '00aaff',
    'aaffaa',
    '71c6c6',
    '388de2',
    '0055ff',
    'ffffff',
    'aaaaff',
    '5555ff',
    '0000ff',
    'ff0000',
    'ff5555',
    'ffaaaa',
    'ffffff',
    'ff0055',
    'f0467f',
    'e28da9',
    'd4d4d4',
    'ff00aa',
    'e238a9',
    'c570a9',
    'a9a9a9',
    'ff00ff',
    'd42ad4',
    'a954a9',
    '7f7f7f',
    'ffffff',
    'aaaaff',
    '5555ff',
    '0000ff',
    'd4d4d4',
    'a98de2',
    '7f46f0',
    '5500ff',
    'a9a9a9',
    'a970c5',
    'a938e2',
    'aa00ff',
    '7f7f7f',
    'a954a9',
    'd42ad4',
    'ff00ff',
    'ff00ff',
    'd42ad4',
    'a954a9',
    '7f7f7f',
    'aa00ff',
    '8d1cc6',
    '70388d',
    '545454',
    '5500ff',
    '460eb8',
    '381c71',
    '2a2a2a',
    '0000ff',
    '0000aa',
    '000055',
    '000000',
    '7f7f7f',
    'a954a9',
    'd42ad4',
    'ff00ff',
    '545454',
    '8d3870',
    'c61c8d',
    'ff00aa',
    '2a2a2a',
    '711c38',
    'b80e46',
    'ff0055',
    '000000',
    '550000',
    'aa0000',
    'ff0000',
    '0000ff',
    '0000aa',
    '000055',
    '000000',
    '0055ff',
    '0055aa',
    '005555',
    '005500',
    '00aaff',
    '00aaaa',
    '00aa55',
    '00aa00',
    '00ffff',
    '00ffaa',
    '00ff55',
    '00ff00',
    '000000',
    '550000',
    'aa0000',
    'ff0000',
    '005500',
    '555500',
    'aa5500',
    'ff5500',
    '00aa00',
    '55aa00',
    'aaaa00',
    'ffaa00',
    '00ff00',
    '55ff00',
    'aaff00',
    'ffff00'
];
function colorTable(input)
{
    var table = '<table class="hex" cellspacing="0" cellpadding="0">';
    table += '    <thead>';
    table += '    <tr>';
    table += '        <td id="colorPreview" style="background: #ffffff"></td>';
    table += '        <td id="colorText">#FFFFFF</td>';
    table += '    </tr>';
    table += '    </thead>';
    table += '    <tr>';
    table += '        <td>';
    table += '        <table cellspacing="0" cellpadding="0">';
    table += '        <tr>';
    for (i = 0; i < hex.length; i++)
    {
        hex[i] = hex[i].toUpperCase();
        if (i > 0 && i % 32 == 0)
            table += '</tr></table></td></tr><tr><td><table cellspacing="0" cellpadding="0"><tr>' + "\n";
        else if (i > 0 && i % 16 == 0)
            table += '</tr></table></td><td><table cellspacing="0" cellpadding="0"><tr>' + "\n";
        else if (i % 4 == 0)
            table += (i > 0 ? '</tr>' : '') + '<tr>' + "\n";
        table += '<td style="width: 20px; height: 10px; background: #' + hex[i] + '" onclick="document.getElementById(\'' + input + '\').value=\'#' + hex[i] + '\'; hidePop();" onmouseover="selectColor(\'' + hex[i] + '\');"></td>' + "\n";
    }
    table += '        </tr>';
    table += '        </table>';
    table += '        </td>';
    table += '    </tr>';
    table += '    </table>';
    return table;
}

function showColorPicker(event) {
    showPop(event, this, '<b>Select a Color</b><br /><br />' + colorTable(this.rel));
}