﻿Vtab.Application.checkboxChanged = function() {
    var kmlLayer = map.getLayersByName("kmlLayer")[0];
    var features = kmlLayer.features;

    var _temp = "";
    var visibleLayers = [];
    //Check witch "types/layers" are visible/checked
    jQuery("input[type=checkbox]:checked", "#tocLayers").each(function() {
        visibleLayers.push(this.value);
    });
    kmlLayer.setVisibility(true);
    //Loop through all KML features
    for (var i = 0; i < features.length; i++) {
        //Create empty object and array
        var paramObj = { featureData: _temp };
        var paramArr = [];
        for (var j = 0; j < visibleLayers.length; j++) {
            if (visibleLayers[j] == "security") {
                paramArr.push(visibleLayers[j] + ";" + features[i].data.security);
            }
            else if (visibleLayers[j] == "accessibility") {
                paramArr.push(visibleLayers[j] + ";" + features[i].data.accessibility);
            }
            else if (visibleLayers[j] == "availability") {
                paramArr.push(visibleLayers[j] + ";" + features[i].data.availability);
            }
        }
        paramArr.push("summary" + ";" + features[i].data.summary);
        paramObj.featureData = paramArr.join("^");
        var width;
        var height = 51;
        var offsetX = 2;
        var offsetY = -25;
        if (j == 0) {
            width = 25;
            height = 25;
            offsetX = 0;
            offsetY = 0;
        }
        else if (j == 1) {
            width = 53;
        }
        else if (j == 2) {
            width = 77;
        }
        else if (j == 3) {
            width = 101;
        }

        //features[i].style.externalGraphic = "/fullkoll/services/dynamicImage.aspx?featureData=" + paramArr.join("^");
        features[i].style.externalGraphic = gDynamicImagePath + "?featureData=" + paramArr.join("^");

        features[i].style.id = "";

        //Set width, height and offset of the features graphic.
        features[i].style.graphicWidth = width;
        features[i].style.graphicHeight = height;
        features[i].style.graphicYOffset = offsetY;
        features[i].style.graphicXOffset = offsetX;
        features[i].style.graphicZIndex = 444;
        features[i].style.graphicTitle = features[i].data.hplName;

        //Redraw feature
        kmlLayer.drawFeature(features[i]);
    }
}

