var blnSlidingTADown;
var timerSlideDownTA;
var intCurrentTAHeight;
var intMaxTAHeight = 230;
var blnFading;
var timerFadeMaps;
var intFadeIncrement = 5;
var intFadeOutAmount;
var intFadeInAmount;
var intWaitToFade = 0;
var intBackgroundPosLeft = 0;
var intBackgroundPosTop = 0;



function searchMap(intType)
{
var blnShowIreland = false;
var arrAllSelect = document.getElementsByTagName("select");

for (var loopDDs = 0; loopDDs < arrAllSelect.length; loopDDs++)
    {
    if (arrAllSelect[loopDDs].id.indexOf("selTour") != -1)
        {
        if (arrAllSelect[loopDDs].selectedIndex == 0)
            {
            blnShowIreland = true;
            }
        }
    }

if (intType == 1 && blnShowIreland)
    {
    hideAllTours();
    showIrelandMap(0,'',1);
    }
else
    {
    startAjax(intType,'');
    }
}



function resetMapSelects(blnSelTour)
{
var arrAllSelect = document.getElementsByTagName("select");

for (var loopDDs = 0; loopDDs < arrAllSelect.length; loopDDs++)
    {
    if (blnSelTour == 1)
        {
        if (arrAllSelect[loopDDs].id.indexOf("selProvince") != -1 || arrAllSelect[loopDDs].id.indexOf("selCounty") != -1 || arrAllSelect[loopDDs].id.indexOf("selCourseType") != -1 || arrAllSelect[loopDDs].id.indexOf("selGolfClub") != -1)
            {
            arrAllSelect[loopDDs].selectedIndex = 0;
            }
        }
    else if (arrAllSelect[loopDDs].id.indexOf("selTour") != -1)
        {
        arrAllSelect[loopDDs].selectedIndex = 0;
        }
    }
}



function showTAHelp()
{
var objMapTextArea = document.getElementById("mapTextArea");
var strMapTextAreaHeight = objMapTextArea.style.height;
var intMapTextAreaHeight = (strMapTextAreaHeight == "") ? 0 : strMapTextAreaHeight.substring(0,strMapTextAreaHeight.length - 2);

var strMapHelp = "<h2>Map Help</h2>";
strMapHelp += "<p>You can search for golf clubs, accommodation listings and heritage highlights throughout Ireland by either using the Search Filter section above, or by clicking directly on the map.</p>";
strMapHelp += "<p>By using the Search Filter you can either select a tour (and click the Find button beside it) or select a combination of the Province, County, Course Type and Golf Club selection dropdowns.</p>";
strMapHelp += "<p>Once a search is done the map will display all golf clubs that match the search criteria. For example by selecting Discover Ireland from the Tour dropdown above all golf clubs that are visited on the Discover Ireland tour will be shown on the map. Information on the Discover Ireland tour will be shown in this textbox area. Point your mouse at any one of the flags and the golf club name will appear. By clicking on any one of the golf clubs on the map information on that golf club will appear in this textbox area.</p>";
strMapHelp += "<p>You may also select a province in Ireland by clicking that province on the map. Information on the selected province is displayed in this textbox area. All golf clubs in that province that we visit on any one of the tours will be displayed on the map. Click on a county to further refine the golf clubs displayed, and to view information on that county.</p>";
strMapHelp += "<p>By clicking on the buttons above the Search Filter (Golf Clubs, Accommodation and Special Interest) you can turn on or turn off displaying golf clubs, accommodation or special interest items.</p>";

objMapTextArea.innerHTML = strMapHelp;

if (intMapTextAreaHeight == 0)
    {
    slideMapTA();
    }
}



function slideMapTA()
{
if (!blnSlidingTADown)
    {
    blnSlidingTADown = true;

    var objMapTextArea = document.getElementById("mapTextArea");
    var strTACurrentDivHeight = objMapTextArea.style.height;
    var intTACurrentDivHeight = strTACurrentDivHeight.substring(0,strTACurrentDivHeight.length - 2);

    var blnAtMaxHeight = (intTACurrentDivHeight == intMaxTAHeight) ? true : false;

    if (!blnAtMaxHeight)
        {
        intCurrentTAHeight = 0;
        timerSlideDownTA = setInterval("makeTAMoreVisible()", 10);
        }
    else
        {
        intCurrentTAHeight = intMaxTAHeight;
        timerSlideDownTA = setInterval("makeTALessVisible()", 10);
        }
    }
}



function makeTAMoreVisible()
{
if (parseInt(intCurrentTAHeight) < intMaxTAHeight)
    {
    intCurrentTAHeight = parseInt(intCurrentTAHeight) + 10;

    var objMapTextArea = document.getElementById("mapTextArea");
    objMapTextArea.style.height = intCurrentTAHeight + "px";

    var intOpacityLevel = 100 - (100 / (intMaxTAHeight / (intMaxTAHeight - intCurrentTAHeight)))
    objMapTextArea.style.filter = "alpha(opacity=" + intOpacityLevel + ")";
    objMapTextArea.style.opacity = intOpacityLevel / 100;
    objMapTextArea.style.display = "block";
    }
else
    {
    clearInterval(timerSlideDownTA);
    blnSlidingTADown = false;
    }
}



function makeTALessVisible()
{
var objMapTextArea = document.getElementById("mapTextArea");

if (parseInt(intCurrentTAHeight) > 0)
    {
    intCurrentTAHeight = parseInt(intCurrentTAHeight) - 10;

    objMapTextArea.style.height = intCurrentTAHeight + "px";
    
    var intOpacityLevel = (100 - (100 / (intMaxTAHeight / (intMaxTAHeight - intCurrentTAHeight))));
    objMapTextArea.style.filter = "alpha(opacity=" + intOpacityLevel + ")";
    objMapTextArea.style.opacity = intOpacityLevel / 100;
    }
else
    {
    objMapTextArea.style.display = "none";
    objMapTextArea.style.filter = "0";
    objMapTextArea.style.opacity = "0.0";

    clearInterval(timerSlideDownTA);
    blnSlidingTADown = false;
    intCurrentTAHeight = 0;
    }
}



function showIrelandMap(blnFromSearch,strMapInfoRegion,blnHideBackButton)
{
if (blnHideBackButton == 1)
    {
    var objBackButton = document.getElementById("backToIreland");
    objBackButton.className = "hideDiv";
    }

var objMapIreland = document.getElementById("mapIreland");
objMapIreland.className = "showDiv";
objMapIreland.style.filter = "alpha(opacity=100)";
objMapIreland.style.opacity = "1.0";

showRegion('mapProvince','');
hideAllCounties();

var objMapTextArea = document.getElementById("mapTextArea");
var strTACurrentDivHeight = objMapTextArea.style.height;
var intTACurrentDivHeight = strTACurrentDivHeight.substring(0,strTACurrentDivHeight.length - 2);
var blnAtMaxHeight = (intTACurrentDivHeight == intMaxTAHeight) ? true : false;

if (blnFromSearch == 0)
    {
    startAjax(3, "");

    if (blnAtMaxHeight)
        {
        intCurrentTAHeight = intMaxTAHeight;
        timerSlideDownTA = setInterval("makeTALessVisible()", 10);
        }
    }
else if (strMapInfoRegion != "")
    {
    startAjax(4,strMapInfoRegion);
    }
else if (blnAtMaxHeight)
    {
    intCurrentTAHeight = intMaxTAHeight;
    timerSlideDownTA = setInterval("makeTALessVisible()", 10);
    }
}



function loadRegion(strFadeInMapID, strMapFadeOutID, intPixelsToLeft, intPixelsToTop)
{
if (!blnFading)
    {
    blnFading = true;

    intFadeOutAmount = 0;
    intFadeInAmount = 0;
    intBackgroundPosLeft = 0;
    intBackgroundPosTop = 0;

    document.getElementById("golfIcons").className = "hideDiv";

    timerFadeMaps = setInterval("fadeMaps('" + strMapFadeOutID + "','" + strFadeInMapID + "','" + intPixelsToLeft + "','" + intPixelsToTop + "')", 10);
    }
}



function fadeMaps(strMapFadeOutID, strMapFadeInID, intPixelsToLeft, intPixelsToTop)
{
var objHoldIcons = document.getElementById("holdIcons");
objHoldIcons.className = "hideDiv";

var objMapFadeOut = document.getElementById(strMapFadeOutID);
var objMapFadeOutSmaller = document.getElementById(strMapFadeInID + "Small");

if (intFadeOutAmount == 100)
    {
    if (intWaitToFade == 10)
        {
        objMapFadeOut.className = "hideDiv";

        intFadeInAmount = (intFadeInAmount == 0) ? intFadeIncrement : intFadeInAmount + intFadeIncrement;

        var objMapFadeIn = document.getElementById(strMapFadeInID);
        objMapFadeIn.style.filter = "alpha(opacity=" + intFadeInAmount + ")";
        objMapFadeIn.style.opacity = intFadeInAmount / 100;
        objMapFadeIn.className = "showDiv";

        objMapFadeOutSmaller.style.filter = "alpha(opacity=" + (100 - intFadeInAmount) + ")";
        objMapFadeOutSmaller.style.opacity = (100 - intFadeInAmount) / 100;

        if (intFadeInAmount == 100)
            {
            clearInterval(timerFadeMaps);

            objMapFadeOutSmaller.className = "hideDiv";

            var strRegionName;
            var objBackButton = document.getElementById("backToIreland");

            if (objBackButton.hasChildNodes())
                {
                while (objBackButton.childNodes.length >= 1)
                    {
                    objBackButton.removeChild(objBackButton.firstChild);
                    }
                }

            var objNewParaBack = document.createElement("div");

            if (strMapFadeInID.indexOf("mapCounty") != -1)
                {
                strRegionName = strMapFadeInID.substring(strMapFadeInID.indexOf("mapCounty") + 9);
                startAjax(3, "County='" + strRegionName + "'");

                objNewParaBack.innerHTML = '<p><a href="javascript:void(0);" onclick="reloadProvince(\'' + strMapFadeOutID + '\');">Back to ' + strMapFadeOutID.substring(3) + '</a></p>';
                }
            else
                {
                strRegionName = strMapFadeInID.substring(strMapFadeInID.indexOf("map") + 3);
                startAjax(3, "Province='" + strRegionName + "'");

                objNewParaBack.innerHTML = '<p><a href="javascript:void(0);" onclick="showIrelandMap(0,\'\',1);">Back to Main Map</a></p>';
                }

            objHoldIcons.className = "showDiv";

            objBackButton.appendChild(objNewParaBack);
            objBackButton.className = "showDiv";

            blnFading = false;
            }
        }
    else
        {
        intWaitToFade++;
        }
    }
else
    {
    intFadeOutAmount = (intFadeOutAmount == 0) ? intFadeIncrement : intFadeOutAmount + intFadeIncrement;

    objMapFadeOut.className = "showDiv";
    objMapFadeOut.style.filter = "alpha(opacity=" + (100 - intFadeOutAmount) + ")";
    objMapFadeOut.style.opacity = (100 - intFadeOutAmount) / 100;

    intBackgroundPosLeft = intBackgroundPosLeft + (intPixelsToLeft / (100 / intFadeIncrement));
    intBackgroundPosTop = intBackgroundPosTop + (intPixelsToTop / (100 / intFadeIncrement));

    objMapFadeOutSmaller.style.filter = "alpha(opacity=100)";
    objMapFadeOutSmaller.style.opacity = "1.0";
    objMapFadeOutSmaller.className = "showDiv";
    objMapFadeOutSmaller.style.backgroundPosition = intBackgroundPosLeft + "px " + intBackgroundPosTop + "px";
    }
}



function reloadProvince(strMapProvince)
{
var objBackButton = document.getElementById("backToIreland");

if (objBackButton.hasChildNodes())
    {
    while (objBackButton.childNodes.length >= 1)
        {
        objBackButton.removeChild(objBackButton.firstChild);
        }
    }

var objNewParaBack = document.createElement("div");
objNewParaBack.innerHTML = '<p><a href="javascript:void(0);" onclick="showIrelandMap(0,\'\',1);">Back to Main Map</a></p>';
objBackButton.appendChild(objNewParaBack);

hideAllCounties();

var objProvinceReload = document.getElementById(strMapProvince);
objProvinceReload.style.filter = "alpha(opacity=100)";
objProvinceReload.style.opacity = "1.0";
objProvinceReload.className = "showDiv";

//startAjax(4,strMapProvince.substring(3));
startAjax(3, "Province='" + strMapProvince.substring(3) + "'");
}



function showRegion(arrType, strRegionDivID)
{
switch(arrType)
    {
    case "Ireland":
    var arrRegionRegions = new Array("provinceLeinster","provinceUlster","provinceMunster","provinceConnaught");
    break;

    case "mapProvince":
    var arrRegionRegions = new Array("mapLeinster","mapUlster","mapMunster","mapConnaught");
    break;

    case "Leinster":
    var arrRegionRegions = new Array("countyLouth","countyMeath","countyDublin","countyWicklow","countyWexford","countyKildare","countyCarlow","countyKilkenny","countyLaois","countyOffaly","countyWestmeath","countyLongford");
    break;

    case "Ulster":
    var arrRegionRegions = new Array("countyDonegal","countyDerry","countyAntrim","countyDown","countyArmagh","countyMonaghan","countyCavan","countyFermanagh","countyTyrone");
    break;

    case "Munster":
    var arrRegionRegions = new Array("countyWaterford","countyCork","countyKerry","countyClare","countyLimerick","countyTipperary");
    break;

    case "Connaught":
    var arrRegionRegions = new Array("countyGalway","countyMayo","countySligo","countyLeitrim","countyRoscommon");
    break;
    }

var objProvinceDiv;

for (var intLoopProvinces = 0; intLoopProvinces < arrRegionRegions.length; intLoopProvinces++)
    {
    objProvinceDiv = document.getElementById(arrRegionRegions[intLoopProvinces]);

    if (strRegionDivID == arrRegionRegions[intLoopProvinces])
        {
        objProvinceDiv.className = "showDiv";
        }
    else
        {
        objProvinceDiv.className = "hideDiv";
        }
    }
}



function hideAllCounties()
{
var objHoldBigCounties = document.getElementById("holdBigCounties");

if (objHoldBigCounties.hasChildNodes())
    {
    var objCountyDiv = objHoldBigCounties.firstChild;

    while(objCountyDiv != objHoldBigCounties.lastChild)
        {
        if (objCountyDiv.nodeType == 1)
            {
            objCountyDiv.className = "hideDiv";
            }

        objCountyDiv = objCountyDiv.nextSibling;
        }
    }
}



function hideAllTours()
{
var objHoldTours = document.getElementById("holdTourMaps");

if (objHoldTours.hasChildNodes())
    {
    var objTourDiv = objHoldTours.firstChild;

    while(objTourDiv != objHoldTours.lastChild)
        {
        if (objTourDiv.nodeType == 1)
            {
            objTourDiv.className = "hideDiv";
            }

        objTourDiv = objTourDiv.nextSibling;
        }
    }
}



function showIcons(strIconDivID)
{
var objIconsDiv = document.getElementById(strIconDivID);
objIconsDiv.className = (objIconsDiv.className == "hideDiv") ? "showDiv" : "hideDiv";

var objIconsListItem = document.getElementById(strIconDivID + "Li");
objIconsListItem.className = (objIconsListItem.className || objIconsDiv.className == strIconDivID + "LiOn") ? "" : strIconDivID + "LiOn";

/* TEMP */
switch(strIconDivID)
    {
    case "accIcons":
    alert("Accommodation listings will be added soon...");
    break;

    case "specialIcons":
    alert("Special Interest listings will be added soon...");
    break;
    }
/* TEMP */
}