﻿$(document).ready(function () {

    SetupKaipara();

});

function SetupKaipara() {
    //hide the maps image if it is visible
    var $theMap = $('img[usemap="#landImageMap"], img[usemap="#siteImageMap"]');
    if ($theMap && $theMap.length !== 0) {
        var mapPath = $theMap.attr("href");
        if (mapPath !== 'UserFiles/Image/Maps/IND_03.jpg') {//don't hide the index map
            $theMap.hide();
        }

        //hide the iframe
        $("iframe:first").hide();

        var $mapLinksDiv = $(".divMapLinks");
        $mapLinksDiv.closest("table").css("width", "100%");

        var $linksCell = $mapLinksDiv.closest("table").closest("td");


        var $downloadDiv = $(".divDownload");
        var $downloadDivTable = $(".divDownload").closest("table");

        $downloadDiv.find("h3:first").text("Downloadable Documents - use the links below to download the desired file").after("<br>");

        $downloadDivTable.appendTo($linksCell);

        var imgText = "<img class='' align='absMiddle' src='UserFiles/Image/pdf-logo.jpg'/>";

        var $mapLink = $downloadDiv.find("a:first");

        var pdfRef = $mapLink.attr("href");

        $mapLink.html("<a href='" + pdfRef + "'>" + imgText + "Decisions version map</a>");

        var $legend = $("a:contains(Map Legend)");
        var $legendRef = $legend.attr("href");

        $legend.html("<a href='" + $legendRef + "'>" + imgText + "Decisions version legend</a>");

        $legend.after("<br><br/><a id='lnkNotifiedMap' href='" + pdfRef.replace('UserFiles/File/PDF', 'UserFiles/File/PDF/Notified') + "'>" + imgText + "As Notified map</a>");

        $("#lnkNotifiedMap").after("<br/><a href='" + $legendRef.replace('UserFiles/File/PDF', 'UserFiles/File/PDF/Notified') + "'>" + imgText + "As Notified version legend</a>");



    } else {

        var $theAppendixMap = $('img[usemap="#imageMap"]');

        if ($theAppendixMap && $theAppendixMap.length !== 0 && (window.location.href.indexOf("Maps") === -1))//do it if found, but not on maps page
            $theAppendixMap.hide();
        
    }
}
